Jest JSON Reporter
jest-json-reporter is a utility package for Jest that processes test results and outputs them to a specified JSON file. It adheres to the JSON format defined by Jest's own documentation, making it suitable for integration into Continuous Integration (CI) pipelines, custom reporting dashboards, or any system that consumes structured test results. The package is currently at version 1.2.2 and generally operates as a 'set-and-forget' utility, meaning its release cadence is typically slow, focused on stability and compatibility with new Jest versions rather than frequent feature additions. Its key differentiator is its straightforward, minimal configuration for generating a standard JSON report, which is often preferred over more complex or opinionated reporting solutions when raw data is needed for further processing.
Common errors
-
Cannot find module './node_modules/jest-json-reporter' from 'package.json'
cause Jest could not resolve the specified path for the test results processor, likely due to a typo, incorrect path, or the package not being installed.fixVerify that `jest-json-reporter` is installed (check `node_modules` and `package.json`). Ensure the path in `testResultsProcessor` is exactly `./node_modules/jest-json-reporter`. -
Jest: No tests found, exiting with error code 1
cause This error itself isn't directly from `jest-json-reporter`, but if Jest isn't configured correctly to find tests, the reporter won't have any results to process, leading to confusion about its operation.fixEnsure your Jest configuration (`testMatch`, `testRegex`) correctly identifies your test files. The `jest-json-reporter` will only output results if Jest actually runs tests.
Warnings
- breaking Major Jest version updates (e.g., Jest v27, v28, v29+) can sometimes introduce changes to the reporter API or how modules are resolved (e.g., ESM vs. CJS). While generally stable, ensure compatibility by testing against new Jest versions before upgrading in production.
- gotcha The `testResultsProcessor` path in `package.json` or `jest.config.js` must be correct and resolvable from the project root. Incorrect relative paths or typos will lead to Jest failing to load the reporter.
- gotcha The `outputFile` configuration determines where the JSON results are written. If not configured, it defaults to `test-results.json` in the project root. Using a non-unique or shared `outputFile` path across different test runs or CI stages can lead to files being overwritten.
Install
-
npm install jest-json-reporter -
yarn add jest-json-reporter -
pnpm add jest-json-reporter
Imports
- JestJSONReporterPath
import reporter from 'jest-json-reporter';
"testResultsProcessor": "./node_modules/jest-json-reporter"
Quickstart
npm install --save-dev jest jest-json-reporter
// package.json
// Add the following configuration to your package.json:
// {
// "name": "my-project",
// "version": "1.0.0",
// "devDependencies": {
// "jest": "^29.0.0",
// "jest-json-reporter": "^1.0.0"
// },
// "jest": {
// "testResultsProcessor": "./node_modules/jest-json-reporter",
// "testEnvironment": "node"
// },
// "jestJsonReporter": {
// "outputFile": "jest-test-results.json"
// }
// }
// __tests__/example.test.ts
// Create a simple test file, e.g., '__tests__/example.test.ts':
describe('Basic math operations', () => {
test('adds 1 + 2 to equal 3', () => {
expect(1 + 2).toBe(3);
});
test('multiplies 2 * 3 to equal 6', () => {
expect(2 * 3).toBe(6);
});
});
// Run Jest from your terminal
npx jest
// Verify the JSON output file
// cat jest-test-results.json