Code Coverage for Cypress
Learn how to setup Cypress to start reporting code coverage results
Code Coverage for Cypress
Enabling code coverage for Cypress involves the following steps:
Instrumenting the code and generating the coverage report (done by
cypressrunner together with Istanbul or any other coverage tool)Uploading the report to Currents for processing (done by
cypress-cloudpackage)
Instrumenting the code
Instrumenting the code and generating reports is well described in the detailed guide.
In short:
Install and configure the official @cypress/code-coverage plugin together with the
@cypress/code-coverage/supportsupport file (the plugin is developed and maintained by the Cypress.io team)Add code instrumentation - for example, by using
@cypress/code-coverage/use-babelrcfor on-the-fly instrumentation
Uploading the reports to Currents
If you haven’t yet, install
cypress-cloud; make sure to addcypress-cloud/pluginafter@cypress/code-coverageOptional: provide custom location for generated reports:
cypress-cloudexpects to find the coverage reports at their default location at<projectRoot>/.nyc_output/out.jsonYou can provide a custom location by setting
env.coverageFileincypress.config.{jt}s
Example cypress.config.ts file
Example Cypress support.ts file
Run cypress-cloud with coverage enabled
cypress-cloud with coverage enabledRunning cypress-cloud with --experimental-coverage-recording flag will activate the collection of the coverage reports and send them to Currents for processing.
The script will discover the reports at the configured location ./.nyc_output/out.json by default, or an explicit location defined in env.coverageFile of cypress.config.{jt}s
Example:
Last updated
Was this helpful?