{"id":13411,"library":"junit-report-builder","title":"JUnit Report Builder","description":"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.","status":"active","version":"5.1.2","language":"javascript","source_language":"en","source_url":"git://github.com/davidparsson/junit-report-builder","tags":["javascript","junit","xunit","report","builder","typescript"],"install":[{"cmd":"npm install junit-report-builder","lang":"bash","label":"npm"},{"cmd":"yarn add junit-report-builder","lang":"bash","label":"yarn"},{"cmd":"pnpm add junit-report-builder","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"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.","wrong":"import { builder } from 'junit-report-builder';","symbol":"builder","correct":"import builder from 'junit-report-builder';"},{"note":"CommonJS `require` pattern for Node.js environments. This was problematic in v4.0.0 and v4.0.1, fixed in v5.0.0.","symbol":"builder (CommonJS)","correct":"const builder = require('junit-report-builder');"},{"note":"Type import for the TestSuite interface for TypeScript usage. Other types like `TestCase` are also available.","symbol":"TestSuite","correct":"import type { TestSuite } from 'junit-report-builder';"}],"quickstart":{"code":"import builder from 'junit-report-builder';\nimport path from 'path';\n\nasync function generateReport() {\n  // Create a test suite\n  let suite = builder.testSuite().name('My example suite');\n\n  // Create a test case\n  let firstTestCase = suite.testCase()\n    .className('my.test.Class')\n    .name('My first successful test');\n  firstTestCase.time(0.123);\n\n  // Create another test case which is marked as failed\n  let secondTestCase = suite.testCase()\n    .className('my.test.Class')\n    .name('My second failing test')\n    .failure('Assertion failed', 'Expected true to be false');\n  secondTestCase.time(0.045);\n\n  // Create a skipped test case\n  let skippedTestCase = suite.testCase()\n    .name('My third skipped test')\n    .skipped();\n\n  // Create a test case with an error\n  let errorTestCase = suite.testCase()\n    .name('My fourth test with error')\n    .error('Runtime error', 'Unhandled exception occurred.');\n\n  const reportFilePath = path.join(process.cwd(), 'test-report-example.xml');\n  await builder.writeTo(reportFilePath);\n\n  console.log(`JUnit report written to: ${reportFilePath}`);\n}\n\ngenerateReport();","lang":"typescript","description":"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."},"warnings":[{"fix":"Upgrade your Node.js runtime to version 16 or newer. Use a tool like `nvm` to manage multiple Node.js versions if necessary.","message":"Version 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.","severity":"breaking","affected_versions":">=4.0.0"},{"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`).","message":"Version 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.","severity":"breaking","affected_versions":"=4.0.0, =4.0.1"},{"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+.","message":"Version 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+.","severity":"gotcha","affected_versions":">=4.0.1 <5.0.0"},{"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.","message":"Version 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.","severity":"gotcha","affected_versions":">=3.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"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.","cause":"The `builder` object was not correctly imported or is `undefined`.","error":"TypeError: builder.testSuite is not a function"},{"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\"`.","cause":"Attempting to use CommonJS `require()` syntax within an ES module file (`.mjs` or when `type: \"module\"` in `package.json`).","error":"ReferenceError: require is not defined in ES module scope"},{"fix":"Run `npm install junit-report-builder` to install the package. Verify that your project's `node_modules` directory is correctly configured.","cause":"The package is not installed or the module resolution path is incorrect.","error":"Error: Cannot find module 'junit-report-builder'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"","cli_version":null}