Node.js Test Runner JUnit Reporter

2.0.1 · active · verified Tue Apr 21

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.

Common errors

Warnings

Install

Quickstart

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.

view raw JSON →