You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: use nyc NPM dependency directly without bin executable (cypress-io#162)
BREAKING CHANGE: `nyc` is no longer a peer dependency, instead
this module calls its API directly.
* use nyc as direct dependency
* feat: use nyc directly as a module
* skip binary install, closecypress-io#163
* hide CircleCI PR env variables
* add typescript example
* run ts-example server
* update README file
* use command
* feat: move istanbul-lib-coverage from peer to prod dependencies
* describe how to generate other reports
* add link to Docker example, closecypress-io#164
Copy file name to clipboardExpand all lines: README.md
+40-46Lines changed: 40 additions & 46 deletions
Original file line number
Diff line number
Diff line change
@@ -11,11 +11,7 @@ This plugin will slow down your tests. There will be more web application JavaSc
11
11
npm install -D @cypress/code-coverage
12
12
```
13
13
14
-
and its peer dependencies
15
-
16
-
```shell
17
-
npm install -D nyc istanbul-lib-coverage cypress
18
-
```
14
+
Note: this plugin assumes `cypress` is a peer dependency already installed in your project.
19
15
20
16
Add to your `cypress/support/index.js` file
21
17
@@ -57,6 +53,40 @@ If you have instrumented your application's code and see the `window.__coverage_
57
53
58
54
That should be it!
59
55
56
+
## Reports
57
+
58
+
The `coverage` folder has results in several formats, and the coverage raw data is stored in `.nyc_output` folder. You can see the coverage numbers yourself. This plugin has `nyc` as a dependency, so it should be available right away. Here are common examples:
59
+
60
+
```shell
61
+
# see just the coverage summary
62
+
$ npx nyc report --reporter=text-summary
63
+
# see just the coverage file by file
64
+
$ npx nyc report --reporter=text
65
+
# save the HTML report again
66
+
$ npx nyc report --reporter=lcov
67
+
```
68
+
69
+
It is useful to enforce [minimum coverage](https://github.com/istanbuljs/nyc#common-configuration-options) numbers. For example:
ERROR: Coverage for lines (100%) does not meet global threshold (101%)
88
+
```
89
+
60
90
## Instrument unit tests
61
91
62
92
If you test your application code directly from `specs` you might want to instrument them and combine unit test code coverage with any end-to-end code coverage (from iframe). You can easily instrument spec files using [babel-plugin-istanbul](https://github.com/istanbuljs/babel-plugin-istanbul) for example.
@@ -181,17 +211,6 @@ You can specify custom coverage reporter(s) to use. For example to output text s
181
211
182
212
**Tip:** find list of reporters [here](https://istanbul.js.org/docs/advanced/alternative-reporters/)
183
213
184
-
## NYC
185
-
186
-
This module tries to find the `nyc` tool using [bin-up][bin-up], so it would be found in the current `node_modules/.bin` or folders up the parent chain
187
-
188
-
```text
189
-
node_modules/.bin/
190
-
../node_modules/.bin/
191
-
../../node_modules/.bin/
192
-
etc
193
-
```
194
-
195
214
## Custom NYC command
196
215
197
216
Sometimes NYC tool might be installed in a different folder not in the current or parent folder, or you might want to customize the report command. In that case, put the custom command into `package.json` in the current folder and this plugin will automatically use it.
@@ -204,42 +223,14 @@ Sometimes NYC tool might be installed in a different folder not in the current o
204
223
}
205
224
```
206
225
207
-
See examples below.
208
-
209
-
### Install NYC on the fly
210
-
211
-
The simplest solution: let `npx` install `nyc` on the fly
**Tip:** finding and running pre-installed tool is always faster than installing it again and again.
234
-
235
226
## TypeScript users
236
227
237
228
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:
238
229
239
230
1. Add these dev dependencies that let Istanbul work with TypeScript
240
231
241
232
```shell
242
-
npm i -D @istanbuljs/nyc-config-typescript source-map-support ts-node
233
+
npm i -D @istanbuljs/nyc-config-typescript source-map-support
243
234
```
244
235
245
236
2. In `package.json` use the following `nyc` configuration object
@@ -253,6 +244,8 @@ npm i -D @istanbuljs/nyc-config-typescript source-map-support ts-node
253
244
}
254
245
```
255
246
247
+
See [examples/ts-example](examples/ts-example)
248
+
256
249
## Exclude code
257
250
258
251
You can exclude parts of the code or entire files from the code coverage report. See [Istanbul guide](https://github.com/gotwarlost/istanbul/blob/master/ignoring-code-for-coverage.md). Common cases:
@@ -337,6 +330,7 @@ npm run dev:no:coverage
337
330
338
331
-[examples/before-each-visit](examples/before-each-visit) checks if code coverage correctly keeps track of code when doing `cy.visit` before each test
339
332
-[examples/before-all-visit](examples/before-all-visit) checks if code coverage works when `cy.visit` is made once in the `before` hook
333
+
-[examples/ts-example](examples/ts-example) uses Babel + Parcel to instrument and serve TypeScript file
340
334
341
335
### External examples
342
336
@@ -353,6 +347,7 @@ npm run dev:no:coverage
353
347
-[bahmutov/next-and-cypress-example](https://github.com/bahmutov/next-and-cypress-example) shows how to get backend and frontend coverage for a [Next.js](https://nextjs.org) project. Uses [middleware/nextjs.js](middleware/nextjs.js).
354
348
-[akoidan/vue-webpack-typescript](https://github.com/akoidan/vue-webpack-typescript) Pure webpack config with vue + typescript with codecov reports. This setup uses babel-loader with TS checker as a separate thread.
355
349
-[bahmutov/code-coverage-subfolder-example](https://github.com/bahmutov/code-coverage-subfolder-example) shows how to instrument `app` folder using `nyc instrument` as a separate step before running E2E tests
350
+
-[bahmutov/docker-with-cypress-included-code-coverage-example](https://github.com/bahmutov/docker-with-cypress-included-code-coverage-example) runs tests inside pre-installed Cypress using [cypress/included:x.y.z](https://github.com/cypress-io/cypress-docker-images/tree/master/included) Docker image and reports code coverage.
356
351
357
352
## Debugging
358
353
@@ -392,4 +387,3 @@ This project is licensed under the terms of the [MIT license](LICENSE.md).
0 commit comments