Registry / testing / junit-report-builder

junit-report-builder

JSON →
library5.1.2jsnpmunverified

junit-report-builder is a Node.js library designed to simplify the creation of JUnit XML reports compatible with Jenkins and other CI systems. Currently stable at version 5.1.2, it maintains a moderate release cadence, addressing dependency updates, minor features, and critical compatibility fixes. Its primary function is to programmatically construct complex XML reports, providing a fluent API for defining test suites, test cases, and their outcomes (success, failure, skipped, error). A key differentiator is its focus on direct XML generation from a programmatic interface, rather than processing existing test output, making it ideal for integration into custom testing frameworks or report generation tools. It ships with TypeScript type definitions, ensuring robust development workflows.

npm install junit-report-builder
INSTALL
IMPORT
SIG · JUNIT-REPORT-BUILD
J
junit-report-builder
testingjavascriptv5.1.2
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

builder
import builder from 'junit-report-builder';
import { builder } from 'junit-report-builder';
The primary builder instance is exported as a default. Since v5.0.0, both ESM and CommonJS are supported, but older versions had issues with CommonJS.
builder (CommonJS)
const builder = require('junit-report-builder');
CommonJS `require` pattern for Node.js environments. This was problematic in v4.0.0 and v4.0.1, fixed in v5.0.0.
TestSuite
import type { TestSuite } from 'junit-report-builder';
Type import for the TestSuite interface for TypeScript usage. Other types like `TestCase` are also available.

This example demonstrates creating a test suite, adding successful, failed, skipped, and error test cases, and writing the complete report to an XML file using async/await.

import builder from 'junit-report-builder'; import path from 'path'; async function generateReport() { // Create a test suite let suite = builder.testSuite().name('My example suite'); // Create a test case let firstTestCase = suite.testCase() .className('my.test.Class') .name('My first successful test'); firstTestCase.time(0.123); // Create another test case which is marked as failed let secondTestCase = suite.testCase() .className('my.test.Class') .name('My second failing test') .failure('Assertion failed', 'Expected true to be false'); secondTestCase.time(0.045); // Create a skipped test case let skippedTestCase = suite.testCase() .name('My third skipped test') .skipped(); // Create a test case with an error let errorTestCase = suite.testCase() .name('My fourth test with error') .error('Runtime error', 'Unhandled exception occurred.'); const reportFilePath = path.join(process.cwd(), 'test-report-example.xml'); await builder.writeTo(reportFilePath); console.log(`JUnit report written to: ${reportFilePath}`); } generateReport();
Debug
Known issues
breakingVersion 4.0.0 dropped support for Node.js 14, 12, 10, and 8. The package now requires Node.js >=16. Ensure your environment meets this requirement before upgrading.
fix
Upgrade your Node.js runtime to version 16 or newer. Use a tool like `nvm` to manage multiple Node.js versions if necessary.
affects: >=4.0.0
breakingVersion 4.0.0 inadvertently removed CommonJS support, making the library ESM-only. While version 4.0.1 attempted to reintroduce CJS, it was buggy and deprecated.
fix
For projects requiring CommonJS, upgrade directly to version 5.0.0 or later, which correctly restores CommonJS compatibility. Alternatively, refactor your codebase to use ES modules (`import`).
affects: =4.0.0, =4.0.1
gotchaVersion 5.0.0 was released specifically to fix the broken CommonJS API introduced in 4.0.1. Users experiencing issues with `require()` after upgrading to 4.x should upgrade to 5.0.0+.
fix
Upgrade to `junit-report-builder@^5.0.0` or higher to ensure stable CommonJS support. If you're on 4.0.0, either use ESM or upgrade to 5.0.0+.
affects: >=4.0.1 <5.0.0
gotchaVersion 3.0.0 introduced improved prevention of invalid characters being included in generated XML files. While beneficial, this might change the output slightly if previous versions allowed malformed characters.
fix
Ensure that any input strings to report fields are valid XML characters. No specific fix is usually needed unless you were relying on malformed output.
affects: >=3.0.0
Errors
Common errors & fixes
TypeError: builder.testSuite is not a function
The `builder` object was not correctly imported or is `undefined`.
fix
Ensure you are using the correct import statement: `import builder from 'junit-report-builder';` for ESM or `const builder = require('junit-report-builder');` for CommonJS. Verify that the package is installed.
ReferenceError: require is not defined in ES module scope
Attempting to use CommonJS `require()` syntax within an ES module file (`.mjs` or when `type: "module"` in `package.json`).
fix
Switch to ES module import syntax: `import builder from 'junit-report-builder';`. Alternatively, rename your file to `.cjs` or ensure your `package.json` specifies `"type": "commonjs"`.
Error: Cannot find module 'junit-report-builder'
The package is not installed or the module resolution path is incorrect.
fix
Run `npm install junit-report-builder` to install the package. Verify that your project's `node_modules` directory is correctly configured.
Upgrade
Version history
5.1.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

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