Cypress CircleCI Reporter
cypress-circleci-reporter is a specialized test reporter for Cypress, designed to integrate seamlessly with CircleCI's test parallelization features. Based on `mocha-junit-reporter`, it generates JUnit XML reports and leverages test timing data to optimize test distribution across parallel CircleCI containers. This allows for faster feedback cycles in CI/CD pipelines. The current stable version is 0.5.0, with releases occurring intermittently but actively since 2020. Key differentiators include its focus on enhancing CircleCI's built-in parallelization, the ability to specify report output directories and filenames with hash-based uniqueness, and a `consoleOutput` option for real-time test status in the terminal. It requires Cypress 3.8.3 or newer and `mocha` as a peer dependency.
Common errors
-
Error: Cannot find module 'mocha'
cause The `mocha` package is a peer dependency but was not installed in your project.fixRun `npm install mocha --save-dev` or `yarn add mocha --dev` to install the `mocha` test framework. -
Error: Reporter "cypress-circleci-reporter" not found.
cause The reporter package is either not installed, misspelled in the configuration, or Cypress cannot resolve its path.fixVerify the package name is correctly spelled in your `cypress.config.js` or CLI command, and ensure `npm install cypress-circleci-reporter` was run successfully. -
Invalid reporter option 'resultFileName': Must include '[hash]' placeholder.
cause The `resultFileName` option was provided without the mandatory `[hash]` string, which is required for generating unique report filenames.fixModify your `reporterOptions` to include `resultFileName: 'my-report-[hash].xml'` (or similar) to ensure unique filenames.
Warnings
- breaking Version 0.2.0 moved `mocha` from direct dependency to a peer dependency. This means `mocha` must now be explicitly installed in your project.
- gotcha The `resultFileName` reporter option MUST include the `[hash]` placeholder. This is crucial for generating unique report files when Cypress runs multiple spec files, especially in parallel environments, as each spec is processed separately. Without it, reports might overwrite each other.
- gotcha This reporter is designed for Cypress 3.8.3 or newer. Using older Cypress versions may lead to unexpected behavior or incompatibilities.
- gotcha Effective test parallelization relies on CircleCI's `circleci tests glob` and `circleci tests split --split-by=timings` commands. Incorrect usage or omission of these commands will prevent the reporter from aiding in optimized test distribution.
Install
-
npm install cypress-circleci-reporter -
yarn add cypress-circleci-reporter -
pnpm add cypress-circleci-reporter
Imports
- Reporter Configuration String
import { CypressCircleciReporter } from 'cypress-circleci-reporter';module.exports = defineConfig({ e2e: { reporter: 'cypress-circleci-reporter', reporterOptions: { resultsDir: './test_results/cypress', resultFileName: 'cypress-[hash].xml' } } }); - CLI Reporter Flag
cypress run --reporter require('cypress-circleci-reporter')cypress run --reporter cypress-circleci-reporter --reporter-options "resultsDir=./results/cypress,resultFileName=report-[hash].xml"
- ReporterOptions (TypeScript Type)
import ReporterOptions from 'cypress-circleci-reporter';
import { ReporterOptions } from 'cypress-circleci-reporter';
Quickstart
import { defineConfig } from 'cypress';
module.exports = defineConfig({
e2e: {
// Configure the reporter and its options
reporter: 'cypress-circleci-reporter',
reporterOptions: {
project: process.env.CYPRESS_PROJECT_NAME ?? undefined, // Optional: if you use Cypress' project parameter
resultsDir: './test_results/cypress', // Directory for JUnit XML reports
resultFileName: 'cypress-[hash].xml', // Filename for each report, [hash] is crucial for uniqueness
consoleOutput: true // Enable console output for test results
},
// Implement node event listeners if needed (e.g., for code coverage, though not direct reporter usage)
setupNodeEvents(on, config) {
// This is where you might include other Cypress plugins if necessary
// For cypress-circleci-reporter, primary setup is through the 'reporter' key above.
return config;
}
}
});
// In your package.json scripts:
// "scripts": {
// "cypress:ci": "yarn cypress run --spec \"$(circleci tests glob \"./cypress/e2e/**/*.cy.js\" | circleci tests split --split-by=timings | paste -sd \",\" -)\" --reporter cypress-circleci-reporter"
// }
// Example CircleCI config snippet:
// run_cypress_tests:
// parallelism: 3
// steps:
// - run:
// name: Run cypress tests
// command: |
// yarn cypress run --spec "$(circleci tests glob "./cypress/e2e/**/*.cy.js" | circleci tests split --split-by=timings | paste -sd "," -)" \
// --reporter cypress-circleci-reporter \
// --reporter-options "resultsDir=./test_results/cypress,resultFileName=cypress-[hash].xml,consoleOutput=true"
// - store_test_results:
// path: test_results
// - store_artifacts:
// path: test_results