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: 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. diff --git a/README.md b/README.md index c7102a16..d462bc04 100644 --- a/README.md +++ b/README.md @@ -229,26 +229,9 @@ 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: +TypeScript source files should be automatically included in the report, if they are instrumented. -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 - } -} -``` - -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 @@ -413,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/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" } 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 }