From 448ef180e52a736a3a769d7f133a4fdc64756bb0 Mon Sep 17 00:00:00 2001 From: Gleb Bahmutov Date: Fri, 17 Apr 2020 12:46:40 -0400 Subject: [PATCH 1/5] simpler TypeScript advice --- README.md | 19 +------------------ examples/ts-example/calc.ts | 3 +++ examples/ts-example/main.ts | 4 +--- examples/ts-example/package.json | 4 ---- package.json | 2 -- 5 files changed, 5 insertions(+), 27 deletions(-) create mode 100644 examples/ts-example/calc.ts diff --git a/README.md b/README.md index c7102a16..7b7e9f82 100644 --- a/README.md +++ b/README.md @@ -229,24 +229,7 @@ Sometimes NYC tool might be installed in a different folder not in the current o ## TypeScript users -TypeScript source files are NOT included in the code coverage report by default, even if they are properly instrumented. In order to tell `nyc` to include TS files in the report, you need to: - -1. Add these dev dependencies that let Istanbul work with TypeScript - -```shell -npm i -D @istanbuljs/nyc-config-typescript source-map-support -``` - -2. In `package.json` use the following `nyc` configuration object - -```json -{ - "nyc": { - "extends": "@istanbuljs/nyc-config-typescript", - "all": true - } -} -``` +TypeScript source files should be automatically included in the report, if they are instrumented. See [examples/ts-example](examples/ts-example) diff --git a/examples/ts-example/calc.ts b/examples/ts-example/calc.ts new file mode 100644 index 00000000..e29e78dc --- /dev/null +++ b/examples/ts-example/calc.ts @@ -0,0 +1,3 @@ +export const add = (a: number, b: number) => { + return a + b +} diff --git a/examples/ts-example/main.ts b/examples/ts-example/main.ts index 61e93ad4..18b1d1dc 100644 --- a/examples/ts-example/main.ts +++ b/examples/ts-example/main.ts @@ -1,6 +1,4 @@ -const add = (a: number, b: number) => { - return a + b -} +import { add } from './calc' const sub = (a: number, b: number) => { return a - b diff --git a/examples/ts-example/package.json b/examples/ts-example/package.json index 3f296f79..b45541ca 100644 --- a/examples/ts-example/package.json +++ b/examples/ts-example/package.json @@ -4,10 +4,6 @@ "devDependencies": { "@babel/core": "7.9.0" }, - "nyc": { - "extends": "@istanbuljs/nyc-config-typescript", - "all": true - }, "scripts": { "start": "../../node_modules/.bin/parcel serve index.html", "build": "../../node_modules/.bin/parcel build index.html", diff --git a/package.json b/package.json index 79888dc1..ad715ebe 100644 --- a/package.json +++ b/package.json @@ -54,7 +54,6 @@ }, "devDependencies": { "@babel/core": "7.9.0", - "@istanbuljs/nyc-config-typescript": "1.0.1", "babel-plugin-istanbul": "6.0.0", "check-code-coverage": "1.0.1", "cypress": "4.3.0", @@ -65,7 +64,6 @@ "prettier": "1.19.1", "semantic-release": "17.0.4", "serve": "11.3.0", - "source-map-support": "0.5.16", "start-server-and-test": "1.10.11", "typescript": "3.8.3" } From a7f3a17f01f5690d9685825ca02b2bddf5232f6f Mon Sep 17 00:00:00 2001 From: Gleb Bahmutov Date: Fri, 17 Apr 2020 12:48:50 -0400 Subject: [PATCH 2/5] make debug statement stronger --- .github/ISSUE_TEMPLATE/bug_report.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index a7b4cdba..f7718ec4 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -6,6 +6,9 @@ labels: '' assignees: '' --- +**Logs and screenshots** +Please provide debug logs by running Cypress from the terminal with `DEBUG=code-coverage` environment variable set, see the [Debugging](https://github.com/cypress-io/code-coverage#debugging) section of the README file. + **Versions** - What is this plugin's version? @@ -21,8 +24,5 @@ assignees: '' **Describe the bug** A clear and concise description of what the bug is. -**Logs and screenshots** -If possible, add the log from the terminal. You can turn on debugging logging, see [Debugging](https://github.com/cypress-io/code-coverage#debugging) section of the README file. - **Link to the repo** Bugs with a reproducible example, like an open source repo showing the bug, are the most likely to be resolved. From cd9c7901d64c9d94133e410b59743f963cc11773 Mon Sep 17 00:00:00 2001 From: Gleb Bahmutov Date: Fri, 17 Apr 2020 12:51:28 -0400 Subject: [PATCH 3/5] update checked files --- .circleci/config.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 937a2387..799407b9 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -219,7 +219,8 @@ workflows: name: Check code coverage 📈 command: | ../../node_modules/.bin/check-coverage main.ts - ../../node_modules/.bin/only-covered main.ts + ../../node_modules/.bin/check-coverage calc.ts + ../../node_modules/.bin/only-covered main.ts calc.ts working_directory: examples/ts-example - cypress/run: From 79445984ab8185b496c183d3a8b93ec06846251a Mon Sep 17 00:00:00 2001 From: Gleb Bahmutov Date: Fri, 17 Apr 2020 13:08:33 -0400 Subject: [PATCH 4/5] fix: pass extension from package nyc object --- README.md | 2 ++ task.js | 10 +++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7b7e9f82..952e78c0 100644 --- a/README.md +++ b/README.md @@ -396,6 +396,8 @@ npx nyc report --check-coverage true --lines 100 --include cypress/about.js npx nyc report --check-coverage true --lines 100 --include cypress/unit.js ``` +**Tip:** use [check-code-coverage](https://github.com/bahmutov/check-code-coverage) for stricter code coverage checks than `nyc report --check-coverage` allows. + ### Markdown You can validate links in Markdown files in this directory by executing (Linux + Mac only) script diff --git a/task.js b/task.js index a0a0445c..64bd0406 100644 --- a/task.js +++ b/task.js @@ -148,6 +148,7 @@ const tasks = { // I am mostly worried about additional NYC options that are stored in // package.json and .nycrc resource files. // for now let's just camel case all options + // https://github.com/istanbuljs/nyc#common-configuration-options const nycReportOptions = { reportDir, tempDir: coverageFolder, @@ -156,7 +157,14 @@ const tasks = { exclude: nycOptions.exclude, // from working with TypeScript code seems we need these settings too excludeAfterRemap: true, - extension: ['.js', '.cjs', '.mjs', '.ts', '.tsx', '.jsx'], + extension: nycOptions.extension || [ + '.js', + '.cjs', + '.mjs', + '.ts', + '.tsx', + '.jsx' + ], all: nycOptions.all } From db50dc226a51b925a4458e38592bcddda87a3146 Mon Sep 17 00:00:00 2001 From: Gleb Bahmutov Date: Fri, 17 Apr 2020 13:11:02 -0400 Subject: [PATCH 5/5] link in readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 952e78c0..d462bc04 100644 --- a/README.md +++ b/README.md @@ -231,7 +231,7 @@ Sometimes NYC tool might be installed in a different folder not in the current o TypeScript source files should be automatically included in the report, if they are instrumented. -See [examples/ts-example](examples/ts-example) +See [examples/ts-example](examples/ts-example) and [bahmutov/cra-ts-code-coverage-example](https://github.com/bahmutov/cra-ts-code-coverage-example). ## Exclude code