Registry / testing / node-test-junit-reporter

node-test-junit-reporter

JSON →
library2.0.1jsnpmunverified

node-test-junit-reporter is a utility package designed to integrate with Node.js's built-in test runner, generating JUnit XML formatted test reports. It functions as a command-line test reporter, allowing developers to output test results in a standardized, machine-readable format compatible with Continuous Integration (CI) systems like Jenkins, GitLab CI, or GitHub Actions. The current stable version is 2.0.1. Releases occur frequently, primarily driven by dependency updates and minor bug fixes, with major versions introducing Node.js compatibility changes. Its primary differentiation lies in its direct integration with the native `node --test` command, providing a straightforward solution for projects utilizing Node.js's own testing capabilities without external test frameworks.

npm install node-test-junit-reporter
INSTALL
IMPORT
SIG · NODE-TEST-JUNIT-RE
N
node-test-junit-reporter
testingjavascriptv2.0.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Demonstrates how to configure and run Node.js native tests with `node-test-junit-reporter` to generate a `report.xml` file, including setup in `package.json` and a sample test file structure.

// 1. Install the package as a development dependency: // npm i -D node-test-junit-reporter // 2. Create a test file, for instance, 'tests/example.test.js': // import { test } from 'node:test'; // import assert from 'node:assert'; // // test('passing test example', () => { // assert.strictEqual(1, 1, 'Numbers should be identical'); // }); // // test('failing test example', () => { // assert.notStrictEqual(1, 1, 'This assertion is intentionally designed to fail'); // }); // // test('asynchronous test example', async () => { // await new Promise(resolve => setTimeout(resolve, 50)); // assert.ok(true, 'Asynchronous operation successfully completed'); // }); // 3. Add a script to your package.json to run the tests with the reporter: // { // "name": "my-node-project", // "version": "1.0.0", // "scripts": { // "test:junit": "node --test --test-reporter node-test-junit-reporter --test-reporter-destination report.xml tests/example.test.js" // }, // "devDependencies": { // "node-test-junit-reporter": "^2.0.1" // } // } // 4. Execute the test script from your terminal: // npm run test:junit // This command will run your Node.js native tests and generate a 'report.xml' // file in your project's root directory, containing the JUnit XML formatted results. // The report will detail test successes, failures, and execution times, // suitable for consumption by CI/CD tools.
node-test-junit-reporter --version
Debug
Known issues
breakingVersion 2.0.0 introduced a breaking change requiring Node.js version 22 or higher. Earlier Node.js versions are no longer supported.
fix
Upgrade your Node.js environment to version 22 or newer, or pin `node-test-junit-reporter` to a compatible earlier version (e.g., `^1.0.0`) if a Node.js upgrade is not feasible.
affects: >=2.0.0
gotchaWhen using multiple `--test-reporter` flags (e.g., one for `stdout` and one for JUnit XML), ensure each reporter is immediately followed by its `--test-reporter-destination`. Incorrect ordering or omission of a destination can lead to unexpected output behavior or reports overwriting each other.
fix
Always pair `--test-reporter <reporter-name>` with `--test-reporter-destination <output-path>` directly. For example: `node --test --test-reporter tap --test-reporter-destination stdout --test-reporter node-test-junit-reporter --test-reporter-destination report.xml`
affects: >=1.0.0
gotchaAs of v2.0.1, the `times` attribute in the generated JUnit XML report is correctly expressed in seconds. Previous versions might have reported incorrect units or values, potentially affecting CI systems that parse these metrics. Users consuming these time values should re-validate their parsing logic after updating.
fix
Review any CI/CD pipelines or scripts that parse the `time` attribute from the generated JUnit XML reports to ensure they correctly interpret the value as seconds after upgrading to v2.0.1 or later.
affects: >=2.0.1
Errors
Common errors & fixes
Error: The test reporter 'node-test-junit-reporter' could not be found.
The package is not installed as a development dependency or Node.js cannot resolve its path from the current working directory.
fix
Ensure `node-test-junit-reporter` is installed in your project's `node_modules` directory (`npm install -D node-test-junit-reporter`) and that the `node` command is run from the project root or a location where local `node_modules` can be resolved.
TypeError: node-test-junit-reporter requires Node.js v22 or higher. Current: vX.Y.Z
Attempting to use `node-test-junit-reporter` v2.0.0 or later with a Node.js runtime version older than v22.
fix
Upgrade your Node.js environment to version 22 or newer, or modify your `package.json` to use a compatible earlier version of `node-test-junit-reporter` (e.g., `"node-test-junit-reporter": "^1.0.0"`).
Upgrade
Version history
2.0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
node-test-junit-reporter — npm install node-test-junit-reporter · libregistry