{"id":14967357,"url":"https://github.com/ctrf-io/mocha-ctrf-json-reporter","last_synced_at":"2026-04-01T21:51:55.233Z","repository":{"id":245261293,"uuid":"735280154","full_name":"ctrf-io/mocha-ctrf-json-reporter","owner":"ctrf-io","description":"A Mocha JSON test results reporter that follows the CTRF schema","archived":false,"fork":false,"pushed_at":"2025-03-12T21:49:20.000Z","size":292,"stargazers_count":9,"open_issues_count":4,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-04T07:40:24.962Z","etag":null,"topics":["mocha","mocha-reporter","test-automation","test-reporting"],"latest_commit_sha":null,"homepage":"https://ctrf.io","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ctrf-io.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-12-24T10:35:36.000Z","updated_at":"2025-05-27T13:23:36.000Z","dependencies_parsed_at":"2024-06-21T00:52:57.963Z","dependency_job_id":"3a1417db-181e-46d0-8ea7-db93c1347797","html_url":"https://github.com/ctrf-io/mocha-ctrf-json-reporter","commit_stats":null,"previous_names":["ctrf-io/mocha-ctrf-json-reporter"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ctrf-io/mocha-ctrf-json-reporter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ctrf-io%2Fmocha-ctrf-json-reporter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ctrf-io%2Fmocha-ctrf-json-reporter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ctrf-io%2Fmocha-ctrf-json-reporter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ctrf-io%2Fmocha-ctrf-json-reporter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ctrf-io","download_url":"https://codeload.github.com/ctrf-io/mocha-ctrf-json-reporter/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ctrf-io%2Fmocha-ctrf-json-reporter/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266465384,"owners_count":23933120,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-22T02:00:09.085Z","response_time":66,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["mocha","mocha-reporter","test-automation","test-reporting"],"created_at":"2024-09-24T13:37:54.130Z","updated_at":"2026-04-01T21:51:55.220Z","avatar_url":"https://github.com/ctrf-io.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Mocha JSON test results report\n\n\u003e Save Mocha test results as a JSON file\n\nA Mocha JSON test reporter to create test reports that follow the CTRF standard.\n\n[Common Test Report Format](https://ctrf.io) ensures the generation of uniform JSON test reports, independent of programming languages or test framework in use.\n\n## CTRF Open Standard\n\nCTRF is a community-driven open standard for test reporting.\n\nBy standardizing test results, reports can be validated, merged, compared, and analyzed consistently across languages and frameworks.\n\n- **CTRF Specification**: https://github.com/ctrf-io/ctrf  \n  The official specification defining the format and semantics\n- **Discussions**: https://github.com/orgs/ctrf-io/discussions  \n  Community forum for questions, ideas, and support\n\n\u003e [!NOTE]  \n\u003e ⭐ Starring the **CTRF specification repository** (https://github.com/ctrf-io/ctrf)\n\u003e helps support the standard.\n\n## Features\n\n- Generate JSON test reports that are [CTRF](https://ctrf.io) compliant\n- Straightforward integration with Mocha\n\n```json\n{\n  \"results\": {\n    \"tool\": {\n      \"name\": \"mocha\"\n    },\n    \"summary\": {\n      \"tests\": 1,\n      \"passed\": 1,\n      \"failed\": 0,\n      \"pending\": 0,\n      \"skipped\": 0,\n      \"other\": 0,\n      \"start\": 1706828654274,\n      \"stop\": 1706828655782\n    },\n    \"tests\": [\n      {\n        \"name\": \"ctrf should generate the same report with any tool\",\n        \"status\": \"passed\",\n        \"duration\": 100\n      }\n    ],\n    \"environment\": {\n      \"appName\": \"MyApp\",\n      \"buildName\": \"MyBuild\",\n      \"buildNumber\": \"1\"\n    }\n  }\n}\n```\n\n## Installation\n\n```bash\nnpm install --save-dev mocha-ctrf-json-reporter\n```\n\nYou can configure Mocha to use mocha-ctrf-json-reporter in several ways: through .mocharc.js, .mocharc.json, or via the command line. Below are the instructions for each method:\n\nUpdate your .mocharc.js file as follows:\n\n```javascript\nmodule.exports = {\n  reporter: 'mocha-ctrf-json-reporter',\n}\n```\n\nUsing .mocharc.json, update your config file as follows:\n\n```json\n{\n  \"reporter\": \"mocha-ctrf-json-reporter\"\n}\n```\n\nRun your tests as you normally would:\n\n```bash\nnpx mocha\n```\n\nYou'll find a JSON file named `ctrf-report.json` in the `ctrf` directory.\n\nYou can also specify the reporter from the command line:\n\n```bash\nmocha --reporter mocha-ctrf-json-reporter\n```\n\n## Reporter Options\n\nThe reporter supports several configuration options, update your .mocharc.js\n\n```javascript\n{\n  reporter: \"mocha-ctrf-json-reporter\",\n  reporterOptions: {\n    outputFile: 'custom-name.json', // Optional: Output file name. Defaults to 'ctrf-report.json'.\n    outputDir: 'custom-directory',  // Optional: Output directory path. Defaults to 'ctrf'.\n    appName: 'MyApp',               // Optional: Specify the name of the application under test.\n    appVersion: '1.0.0',            // Optional: Specify the version of the application under test.\n    osPlatform: 'linux',            // Optional: Specify the OS platform.\n    osRelease: '18.04',             // Optional: Specify the OS release version.\n    osVersion: '5.4.0',             // Optional: Specify the OS version.\n    buildName: 'MyApp Build',       // Optional: Specify the build name.\n    buildNumber: '100',             // Optional: Specify the build number.\n    buildName: 'MyApp Build',       // Optional: Specify the build name.\n    buildUrl: \"https://ctrf.io\",    // Optional: Specify the build url.\n    repositoryName: \"ctrf-json\",    // Optional: Specify the repository name.\n    repositoryUrl: \"https://gh.io\", // Optional: Specify the repository url.\n    branchName: \"main\",             // Optional: Specify the branch name.\n    testEnvironment: \"staging\"      // Optional: Specify the test environment (e.g. staging, production).\n  }\n},\n\n```\n\nFor .mocharc.json\n\n```json\n{\n  \"reporter\": \"mocha-ctrf-json-reporter\",\n  \"reporterOptions\": {\n    \"outputFile\": \"custom-name.json\"\n  }\n}\n```\n\nAlternatively, you can pass the reporter options via the command line when running your Mocha tests. Use the --reporter-options flag followed by the options in a key=value format, separated by commas:\n\n```bash\nnpx mocha --reporter mocha-ctrf-json-reporter --reporter-options \"outputFile=custom-name.json,outputDir=custom-directory,appName=MyApp,appVersion=1.0.0\"\n```\n\n### Results Report\n\nResults JSON filename can contain `[hash]`, e.g. `./path_to_your/test-results.[hash].json`. `[hash]` is replaced by MD5 hash of test results JSON. This enables support of parallel execution of multiple `mocha-ctrf-json-reporter`'s writing test results in separate files.\n\n## Extra\n\nThe `extra` field lets you attach custom metadata to individual test results at runtime.\nSee the [CTRF extra specification](https://www.ctrf.io/docs/specification/extra) for full details.\n\n### Usage\n\nImport `ctrf` from the reporter and call `ctrf.extra()` inside any test:\n\n```javascript\nconst { ctrf } = require('mocha-ctrf-json-reporter')\n\ndescribe('Checkout', () =\u003e {\n  it('checkout flow', () =\u003e {\n    ctrf.extra({ owner: 'checkout-team', priority: 'P1' })\n\n    // ... test logic ...\n  })\n})\n```\n\nYou can call it multiple times in a single test:\n\n```javascript\ndescribe('Search', () =\u003e {\n  it('search results', () =\u003e {\n    ctrf.extra({ owner: 'search-team' })\n    ctrf.extra({ feature: 'search', environment: 'staging' })\n\n    // ... test logic ...\n\n    ctrf.extra({ customMetric: 'some-value' })\n  })\n})\n```\n\nThe resulting `extra` field in the CTRF report:\n\n```json\n{\n  \"name\": \"search results\",\n  \"status\": \"passed\",\n  \"duration\": 300,\n  \"extra\": {\n    \"owner\": \"search-team\",\n    \"feature\": \"search\",\n    \"environment\": \"staging\",\n    \"customMetric\": \"some-value\"\n  }\n}\n```\n\n### Merge behaviour\n\n| Data type  | Behaviour                           | Example                                                                                                        |\n| ---------- | ----------------------------------- | -------------------------------------------------------------------------------------------------------------- |\n| Primitives | Later call overwrites earlier       | `extra({ owner: 'a' })` then `extra({ owner: 'b' })` → `{ owner: 'b' }`                                        |\n| Objects    | Deep merged - nested keys preserved | `extra({ build: { id: '1' } })` then `extra({ build: { url: '...' } })` → `{ build: { id: '1', url: '...' } }` |\n| Arrays     | Concatenated across calls           | `extra({ tags: ['smoke'] })` then `extra({ tags: ['e2e'] })` → `{ tags: ['smoke', 'e2e'] }`                    |\n\n## Test Object Properties\n\nThe test object in the report includes the following [CTRF properties](https://ctrf.io/docs/schema/test):\n\n| Name        | Type    | Required | Details                                                                             |\n| ----------- | ------- | -------- | ----------------------------------------------------------------------------------- |\n| `name`      | String  | Required | The name of the test.                                                               |\n| `status`    | String  | Required | The outcome of the test. One of: `passed`, `failed`, `skipped`, `pending`, `other`. |\n| `duration`  | Number  | Required | The time taken for the test execution, in milliseconds.                             |\n| `message`   | String  | Optional | The failure message if the test failed.                                             |\n| `trace`     | String  | Optional | The stack trace captured if the test failed.                                        |\n| `start`     | Number  | Optional | The start time of the test as a Unix epoch timestamp.                               |\n| `stop`      | Number  | Optional | The end time of the test as a Unix epoch timestamp.                                 |\n| `rawStatus` | String  | Optional | The original playwright status of the test before mapping to CTRF status.           |\n| `filePath`  | String  | Optional | The file path where the test is located in the project.                             |\n| `retries`   | Number  | Optional | The number of retries attempted for the test.                                       |\n| `flaky`     | Boolean | Optional | Indicates whether the test result is flaky.                                         |\n\n## What is CTRF?\n\nCTRF is a universal JSON test report schema that addresses the lack of a standardized format for JSON test reports.\n\n**Consistency Across Tools:** Different testing tools and frameworks often produce reports in varied formats. CTRF ensures a uniform structure, making it easier to understand and compare reports, regardless of the testing tool used.\n\n**Language and Framework Agnostic:** It provides a universal reporting schema that works seamlessly with any programming language and testing framework.\n\n**Facilitates Better Analysis:** With a standardized format, programatically analyzing test outcomes across multiple platforms becomes more straightforward.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fctrf-io%2Fmocha-ctrf-json-reporter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fctrf-io%2Fmocha-ctrf-json-reporter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fctrf-io%2Fmocha-ctrf-json-reporter/lists"}