Skip to main content

Mocha Reporter

The Testream Mocha Reporter generates CTRF test reports from Mocha and uploads them to Testream.

Installation

npm install --save-dev @testream/mocha-reporter

Basic Configuration

Add the reporter to your .mocharc.js:

.mocharc.js
module.exports = {
reporter: "@testream/mocha-reporter",
"reporter-option": [
`apiKey=${process.env.TESTREAM_API_KEY}`,
"uploadEnabled=true",
],
};

Configuration Options

OptionTypeDefaultDescription
apiKeystring-Required Testream API key
uploadEnabledbooleantrueEnable/disable automatic upload
failOnUploadErrorbooleanfalseFail the test run if upload fails
branchstringauto (CI)Git branch name
commitShastringauto (CI)Git commit SHA
repositoryUrlstringauto (CI)Git repository URL
testTypestring-Test type (e.g., unit, integration, e2e)
appNamestring-Application name
appVersionstring-Application version
buildNamestring-Build name
buildNumberstringauto (CI)Build number
buildUrlstringauto (CI)Build URL
testEnvironmentstring-Test environment (e.g., ci, staging)

Full Configuration Example

.mocharc.js
module.exports = {
spec: "test/**/*.spec.js",
timeout: 30000,
reporter: "@testream/mocha-reporter",
"reporter-option": [
`apiKey=${process.env.TESTREAM_API_KEY}`,
"uploadEnabled=true",
"failOnUploadError=false",
`buildName=${process.env.GITHUB_WORKFLOW || "mocha-tests"}`,
`testEnvironment=${process.env.TEST_ENV || "ci"}`,
`appName=${process.env.APP_NAME || "my-app"}`,
`appVersion=${process.env.APP_VERSION || "1.0.0"}`,
"testType=unit",
],
};

Notes

  • The reporter writes the CTRF report to ctrf/ctrf-report.json.
  • Git and CI metadata can be auto-detected when running in supported CI providers.
  • Mocha passes reporter options as strings (key=value), including booleans.

Sample Project

The testream/mocha-jira-reporter repository is a complete working example of a Mocha project integrated with Testream. It includes example tests, full reporter configuration, and a ready-to-use GitHub Actions workflow.

NPM Package

What's Next?