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
Copy file name to clipboardExpand all lines: README.md
+34-51Lines changed: 34 additions & 51 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -30,7 +30,7 @@ module.exports = defineConfig({
30
30
// include any other plugin code...
31
31
32
32
// It's IMPORTANT to return the config object
33
-
// with any changes
33
+
// with any changed environment variables
34
34
return config
35
35
},
36
36
},
@@ -145,6 +145,21 @@ The code coverage from spec files will be combined with end-to-end coverage.
145
145
146
146
Find examples of just the unit tests and JavaScript source files with collected code coverage in [test-apps/unit-tests-js](./test-apps/unit-tests-js).
147
147
148
+
### Alternative for unit tests
149
+
150
+
If you cannot use `.babelrc` (maybe it is used by other tools?), try using the Browserify transformer included with this module in the `use-browserify-istanbul` file.
Example in [test-apps/backend](test-apps/backend) folder.
@@ -187,11 +202,11 @@ if (global.__coverage__) {
187
202
}
188
203
```
189
204
190
-
3. Save the API coverage endpoint in the `cypress.json` file to let the plugin know where to call to receive the code coverage data from the server. Place it in `expose.codeCoverage` object:
205
+
3. Save the API coverage endpoint in the `cypress.json` file to let the plugin know where to call to receive the code coverage data from the server. Place it in `env.codeCoverage` object:
191
206
192
207
```json
193
208
{
194
-
"expose": {
209
+
"env": {
195
210
"codeCoverage": {
196
211
"url": "http://localhost:3000/__coverage__"
197
212
}
@@ -203,7 +218,7 @@ Or if you have multiple servers from which you are wanting to gather code covera
@@ -242,7 +257,7 @@ If there is ONLY frontend code coverage, set `expectFrontendCoverageOnly: true`
242
257
243
258
```json
244
259
{
245
-
"expose": {
260
+
"env": {
246
261
"codeCoverage": {
247
262
"url": "http://localhost:3003/__coverage__",
248
263
"expectFrontendCoverageOnly": true
@@ -354,11 +369,11 @@ switch (foo) {
354
369
355
370
### Exclude files and folders
356
371
357
-
The code coverage plugin will automatically exclude any test/spec files you have defined in the `testFiles` (Cypress < v10) or `specPattern` (Cypress >= v10) configuration options. Additionally, you can set the `exclude` pattern glob in the code coverage configuration key to specify additional files to be excluded:
372
+
The code coverage plugin will automatically exclude any test/spec files you have defined in the `testFiles` (Cypress < v10) or `specPattern` (Cypress >= v10) configuration options. Additionally, you can set the `exclude` pattern glob in the code coverage environment variable to specify additional files to be excluded:
358
373
359
374
```javascript
360
375
// cypress.config.js or cypress.json
361
-
expose: {
376
+
env: {
362
377
codeCoverage: {
363
378
exclude: ['cypress/**/*.*'],
364
379
},
@@ -386,18 +401,20 @@ Another important option is `excludeAfterRemap`. By default, it is false, which
386
401
387
402
## Disable plugin
388
403
389
-
You can skip the client-side code coverage hooks by setting the exposed `coverage` value to `false`.
404
+
You can skip the client-side code coverage hooks by setting the environment variable `coverage` to `false`.
390
405
391
406
```shell
392
-
# tell Cypress to set the exposed variable "coverage" to false
393
-
cypress run --expose coverage=false
407
+
# tell Cypress to set environment variable "coverage" to false
408
+
cypress run --env coverage=false
409
+
# or pass the environment variable
410
+
CYPRESS_COVERAGE=false cypress run
394
411
```
395
412
396
413
Or set it to `false` in the `cypress.json` file.
397
414
398
415
```json
399
416
{
400
-
"expose": {
417
+
"env": {
401
418
"coverage": false
402
419
}
403
420
}
@@ -432,7 +449,6 @@ Full examples we use for testing in this repository:
432
449
-[test-apps/before-each-visit](test-apps/before-each-visit) checks if code coverage correctly keeps track of code when doing `cy.visit` before each test
433
450
-[test-apps/one-spec](test-apps/one-spec) confirms that coverage is collected and filtered correctly if the user only executes a single Cypress test
434
451
-[test-apps/ts-example](test-apps/ts-example) uses Babel + Parcel to instrument and serve TypeScript file
435
-
-[test-apps/esm-example](test-apps/esm-example) demonstrates using ES module syntax (`import`/`export`) with the plugin
436
452
-[test-apps/use-webpack](test-apps/use-webpack) shows Webpack build with source maps and Babel
437
453
-[test-apps/unit-tests-js](test-apps/unit-tests-js) runs just the unit tests and reports code coverage (JavaScript source code)
438
454
-[test-apps/unit-tests-ts](test-apps/ts-example) runs just the unit tests and reports code coverage (TypeScript source code)
@@ -463,40 +479,6 @@ Look up the list of examples under the GitHub topic [cypress-code-coverage-examp
463
479
464
480
## Migrations
465
481
466
-
### `@cypress/code-coverage` 3.x to 4.x
467
-
468
-
`Cypress.env()` was deprecated in Cypress v15.10.0, and will be removed in Cypress 16. This necessitates a breaking change to how you configure `@cypress/code-coverage`.
469
-
470
-
```js
471
-
// BEFORE
472
-
// Configure in the `env` key in your Cypress config:
473
-
const { defineConfig } =require('cypress')
474
-
475
-
module.exports=defineConfig({
476
-
env: {
477
-
codeCoverage: {
478
-
url:'http://localhost:1234/__coverage__',
479
-
exclude:'cypress/**/*.*'
480
-
}
481
-
}
482
-
})
483
-
```
484
-
485
-
```js
486
-
// AFTER
487
-
// Configure in the `expose` key in your Cypress config:
488
-
const { defineConfig } =require('cypress')
489
-
490
-
module.exports=defineConfig({
491
-
expose: {
492
-
codeCoverage: {
493
-
url:'http://localhost:1234/__coverage__',
494
-
exclude:'cypress/**/*.*'
495
-
}
496
-
}
497
-
})
498
-
```
499
-
500
482
### Cypress v9 to v10
501
483
502
484
With the removal of the `plugins` directory in Cypress version 10+, you'll need to add all of your configuration into the configuration file (`cypress.config.js` by default).
@@ -593,7 +575,8 @@ If you decide to open an issue in this repository, please fill in all informatio
593
575
### Coverage reporting timeouts
594
576
595
577
If the plugin times out when sending coverage report data to be merged, this may be due to a very large
596
-
report being sent across processes. You can batch the report by setting the `sendCoverageBatchSize` value in your `cypress.config.js` file's `expose` section. Assign the variable an integer value representing
578
+
report being sent across processes. You can batch the report by setting the `sendCoverageBatchSize` environment
579
+
variable in your `cypress.config.js` file's 'env' section. Assign the variable an integer value representing
0 commit comments