Mocha Common Test Report Format (CTRF) JSON Reporter

0.0.11 · active · verified Sun Apr 19

This package provides a Mocha test reporter that generates test results in the Common Test Report Format (CTRF) as a JSON file. CTRF is an open, community-driven standard for normalizing test reports across different programming languages and test frameworks, enabling consistent validation, merging, comparison, and analysis of test results. The current stable version is `0.0.11`. Releases appear to be ad-hoc, primarily driven by dependency updates or feature additions, without a strict cadence. Its key differentiator is its adherence to the CTRF specification, providing a standardized output that integrates into a broader ecosystem of tools designed to consume CTRF data, abstracting away framework-specific report parsing. This allows for unified reporting in CI/CD pipelines.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates installation, configuration via `.mocharc.js` with custom options including environment variables, and running example Mocha tests to generate a CTRF-compliant JSON report.

npm install --save-dev mocha mocha-ctrf-json-reporter

// .mocharc.js
module.exports = {
  reporter: 'mocha-ctrf-json-reporter',
  reporterOptions: {
    outputFile: 'my-custom-ctrf-report.json',
    outputDir: './test-reports',
    appName: 'MyAwesomeApp',
    appVersion: '1.0.0',
    buildName: 'CI Build',
    buildNumber: process.env.CI_BUILD_NUMBER ?? 'local-run',
    testEnvironment: process.env.NODE_ENV ?? 'development'
  }
};

// test/example.test.js
const assert = require('assert');

describe('Application Feature', function() {
  it('should handle basic arithmetic correctly', function() {
    assert.strictEqual(2 + 2, 4);
  });

  it('should skip this test as an example', function() {
    this.skip();
    assert.fail('This test should not be executed');
  });

  it('should correctly identify string length', function() {
    assert.strictEqual('hello'.length, 5);
  });
});

// To run the tests, add to package.json scripts:
// "scripts": {
//   "test": "mocha"
// }
// Then run: npm test
// The report will be found at ./test-reports/my-custom-ctrf-report.json

view raw JSON →