Code Coverage for Cypress
Learn how to setup Cypress to start reporting code coverage results
Last updated
Was this helpful?
Was this helpful?
// cypress.config.ts
import coveragePlugin from "@cypress/code-coverage/task";
import coverageInstrumenter from "@cypress/code-coverage/use-babelrc";
import { cloudPlugin } from "cypress-cloud/plugin";
import { defineConfig } from "cypress";
export default defineConfig({
e2e: {
async setupNodeEvents(on, config) {
// enable on-the-file instrumentation
on("file:preprocessor", coverageInstrumenter);
// enable coverage plugin to generate a report
const tempConfig = coveragePlugin(on, config);
// enable cypress-cloud plugin
return await cloudPlugin(on, tempConfig);
},
baseUrl: "<http://localhost:8888>",
supportFile: "cypress/support/e2e.js",
specPattern: "cypress/**/*.cy.js",
env: {
// @cypress/code-coverage config
// exclude test files from the reports
codeCoverage: {
exclude: ["cypress/**/*.*"],
},
// ⭐️ instruct cypress-cloud on the location of the generated report
coverageFile: "./.nyc_output/out.json",
},
},
});import "@cypress/code-coverage/support";
import "cypress-cloud/support";npx cypress-cloud run --parallel --record --key <record_key> --ci-build-id <ci-build-id> --experimental-coverage-recording