Implementation:Cypress io Cypress Exit and Reporter Results
Appearance
| Knowledge Sources | |
|---|---|
| Domains | CI_CD, Testing |
| Last Updated | 2026-02-12 00:00 GMT |
Overview
Concrete tools for aggregating test results and exiting the process with appropriate status codes provided by the Cypress server modules.
Description
Two key components handle CI result processing:
- The exit function (packages/server/lib/cypress.ts:L23-47) manages clean process termination with telemetry span recording
- The Reporter.results method (packages/server/lib/reporter.js:L598-646) aggregates results from the Mocha reporter with stats, hooks, and test data
Usage
Called at the end of cypress run to produce the final test summary and exit code.
Code Reference
Source Location
- Repository: cypress-io/cypress
- Files:
- packages/server/lib/cypress.ts:L23-47 (exit)
- packages/server/lib/cypress.ts:L263-284 (run mode exit handler)
- packages/server/lib/reporter.js:L598-646 (Reporter.results)
- packages/server/lib/reporter.js:L278-288 (Reporter class)
Signature
// Exit function
const exit = async (code?: number): Promise<never> => {
// Records telemetry span with exitCode
// Calls process.exit(code)
}
// Reporter results (JavaScript class)
class Reporter {
results(): {
stats: object
reporter: string
reporterStats: object
hooks: Array
tests: Array
}
}
Import
// Internal server modules
import { exit } from '@packages/server/lib/cypress'
import Reporter from '@packages/server/lib/reporter'
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| code | number | No | Exit code (default 0) |
| Reporter state | internal | Yes | Accumulated test results from spec execution |
Outputs
| Name | Type | Description |
|---|---|---|
| process.exit | void | Process terminates with specified exit code |
| results | object | Aggregated stats, tests, hooks from reporter |
| JUnit XML | file | Optional JUnit report if reporter configured |
Usage Examples
JUnit Reporter Configuration
# Generate JUnit XML for CI dashboard
npx cypress run --reporter junit --reporter-options "mochaFile=results/output.xml"
Multiple Reporters
// cypress.config.ts
import { defineConfig } from 'cypress'
export default defineConfig({
reporter: 'cypress-multi-reporters',
reporterOptions: {
reporterEnabled: 'spec, mocha-junit-reporter',
mochaJunitReporterReporterOptions: {
mochaFile: 'results/output-[hash].xml',
},
},
})
Related Pages
Implements Principle
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment