Skip to content

Commit 171f77d

Browse files
bahmutovrndmerle
authored andcommitted
fix: simpler TypeScript advice (cypress-io#195)
* fix: and pass extension from package nyc object if provided
1 parent 917fe2e commit 171f77d

File tree

8 files changed

+22
-33
lines changed

8 files changed

+22
-33
lines changed

.circleci/config.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,8 @@ workflows:
219219
name: Check code coverage 📈
220220
command: |
221221
../../node_modules/.bin/check-coverage main.ts
222-
../../node_modules/.bin/only-covered main.ts
222+
../../node_modules/.bin/check-coverage calc.ts
223+
../../node_modules/.bin/only-covered main.ts calc.ts
223224
working_directory: examples/ts-example
224225

225226
- cypress/run:

.github/ISSUE_TEMPLATE/bug_report.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ labels: ''
66
assignees: ''
77
---
88

9+
**Logs and screenshots**
10+
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.
11+
912
**Versions**
1013

1114
- What is this plugin's version?
@@ -21,8 +24,5 @@ assignees: ''
2124
**Describe the bug**
2225
A clear and concise description of what the bug is.
2326

24-
**Logs and screenshots**
25-
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.
26-
2727
**Link to the repo**
2828
Bugs with a reproducible example, like an open source repo showing the bug, are the most likely to be resolved.

README.md

+4-19
Original file line numberDiff line numberDiff line change
@@ -229,26 +229,9 @@ Sometimes NYC tool might be installed in a different folder not in the current o
229229

230230
## TypeScript users
231231

232-
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:
232+
TypeScript source files should be automatically included in the report, if they are instrumented.
233233

234-
1. Add these dev dependencies that let Istanbul work with TypeScript
235-
236-
```shell
237-
npm i -D @istanbuljs/nyc-config-typescript source-map-support
238-
```
239-
240-
2. In `package.json` use the following `nyc` configuration object
241-
242-
```json
243-
{
244-
"nyc": {
245-
"extends": "@istanbuljs/nyc-config-typescript",
246-
"all": true
247-
}
248-
}
249-
```
250-
251-
See [examples/ts-example](examples/ts-example)
234+
See [examples/ts-example](examples/ts-example) and [bahmutov/cra-ts-code-coverage-example](https://github.com/bahmutov/cra-ts-code-coverage-example).
252235

253236
## Exclude code
254237

@@ -413,6 +396,8 @@ npx nyc report --check-coverage true --lines 100 --include cypress/about.js
413396
npx nyc report --check-coverage true --lines 100 --include cypress/unit.js
414397
```
415398

399+
**Tip:** use [check-code-coverage](https://github.com/bahmutov/check-code-coverage) for stricter code coverage checks than `nyc report --check-coverage` allows.
400+
416401
### Markdown
417402

418403
You can validate links in Markdown files in this directory by executing (Linux + Mac only) script

examples/ts-example/calc.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const add = (a: number, b: number) => {
2+
return a + b
3+
}

examples/ts-example/main.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
const add = (a: number, b: number) => {
2-
return a + b
3-
}
1+
import { add } from './calc'
42

53
const sub = (a: number, b: number) => {
64
return a - b

examples/ts-example/package.json

-4
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@
44
"devDependencies": {
55
"@babel/core": "7.9.0"
66
},
7-
"nyc": {
8-
"extends": "@istanbuljs/nyc-config-typescript",
9-
"all": true
10-
},
117
"scripts": {
128
"start": "../../node_modules/.bin/parcel serve index.html",
139
"build": "../../node_modules/.bin/parcel build index.html",

package.json

-2
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454
},
5555
"devDependencies": {
5656
"@babel/core": "7.9.0",
57-
"@istanbuljs/nyc-config-typescript": "1.0.1",
5857
"babel-plugin-istanbul": "6.0.0",
5958
"check-code-coverage": "1.0.1",
6059
"cypress": "4.3.0",
@@ -65,7 +64,6 @@
6564
"prettier": "1.19.1",
6665
"semantic-release": "17.0.4",
6766
"serve": "11.3.0",
68-
"source-map-support": "0.5.16",
6967
"start-server-and-test": "1.10.11",
7068
"typescript": "3.8.3"
7169
}

task.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ const tasks = {
148148
// I am mostly worried about additional NYC options that are stored in
149149
// package.json and .nycrc resource files.
150150
// for now let's just camel case all options
151+
// https://github.com/istanbuljs/nyc#common-configuration-options
151152
const nycReportOptions = {
152153
reportDir,
153154
tempDir: coverageFolder,
@@ -156,7 +157,14 @@ const tasks = {
156157
exclude: nycOptions.exclude,
157158
// from working with TypeScript code seems we need these settings too
158159
excludeAfterRemap: true,
159-
extension: ['.js', '.cjs', '.mjs', '.ts', '.tsx', '.jsx'],
160+
extension: nycOptions.extension || [
161+
'.js',
162+
'.cjs',
163+
'.mjs',
164+
'.ts',
165+
'.tsx',
166+
'.jsx'
167+
],
160168
all: nycOptions.all
161169
}
162170

0 commit comments

Comments
 (0)