Registry / testing / junit-merge

junit-merge

JSON →
library2.0.0jsnpmunverified

junit-merge is a Node.js command-line interface (CLI) tool designed for consolidating multiple JUnit XML test reports into a single, unified XML file. This is particularly useful in CI/CD environments where parallel test runners generate numerous individual report files that need to be aggregated for a comprehensive overview or integration with other reporting systems. The current stable version is 2.0.0. While the package doesn't specify a formal release cadence, updates are typically driven by Node.js compatibility changes or new feature requirements. Its primary differentiator is its simplicity and focus as a dedicated CLI for this specific task within the Node.js ecosystem, allowing for easy integration into build scripts without requiring complex programmatic setups. It supports features like merging all results in a directory, recursive directory merging, and specifying an output file.

npm install junit-merge
INSTALL
IMPORT
SIG · JUNIT-MERGE
J
junit-merge
testingjavascriptv2.0.0
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.

junitMerge
import junitMerge from 'junit-merge';
const junitMerge = require('junit-merge');
While primarily a CLI tool, this assumes a default export of the main CLI execution function for programmatic use, although direct programmatic API is not explicitly documented. The common usage is via the command line.
mergeFiles
import { mergeFiles } from 'junit-merge';
const { mergeFiles } = require('junit-merge');
This import is speculative, assuming the core file merging logic might be exposed as a named export for programmatic integration. Developers should prioritize CLI usage unless an explicit API is found in the source.
cli
import { cli } from 'junit-merge';
const cli = require('junit-merge').cli;
This assumes a named export for the CLI's entry point function, potentially allowing a script to programmatically invoke the CLI logic by passing arguments. This is not explicitly documented API.

This quickstart demonstrates how to use the `junit-merge` CLI to combine multiple JUnit XML reports from a directory into a single output file using Node.js's `child_process` module. It includes setup for dummy reports and cleanup.

import { execSync } from 'node:child_process'; import { writeFileSync, mkdirSync, rmSync } from 'node:fs'; import { join } from 'node:path'; const tempDir = join(process.cwd(), 'temp_junit_reports'); const outputFile = join(process.cwd(), 'merged-results.xml'); // Clean up previous runs rmSync(tempDir, { recursive: true, force: true }); rmSync(outputFile, { force: true }); mkdirSync(tempDir, { recursive: true }); // Simulate creating dummy JUnit XML files writeFileSync(join(tempDir, 'report1.xml'), `<?xml version="1.0" encoding="UTF-8"?>\n<testsuites name="Suite1" tests="2" failures="0" errors="0" time="1.0">\n <testsuite name="TestA" tests="1" failures="0" errors="0" time="0.5">\n <testcase name="testMethod1" classname="package.ClassA" time="0.2"/>\n </testsuite>\n <testsuite name="TestB" tests="1" failures="0" errors="0" time="0.5">\n <testcase name="testMethod2" classname="package.ClassB" time="0.3"/>\n </testsuite>\n</testsuites>`); writeFileSync(join(tempDir, 'report2.xml'), `<?xml version="1.0" encoding="UTF-8"?>\n<testsuites name="Suite2" tests="1" failures="0" errors="0" time="0.8">\n <testsuite name="TestC" tests="1" failures="0" errors="0" time="0.8">\n <testcase name="testMethod3" classname="package.ClassC" time="0.8"/>\n </testsuite>\n</testsuites>`); console.log('Dummy JUnit reports created in:', tempDir); try { // Run junit-merge CLI command const command = `junit-merge -d ${tempDir} -o ${outputFile}`; console.log(`Executing: ${command}`); const output = execSync(command, { encoding: 'utf8' }); console.log('CLI Output:', output); console.log('Merged report saved to:', outputFile); } catch (error) { console.error('Error merging reports:', error.message); process.exit(1); } // Clean up generated files (optional) // rmSync(tempDir, { recursive: true, force: true }); // rmSync(outputFile, { force: true });
Debug
Known issues
breakingVersion 2.0.0 of `junit-merge` dropped support for Node.js v4. Users on older Node.js environments must upgrade their Node.js version to v6, v8, or v10 (or newer compatible versions) to use `junit-merge` v2.0.0 and beyond.
fix
Upgrade your Node.js runtime to version 6, 8, 10, or a more recent compatible LTS version (e.g., `nvm install 16` or `nvm use 16`).
affects: >=2.0.0
gotchaThe package is primarily a CLI tool; direct programmatic API usage (via `import` or `require`) is not explicitly documented. While internal components might be importable, the intended and most stable interaction is through the command line.
fix
Prefer using `junit-merge` via `child_process.execSync` or `spawn` within Node.js scripts for reliable integration, mirroring its CLI usage, rather than attempting direct module imports.
affects: >=1.0.0
gotchaWhen merging files from a directory (`-d` option), ensure that the specified directory contains valid JUnit XML files. Malformed XML or non-XML files might lead to parsing errors and unexpected behavior in the output.
fix
Validate the integrity and format of source XML files before running `junit-merge`. Consider adding a pre-processing step to check XML validity if file sources are untrusted.
affects: >=1.0.0
Errors
Common errors & fixes
command not found: junit-merge
`junit-merge` was not installed globally or is not in the system's PATH.
fix
Install the package globally using `npm install -g junit-merge` or ensure your PATH includes the directory where npm installs global packages.
Error: ENOENT: no such file or directory, scandir './non-existent-dir'
The directory specified with the `-d` option does not exist.
fix
Ensure the input directory specified by `-d` exists before running the command, or use the `-C` (create directory) option if you expect the output directory to be created, though this option is for the *output* directory, not input.
Error: Unable to parse XML file: 'path/to/malformed.xml'
One of the input XML files is not valid JUnit XML or is corrupted, causing the parser to fail.
fix
Inspect the specified XML file (`path/to/malformed.xml`) for syntax errors, missing tags, or incorrect encoding. Ensure all input files adhere to the JUnit XML schema.
Upgrade
Version history
2.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

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