Skip to content

Commit 7c1ee82

Browse files
Update Readme with v10 instructions (#752)
1 parent 794e47a commit 7c1ee82

File tree

1 file changed

+59
-12
lines changed

1 file changed

+59
-12
lines changed

README.md

+59-12
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,31 @@ npm install -D @cypress/code-coverage
1010

1111
**Note:** This plugin assumes that `cypress` is a peer dependency already installed in your project.
1212

13-
Add to your `cypress/support/index.js` file.
13+
Then add the code below to the `supportFile` and `setupNodeEvents` function.
1414

1515
```js
16+
// cypress/support/e2e.js
1617
import '@cypress/code-coverage/support'
1718
```
1819

19-
Register tasks in your `cypress/plugins/index.js` file.
20-
2120
```js
22-
module.exports = (on, config) => {
23-
require('@cypress/code-coverage/task')(on, config)
24-
25-
// add other tasks to be registered here
26-
27-
// IMPORTANT to return the config object
28-
// with the any changed environment variables
29-
return config
30-
}
21+
// cypress.config.js
22+
const { defineConfig } = require('cypress')
23+
24+
module.exports = defineConfig({
25+
// setupNodeEvents can be defined in either
26+
// the e2e or component configuration
27+
e2e: {
28+
setupNodeEvents(on, config) {
29+
require('@cypress/code-coverage/task')(on, config)
30+
// include any other plugin code...
31+
32+
// It's IMPORTANT to return the config object
33+
// with any changed environment variables
34+
return config
35+
},
36+
},
37+
})
3138
```
3239

3340
## Instrument your application
@@ -445,6 +452,46 @@ Look up the list of examples under the GitHub topic [cypress-code-coverage-examp
445452

446453
## Migrations
447454

455+
### Cypress v9 to v10
456+
457+
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).
458+
459+
```js
460+
// BEFORE
461+
// Register tasks in your `cypress/plugins/index.js` file.
462+
463+
module.exports = (on, config) => {
464+
require('@cypress/code-coverage/task')(on, config)
465+
466+
// add other tasks to be registered here
467+
468+
// IMPORTANT to return the config object
469+
// with the any changed environment variables
470+
return config
471+
}
472+
```
473+
474+
```js
475+
// AFTER
476+
// cypress.config.js
477+
const { defineConfig } = require('cypress')
478+
479+
module.exports = defineConfig({
480+
// setupNodeEvents can be defined in either
481+
// the e2e or component configuration
482+
e2e: {
483+
setupNodeEvents(on, config) {
484+
require('@cypress/code-coverage/task')(on, config)
485+
// include any other plugin code...
486+
487+
// It's IMPORTANT to return the config object
488+
// with any changed environment variables
489+
return config
490+
},
491+
},
492+
})
493+
```
494+
448495
### v2 to v3
449496

450497
Change the plugins file `cypress/plugins/index.js`

0 commit comments

Comments
 (0)