{"id":15363,"library":"node-test-junit-reporter","title":"Node.js Test Runner JUnit Reporter","description":"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.","status":"active","version":"2.0.1","language":"javascript","source_language":"en","source_url":"https://github.com/nearform/node-test-junit-reporter","tags":["javascript","test","junit","reporter"],"install":[{"cmd":"npm install node-test-junit-reporter","lang":"bash","label":"npm"},{"cmd":"yarn add node-test-junit-reporter","lang":"bash","label":"yarn"},{"cmd":"pnpm add node-test-junit-reporter","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[],"quickstart":{"code":"// 1. Install the package as a development dependency:\n// npm i -D node-test-junit-reporter\n\n// 2. Create a test file, for instance, 'tests/example.test.js':\n// import { test } from 'node:test';\n// import assert from 'node:assert';\n//\n// test('passing test example', () => {\n//   assert.strictEqual(1, 1, 'Numbers should be identical');\n// });\n//\n// test('failing test example', () => {\n//   assert.notStrictEqual(1, 1, 'This assertion is intentionally designed to fail');\n// });\n//\n// test('asynchronous test example', async () => {\n//   await new Promise(resolve => setTimeout(resolve, 50));\n//   assert.ok(true, 'Asynchronous operation successfully completed');\n// });\n\n// 3. Add a script to your package.json to run the tests with the reporter:\n// {\n//   \"name\": \"my-node-project\",\n//   \"version\": \"1.0.0\",\n//   \"scripts\": {\n//     \"test:junit\": \"node --test --test-reporter node-test-junit-reporter --test-reporter-destination report.xml tests/example.test.js\"\n//   },\n//   \"devDependencies\": {\n//     \"node-test-junit-reporter\": \"^2.0.1\"\n//   }\n// }\n\n// 4. Execute the test script from your terminal:\n// npm run test:junit\n\n// This command will run your Node.js native tests and generate a 'report.xml'\n// file in your project's root directory, containing the JUnit XML formatted results.\n// The report will detail test successes, failures, and execution times,\n// suitable for consumption by CI/CD tools.","lang":"javascript","description":"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."},"warnings":[{"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.","message":"Version 2.0.0 introduced a breaking change requiring Node.js version 22 or higher. Earlier Node.js versions are no longer supported.","severity":"breaking","affected_versions":">=2.0.0"},{"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`","message":"When 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.","severity":"gotcha","affected_versions":">=1.0.0"},{"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.","message":"As 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.","severity":"gotcha","affected_versions":">=2.0.1"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"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.","cause":"The package is not installed as a development dependency or Node.js cannot resolve its path from the current working directory.","error":"Error: The test reporter 'node-test-junit-reporter' could not be found."},{"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\"`).","cause":"Attempting to use `node-test-junit-reporter` v2.0.0 or later with a Node.js runtime version older than v22.","error":"TypeError: node-test-junit-reporter requires Node.js v22 or higher. Current: vX.Y.Z"}],"ecosystem":"npm"}