From 568c08289fd7b2d651364c03801525e8c387a2e2 Mon Sep 17 00:00:00 2001 From: Gleb Bahmutov Date: Tue, 28 Apr 2020 09:06:45 -0400 Subject: [PATCH 1/2] fix: set excludeAfterRemap to false by default --- .github/ISSUE_TEMPLATE/bug_report.md | 3 +++ common-utils.js | 2 +- cypress/integration/combine-spec.js | 6 +++--- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index f5a4d24b..fb685d7d 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -29,3 +29,6 @@ A clear and concise description of what the bug is. **Link to the repo** Bugs with a reproducible example, like an open source repo showing the bug, are the most likely to be resolved. + +**Example** +See [#217](https://github.com/cypress-io/code-coverage/issues/217) that is an excellent bug report example diff --git a/common-utils.js b/common-utils.js index d2c786a8..43037b36 100644 --- a/common-utils.js +++ b/common-utils.js @@ -28,7 +28,7 @@ const defaultNycOptions = { 'report-dir': './coverage', reporter: ['lcov', 'clover', 'json'], extension: ['.js', '.cjs', '.mjs', '.ts', '.tsx', '.jsx'], - excludeAfterRemap: true + excludeAfterRemap: false } module.exports = { diff --git a/cypress/integration/combine-spec.js b/cypress/integration/combine-spec.js index 1d6718b6..11af7f8d 100644 --- a/cypress/integration/combine-spec.js +++ b/cypress/integration/combine-spec.js @@ -15,7 +15,7 @@ describe('Combine NYC options', () => { 'report-dir': './coverage', reporter: ['lcov', 'clover', 'json'], extension: ['.js', '.cjs', '.mjs', '.ts', '.tsx', '.jsx'], - excludeAfterRemap: true + excludeAfterRemap: false }) }) @@ -31,7 +31,7 @@ describe('Combine NYC options', () => { 'report-dir': './coverage', reporter: ['text'], extension: ['.js', '.cjs', '.mjs', '.ts', '.tsx', '.jsx'], - excludeAfterRemap: true + excludeAfterRemap: false }) }) @@ -58,7 +58,7 @@ describe('Combine NYC options', () => { 'report-dir': './coverage', reporter: ['json'], extension: ['.js'], - excludeAfterRemap: true, + excludeAfterRemap: false, include: ['foo.js'], exclude: ['bar.js'] }) From 872a2495eabeb4e2682162f2be6b189f721324ed Mon Sep 17 00:00:00 2001 From: Gleb Bahmutov Date: Tue, 28 Apr 2020 09:35:24 -0400 Subject: [PATCH 2/2] update exclude-files example --- README.md | 2 ++ examples/exclude-files/package.json | 7 +++++-- task.js | 5 +++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 17456086..43bc1731 100644 --- a/README.md +++ b/README.md @@ -302,6 +302,8 @@ For example, if you want to only include files in the `app` folder, but exclude **Note:** if you have `all: true` NYC option set, this plugin will check the produced `.nyc_output/out.json` before generating the final report. If the `out.json` file does not have information for some files that should be there according to `include` list, then an empty placeholder will be included, see [PR 208](https://github.com/cypress-io/code-coverage/pull/208). +Another important option is `excludeAfterRemap`. By default it is false, which might let excluded files through. If you are excluding the files, and the instrumenter does not respect the `nyc.exclude` setting, then add `excludeAfterRemap: true` to tell `nyc report` to exclude files. See [examples/exclude-files](examples/exclude-files). + ## Disable plugin You can skip the client-side code coverage hooks by setting the environment variable `coverage` to `false`. diff --git a/examples/exclude-files/package.json b/examples/exclude-files/package.json index 12c1e965..f2dab330 100644 --- a/examples/exclude-files/package.json +++ b/examples/exclude-files/package.json @@ -4,10 +4,13 @@ "scripts": { "start": "../../node_modules/.bin/parcel serve index.html", "cy:open": "../../node_modules/.bin/cypress open", - "dev": "../../node_modules/.bin/start-test 1234 cy:open" + "cy:run": "../../node_modules/.bin/cypress run", + "dev": "../../node_modules/.bin/start-test 1234 cy:open", + "e2e": "../../node_modules/.bin/start-test 1234 cy:run" }, "nyc": { - "exclude": ["second.js"] + "exclude": ["second.js"], + "excludeAfterRemap": true }, "devDependencies": { "@babel/core": "7.9.0" diff --git a/task.js b/task.js index e649f3cc..88acc828 100644 --- a/task.js +++ b/task.js @@ -168,6 +168,11 @@ const tasks = { // https://github.com/istanbuljs/nyc#common-configuration-options const nycReportOptions = readNycOptions(processWorkingDirectory) + if (nycReportOptions.exclude && !Array.isArray(nycReportOptions.exclude)) { + console.error('NYC options: %o', nycReportOptions) + throw new Error('Expected "exclude" to by an array') + } + // override a couple of options nycReportOptions.tempDir = coverageFolder if (nycReportOptions['report-dir']) {