diff --git a/.circleci/config.yml b/.circleci/config.yml
index c2a1fa2a1..58e7a99cb 100644
--- a/.circleci/config.yml
+++ b/.circleci/config.yml
@@ -251,6 +251,35 @@ workflows:
node ../../scripts/only-covered main.js
working_directory: examples/support-files
+ - cypress/run:
+ attach-workspace: true
+ name: example-use-plugins-and-support
+ requires:
+ - cypress/install
+ # there are no jobs to follow this one
+ # so no need to save the workspace files (saves time)
+ no-workspace: true
+ command: npx cypress run --project examples/use-plugins-and-support
+ # store screenshots and videos
+ store_artifacts: true
+ post-steps:
+ - run: cat examples/use-plugins-and-support/.nyc_output/out.json
+ # store the created coverage report folder
+ # you can click on it in the CircleCI UI
+ # to see live static HTML site
+ - store_artifacts:
+ path: examples/use-plugins-and-support/coverage
+ # make sure the examples captures 100% of code
+ - run:
+ command: npx nyc report --check-coverage true --lines 100
+ working_directory: examples/use-plugins-and-support
+ - run:
+ name: Check code coverage 📈
+ command: |
+ node ../../scripts/check-coverage main.js
+ node ../../scripts/only-covered main.js
+ working_directory: examples/use-plugins-and-support
+
- publish:
filters:
branches:
@@ -266,3 +295,4 @@ workflows:
- example-ts-example
- example-same-folder
- example-support-files
+ - example-use-plugins-and-support
diff --git a/README.md b/README.md
index b65e42dc0..5cdc0009c 100644
--- a/README.md
+++ b/README.md
@@ -2,9 +2,6 @@
> Saves the code coverage collected during Cypress tests
-**⚠️ Performance Warning**
-This plugin will slow down your tests. There will be more web application JavaScript code to execute due to instrumentation, and there will be code coverage information to merge and save after each test. Track issue [#26](https://github.com/cypress-io/code-coverage/issues/26) for current progress.
-
## Install
```shell
@@ -23,7 +20,10 @@ Register tasks in your `cypress/plugins/index.js` file
```js
module.exports = (on, config) => {
- on('task', require('@cypress/code-coverage/task'))
+ require('@cypress/code-coverage/task')(on, config)
+ // IMPORTANT to return the config object
+ // with the any changed environment variables
+ return config
}
```
@@ -109,8 +109,9 @@ Put the following in `cypress/plugins/index.js` file to use `.babelrc` file
```js
module.exports = (on, config) => {
- on('task', require('@cypress/code-coverage/task'))
+ require('@cypress/code-coverage/task')(on, config)
on('file:preprocessor', require('@cypress/code-coverage/use-babelrc'))
+ return config
}
```
@@ -122,11 +123,12 @@ If you cannot use `.babelrc` for some reason (maybe it is used by other tools?),
```js
module.exports = (on, config) => {
- on('task', require('@cypress/code-coverage/task'))
+ require('@cypress/code-coverage/task')(on, config)
on(
'file:preprocessor',
require('@cypress/code-coverage/use-browserify-istanbul')
)
+ return config
}
```
@@ -349,6 +351,37 @@ npm run dev:no:coverage
- [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
- [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.
+## Migrations
+
+### v2 to v3
+
+Change the plugins file `cypress/plugins/index.js`
+
+```js
+// BEFORE
+module.exports = (on, config) => {
+ on('task', require('@cypress/code-coverage/task'))
+}
+// AFTER
+module.exports = (on, config) => {
+ require('@cypress/code-coverage/task')(on, config)
+ // IMPORTANT to return the config object
+ // with the any changed environment variables
+ return config
+}
+```
+
+**Tip:** we include [plugins.js](plugins.js) file you can point at from your code in simple cases. From your `cypress.json` file:
+
+```json
+{
+ "pluginsFile": "node_modules/@cypress/code-coverage/plugins",
+ "supportFile": "node_modules/@cypress/code-coverage/support"
+}
+```
+
+See [examples/use-plugins-and-support](examples/use-plugins-and-support)
+
## Debugging
This plugin uses [debug](https://github.com/visionmedia/debug) module to output additional logging messages from its [task.js](task.js) file. This can help with debugging errors while saving code coverage or reporting. In order to see these messages, run Cypress from the terminal with environment variable `DEBUG=code-coverage`. Example using Unix syntax to set the variable:
diff --git a/cypress/plugins/index.js b/cypress/plugins/index.js
index f45185fc4..689350e64 100644
--- a/cypress/plugins/index.js
+++ b/cypress/plugins/index.js
@@ -1,5 +1,5 @@
module.exports = (on, config) => {
- on('task', require('../../task'))
+ require('../../task')(on, config)
// also use .babelrc file when bundling spec files
// to get the code coverage from unit tests
@@ -9,4 +9,7 @@ module.exports = (on, config) => {
// or use browserify and just push babel-plugin-istanbul
// directory to the list of babelify plugins
// on('file:preprocessor', require('../../use-browserify-istanbul'))
+
+ // IMPORTANT to return the config object with changed environment variable
+ return config
}
diff --git a/examples/before-all-visit/cypress/plugins/index.js b/examples/before-all-visit/cypress/plugins/index.js
index 172deda45..a7fb752b7 100644
--- a/examples/before-all-visit/cypress/plugins/index.js
+++ b/examples/before-all-visit/cypress/plugins/index.js
@@ -1,3 +1,6 @@
module.exports = (on, config) => {
- on('task', require('../../../../task'))
+ require('../../../../task')(on, config)
+ // IMPORTANT to return the config object
+ // with the any changed environment variables
+ return config
}
diff --git a/examples/before-each-visit/cypress/plugins/index.js b/examples/before-each-visit/cypress/plugins/index.js
index 172deda45..a7fb752b7 100644
--- a/examples/before-each-visit/cypress/plugins/index.js
+++ b/examples/before-each-visit/cypress/plugins/index.js
@@ -1,3 +1,6 @@
module.exports = (on, config) => {
- on('task', require('../../../../task'))
+ require('../../../../task')(on, config)
+ // IMPORTANT to return the config object
+ // with the any changed environment variables
+ return config
}
diff --git a/examples/same-folder/plugins.js b/examples/same-folder/plugins.js
index 723dd9e11..2df3f068a 100644
--- a/examples/same-folder/plugins.js
+++ b/examples/same-folder/plugins.js
@@ -1,4 +1,5 @@
module.exports = (on, config) => {
- on('task', require('../../task'))
+ require('../../task')(on, config)
on('file:preprocessor', require('../../use-babelrc'))
+ return config
}
diff --git a/examples/support-files/cypress/plugins/index.js b/examples/support-files/cypress/plugins/index.js
index 42aa38ea8..b17c48db1 100644
--- a/examples/support-files/cypress/plugins/index.js
+++ b/examples/support-files/cypress/plugins/index.js
@@ -1,4 +1,5 @@
module.exports = (on, config) => {
- on('task', require('../../../../task'))
+ require('../../../../task')(on, config)
on('file:preprocessor', require('../../../../use-babelrc'))
+ return config
}
diff --git a/examples/ts-example/cypress/plugins/index.js b/examples/ts-example/cypress/plugins/index.js
index 172deda45..fa838f18c 100644
--- a/examples/ts-example/cypress/plugins/index.js
+++ b/examples/ts-example/cypress/plugins/index.js
@@ -1,3 +1,4 @@
module.exports = (on, config) => {
- on('task', require('../../../../task'))
+ require('../../../../task')(on, config)
+ return config
}
diff --git a/examples/use-plugins-and-support/README.md b/examples/use-plugins-and-support/README.md
new file mode 100644
index 000000000..0f1251b3b
--- /dev/null
+++ b/examples/use-plugins-and-support/README.md
@@ -0,0 +1,5 @@
+# example: use-plugins-and-support
+
+Using included plugins and support files
+
+See [cypress.json](cypress.json) file
diff --git a/examples/use-plugins-and-support/cypress.json b/examples/use-plugins-and-support/cypress.json
new file mode 100644
index 000000000..3681940e8
--- /dev/null
+++ b/examples/use-plugins-and-support/cypress.json
@@ -0,0 +1,5 @@
+{
+ "pluginsFile": "../../plugins",
+ "supportFile": "../../support",
+ "fixturesFolder": false
+}
diff --git a/examples/use-plugins-and-support/cypress/integration/spec.js b/examples/use-plugins-and-support/cypress/integration/spec.js
new file mode 100644
index 000000000..401618d11
--- /dev/null
+++ b/examples/use-plugins-and-support/cypress/integration/spec.js
@@ -0,0 +1,18 @@
+///