Skip to content
Saves the code coverage collected during Cypress tests
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.circleci feat: add babelrc helper script (#8) May 20, 2019
cypress feat: add babelrc helper script (#8) May 20, 2019
images update circleci config May 15, 2019
.babelrc initial May 15, 2019
.gitignore initial May 15, 2019
LICENSE.md initial May 15, 2019
README.md add code coverage guide link Jun 14, 2019
cypress.json initial May 15, 2019
package-lock.json chore(deps): update dependency semantic-release to v15.13.16 Jun 15, 2019
package.json chore(deps): update dependency semantic-release to v15.13.16 Jun 15, 2019
renovate.json initial May 15, 2019
support.js feat: save unit test code coverage from specs May 17, 2019
task.js fix: rename the project, close #11 Jun 4, 2019
use-babelrc.js

README.md

@cypress/code-coverage renovate-app badge CircleCI

Saves the code coverage collected during Cypress tests

Install

npm install -D @cypress/code-coverage

and its peer dependencies

npm install -D nyc istanbul-lib-coverage cypress

Add to your cypress/support/index.js file

import '@cypress/code-coverage/support'

Register tasks in your cypress/plugins/index.js file

module.exports = (on, config) => {
  on('task', require('@cypress/code-coverage/task'))
}

If your application is loaded Istanbul-instrumented source code, then the coverage information will be automatically saved into .nyc_output folder and a report will be generated after the tests finish (even in the interactive mode). Find the HTML report in the coverage folder.

Coverage report

That should be it!

Instrument unit tests

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 for example.

Install the plugin

npm i -D babel-plugin-istanbul

Set your .babelrc file

{
  "plugins": ["istanbul"]
}

Put the following in cypress/plugins/index.js file to use .babelrc file

module.exports = (on, config) => {
  on('task', require('@cypress/code-coverage/task'))
  on('file:preprocessor', require('@cypress/code-coverage/use-babelrc'))
}

Now the code coverage from spec files will be combined with end-to-end coverage.

Examples

Debugging

Run tests with DEBUG=code-coverage environment variable to see log messages

License

This project is licensed under the terms of the MIT license.

You can’t perform that action at this time.