Skip to content

Commit 54f4c50

Browse files
authored
Revert "feat!: read code coverage config from Cypress.expose instead of Cypre…"
This reverts commit 8ec0991.
1 parent 8ec0991 commit 54f4c50

File tree

119 files changed

+43782
-14859
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

119 files changed

+43782
-14859
lines changed

.circleci/config.yml

Lines changed: 45 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
version: 2.1
33
orbs:
44
# https://github.com/cypress-io/circleci-orb
5-
cypress: cypress-io/cypress@6.0.0 # used to run e2e tests
5+
cypress: cypress-io/cypress@3.0.0 # used to run e2e tests
66
win: circleci/windows@5.1.0 # run a test job on Windows
77

88
jobs:
@@ -40,21 +40,14 @@ jobs:
4040
steps:
4141
- checkout
4242
- run:
43-
name: Install node 22
44-
command: nvm install 22
43+
name: Install node 20
44+
command: nvm install 20.12.1
4545
- run:
46-
name: Use node 22
47-
command: nvm use 22
46+
name: Use node 20
47+
command: nvm use 20.12.1
4848
- run:
4949
name: Install deps for code coverage
5050
command: npm ci
51-
- run:
52-
name: Build project
53-
command: npm run build
54-
- run:
55-
name: Install test app deps
56-
command: npm i
57-
working_directory: test-apps/all-files
5851
- cypress/run-tests:
5952
# no-workspace: true
6053
start-command: npm run start:windows --prefix test-apps/all-files
@@ -75,18 +68,6 @@ jobs:
7568
command: npm i -D check-code-coverage && npm run coverage:check-files
7669
working_directory: test-apps/all-files
7770

78-
build-dist:
79-
docker:
80-
- image: cimg/node:22.14.0
81-
steps:
82-
- attach_workspace:
83-
at: ~/
84-
- run: npm run build
85-
- persist_to_workspace:
86-
paths:
87-
- project/dist
88-
root: ~/
89-
9071
publish:
9172
description: Publishes the new version of the plugin to NPM
9273
docker:
@@ -104,45 +85,45 @@ jobs:
10485
at: ~/
10586
- run: npm run semantic-release
10687

107-
verify-test-apps:
88+
cyrun:
10889
docker:
109-
- image: cypress/base:22.14.0
90+
- image: cypress/base:16.18.1
11091
parameters:
111-
app:
92+
jobname:
11293
type: string
11394
steps:
11495
- attach_workspace:
11596
at: ~/
116-
- run:
117-
working_directory: test-apps/<< parameters.app >>
118-
command: npm i
11997
- run:
12098
command: npm run test
121-
working_directory: test-apps/<< parameters.app >>
99+
working_directory: test-apps/<< parameters.jobname >>
122100
- store_artifacts:
123-
path: test-apps/<< parameters.app >>/coverage
101+
path: test-apps/<< parameters.jobname >>/coverage
124102
- run:
125103
name: Verify Code Coverage
126104
command: npm run coverage:verify
127-
working_directory: test-apps/<< parameters.app >>
105+
working_directory: test-apps/<< parameters.jobname >>
128106
- run:
129107
name: Check code coverage files 📈
130108
# we will check the final coverage report
131109
# to make sure it only has files we are interested in
132110
# because there are files covered at 0 in the report
133111
command: npm run coverage:check-files
134-
working_directory: test-apps/<< parameters.app >>
112+
working_directory: test-apps/<< parameters.jobname >>
135113

136-
unit-test:
114+
test-code-coverage-plugin:
137115
docker:
138-
- image: cypress/base:24.11.0
116+
- image: cypress/base:16.18.1
139117
steps:
140118
- attach_workspace:
141119
at: ~/
142120
- run:
143121
command: npm run test
144122
- store_artifacts:
145123
path: coverage
124+
- run:
125+
name: Verify Code Coverage
126+
command: npm run coverage:verify
146127

147128
workflows:
148129
build:
@@ -151,25 +132,24 @@ workflows:
151132
- lint:
152133
requires:
153134
- install_and_persist
154-
- unit-test:
135+
136+
- test-code-coverage-plugin:
155137
requires:
156138
- install_and_persist
157-
- build-dist:
158-
requires:
159-
- lint
160-
- unit-test
161-
- verify-test-apps:
139+
140+
- cyrun:
141+
name: test-<< matrix.jobname>>
162142
requires:
163-
- build-dist
143+
- install_and_persist
164144
matrix:
165145
parameters:
166-
app:
146+
jobname:
167147
- all-files
168148
- backend
169149
- batch-send-coverage
170150
- before-all-visit
171151
- before-each-visit
172-
- esm-example
152+
- cra-e2e-and-ct
173153
- exclude-files
174154
- frontend
175155
- fullstack
@@ -181,9 +161,7 @@ workflows:
181161
- unit-tests-js
182162
- use-webpack
183163
- redirect
184-
- windows_test:
185-
requires:
186-
- build-dist
164+
- windows_test
187165
- publish:
188166
context: org-npm-credentials
189167
filters:
@@ -194,5 +172,23 @@ workflows:
194172
- next
195173
- dev
196174
requires:
197-
- verify-test-apps
175+
- lint
176+
- test-code-coverage-plugin
177+
- test-all-files
178+
- test-backend
179+
- test-batch-send-coverage
180+
- test-before-all-visit
181+
- test-before-each-visit
182+
- test-cra-e2e-and-ct
183+
- test-exclude-files
184+
- test-frontend
185+
- test-fullstack
186+
- test-multiple-backends
187+
- test-one-spec
188+
- test-same-folder
189+
- test-support-files
190+
- test-ts-example
191+
- test-unit-tests-js
192+
- test-use-webpack
193+
- test-redirect
198194
- windows_test

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,3 @@ dist/
99
cypress-coverage/
1010
yarn.lock
1111
.parcel-cache
12-
test-apps/*/package-lock.json

README.md

Lines changed: 34 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ module.exports = defineConfig({
3030
// include any other plugin code...
3131

3232
// It's IMPORTANT to return the config object
33-
// with any changes
33+
// with any changed environment variables
3434
return config
3535
},
3636
},
@@ -145,6 +145,21 @@ The code coverage from spec files will be combined with end-to-end coverage.
145145

146146
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).
147147

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.
151+
152+
```js
153+
module.exports = (on, config) => {
154+
require('@cypress/code-coverage/task')(on, config)
155+
on(
156+
'file:preprocessor',
157+
require('@cypress/code-coverage/use-browserify-istanbul')
158+
)
159+
return config
160+
}
161+
```
162+
148163
## Instrument backend code
149164

150165
Example in [test-apps/backend](test-apps/backend) folder.
@@ -187,11 +202,11 @@ if (global.__coverage__) {
187202
}
188203
```
189204

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:
191206

192207
```json
193208
{
194-
"expose": {
209+
"env": {
195210
"codeCoverage": {
196211
"url": "http://localhost:3000/__coverage__"
197212
}
@@ -203,7 +218,7 @@ Or if you have multiple servers from which you are wanting to gather code covera
203218

204219
```json
205220
{
206-
"expose": {
221+
"env": {
207222
"codeCoverage": {
208223
"url": ["http://localhost:3000/__coverage__", "http://localhost:3001/__coverage__"]
209224
}
@@ -225,7 +240,7 @@ After:
225240

226241
```json
227242
{
228-
"expose": {
243+
"env": {
229244
"codeCoverage": {
230245
"url": "http://localhost:3003/__coverage__",
231246
"expectBackendCoverageOnly": true
@@ -242,7 +257,7 @@ If there is ONLY frontend code coverage, set `expectFrontendCoverageOnly: true`
242257

243258
```json
244259
{
245-
"expose": {
260+
"env": {
246261
"codeCoverage": {
247262
"url": "http://localhost:3003/__coverage__",
248263
"expectFrontendCoverageOnly": true
@@ -354,11 +369,11 @@ switch (foo) {
354369

355370
### Exclude files and folders
356371

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:
358373

359374
```javascript
360375
// cypress.config.js or cypress.json
361-
expose: {
376+
env: {
362377
codeCoverage: {
363378
exclude: ['cypress/**/*.*'],
364379
},
@@ -386,18 +401,20 @@ Another important option is `excludeAfterRemap`. By default, it is false, which
386401

387402
## Disable plugin
388403

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`.
390405

391406
```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
394411
```
395412

396413
Or set it to `false` in the `cypress.json` file.
397414

398415
```json
399416
{
400-
"expose": {
417+
"env": {
401418
"coverage": false
402419
}
403420
}
@@ -432,7 +449,6 @@ Full examples we use for testing in this repository:
432449
- [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
433450
- [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
434451
- [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
436452
- [test-apps/use-webpack](test-apps/use-webpack) shows Webpack build with source maps and Babel
437453
- [test-apps/unit-tests-js](test-apps/unit-tests-js) runs just the unit tests and reports code coverage (JavaScript source code)
438454
- [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
463479

464480
## Migrations
465481

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-
500482
### Cypress v9 to v10
501483

502484
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).
@@ -511,7 +493,7 @@ module.exports = (on, config) => {
511493
// add other tasks to be registered here
512494

513495
// IMPORTANT to return the config object
514-
// with the any changes
496+
// with the any changed environment variables
515497
return config
516498
}
517499
```
@@ -530,7 +512,7 @@ module.exports = defineConfig({
530512
// include any other plugin code...
531513

532514
// It's IMPORTANT to return the config object
533-
// with any changes
515+
// with any changed environment variables
534516
return config
535517
},
536518
},
@@ -550,7 +532,7 @@ module.exports = (on, config) => {
550532
module.exports = (on, config) => {
551533
require('@cypress/code-coverage/task')(on, config)
552534
// IMPORTANT to return the config object
553-
// with the any changes
535+
// with the any changed environment variables
554536
return config
555537
}
556538
```
@@ -593,7 +575,8 @@ If you decide to open an issue in this repository, please fill in all informatio
593575
### Coverage reporting timeouts
594576

595577
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
597580
the number of report keys to send per batch.
598581

599582
## Contributing

0 commit comments

Comments
 (0)