Cypress CTRF JSON Reporter
cypress-ctrf-json-reporter is a Cypress test reporter designed to generate JSON reports conforming to the Common Test Report Format (CTRF) open standard. Currently at version `0.0.14`, this package is in its early development stages, with releases primarily focused on dependency updates and repository hygiene, indicating a maintenance-oriented cadence rather than active feature development. Its primary differentiator is the strict adherence to CTRF, a community-driven specification that ensures uniform, framework-agnostic test reports. This standardization allows for consistent validation, merging, comparison, and analysis of test results across diverse programming languages and testing frameworks, thereby improving CI/CD pipeline integration and analytics. It seamlessly integrates into Cypress configurations, outputting a `ctrf-report.json` file by default.
Common errors
-
Only one listener can be registered for 'after:run' event. Multiple plugins are conflicting.
cause Cypress's plugin system allows only one listener per event. If multiple reporters or plugins try to register for the same lifecycle event (e.g., `after:run`), the last one registered overrides previous ones.fixRefer to the 'Handling Multiple Plugins in Cypress' section in the reporter's README for guidance on how to manage and merge multiple event listeners, ensuring all plugins work together without conflict. This often involves a custom `setupNodeEvents` helper. -
TypeError: GenerateCtrfReport is not a constructor or function.
cause This usually indicates that the `GenerateCtrfReport` symbol was not correctly imported or required, or that the `new` keyword was omitted when instantiating the class.fixEnsure `const { GenerateCtrfReport } = require('cypress-ctrf-json-reporter')` (for CJS) or `import { GenerateCtrfReport } from 'cypress-ctrf-json-reporter'` (for ESM/TS) is used, and always instantiate it with `new GenerateCtrfReport({...})`.
Warnings
- gotcha The package is still in early development (v0.0.x), which typically means API stability is not guaranteed, and breaking changes might occur in minor releases.
- breaking Cypress versions below v10 require a different installation approach, placing the reporter initialization in `cypress/plugins/index.js` instead of `cypress.config.js`'s `setupNodeEvents` function.
Install
-
npm install cypress-ctrf-json-reporter -
yarn add cypress-ctrf-json-reporter -
pnpm add cypress-ctrf-json-reporter
Imports
- GenerateCtrfReport
import { GenerateCtrfReport } from 'cypress-ctrf-json-reporter'const { GenerateCtrfReport } = require('cypress-ctrf-json-reporter') - GenerateCtrfReport
import GenerateCtrfReport from 'cypress-ctrf-json-reporter'
import { GenerateCtrfReport } from 'cypress-ctrf-json-reporter' - GenerateCtrfReportOptions
import type { GenerateCtrfReportOptions } from 'cypress-ctrf-json-reporter'
Quickstart
const { defineConfig } = require('cypress');
const { GenerateCtrfReport } = require('cypress-ctrf-json-reporter');
module.exports = defineConfig({
e2e: {
setupNodeEvents(on, config) {
// Implement node event listeners here
new GenerateCtrfReport({
on,
outputFile: 'my-custom-report.json',
appName: 'My Cypress App',
buildNumber: process.env.CI_BUILD_NUMBER ?? 'local'
});
},
},
});
// To run:
// npx cypress run