Jest JUnit Reporter (Legacy)
This entry describes `jest-junit-reporter` version 1.1.0, a utility for generating JUnit XML test reports from Jest test results. Published 9 years ago, this specific package is effectively abandoned and is no longer maintained. It leverages Jest's `testResultsProcessor` configuration option to intercept test outcomes and format them into a `test-results.xml` file. For any new projects or migrations, the actively maintained and recommended alternative is `jest-junit` (currently at version 16.0.0), which offers more features, better compatibility with modern Jest versions, and uses the `reporters` array configuration (as `testResultsProcessor` is deprecated by Jest itself). This legacy reporter's configuration is limited to environment variables like `TEST_REPORT_PATH` and `TEST_REPORT_FILENAME` for output location and filename. Due to its age, it may have compatibility issues with newer Node.js or Jest versions.
Common errors
-
Error: Could not resolve a module for a custom reporter. Module name: ./node_modules/jest-junit-reporter
cause The `jest-junit-reporter` package is not correctly installed or the path in `testResultsProcessor` is incorrect.fixEnsure `jest-junit-reporter` is listed in your `devDependencies` and run `npm install`. Verify the path in `jest.testResultsProcessor` points to the correct location (e.g., `./node_modules/jest-junit-reporter`). -
No 'test-results.xml' file generated.
cause Jest might not be running the `testResultsProcessor` due to an error, or the output path/filename is being overridden unexpectedly.fixCheck Jest's console output for errors. Ensure tests are actually running. If using `TEST_REPORT_PATH` or `TEST_REPORT_FILENAME` environment variables, verify they are correctly set and accessible to the Jest process. -
DeprecationWarning: The 'testResultsProcessor' option is deprecated and will be removed in a future release.
cause Jest is actively warning about the use of `testResultsProcessor`.fixMigrate to the `reporters` array in your Jest configuration. Consider switching to the `jest-junit` package for modern compatibility and features.
Warnings
- deprecated The `testResultsProcessor` configuration option in Jest, which `jest-junit-reporter` uses, is deprecated and may be removed in future Jest versions.
- breaking The `jest-junit-reporter` package (v1.1.0) is abandoned, with its last publish date 9 years ago. It is no longer maintained and may have compatibility issues with recent Node.js or Jest versions.
- gotcha Configuration for `jest-junit-reporter` (v1.1.0) relies solely on environment variables (`TEST_REPORT_PATH`, `TEST_REPORT_FILENAME`) to customize the output file path and name. This differs significantly from modern Jest reporters.
Install
-
npm install jest-junit-reporter -
yarn add jest-junit-reporter -
pnpm add jest-junit-reporter
Quickstart
{
"name": "my-jest-project",
"version": "1.0.0",
"description": "A simple project demonstrating jest-junit-reporter (legacy).",
"main": "index.js",
"scripts": {
"test": "jest"
},
"devDependencies": {
"jest": "^27.0.0",
"jest-junit-reporter": "^1.1.0"
},
"jest": {
"testResultsProcessor": "./node_modules/jest-junit-reporter"
}
}
// Example test file (sum.test.js)
function sum(a, b) {
return a + b;
}
describe('sum', () => {
test('adds 1 + 2 to equal 3', () => {
expect(sum(1, 2)).toBe(3);
});
test('adds 5 + 10 to equal 15', () => {
expect(sum(5, 10)).toBe(15);
});
test('should handle negative numbers', () => {
expect(sum(-1, -1)).toBe(-2);
});
});
// To run this and generate the report:
// 1. npm install
// 2. npm test
// This will create a 'test-results.xml' file in the project root.