
Security News
Create React App Officially Deprecated Amid React 19 Compatibility Issues
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
junit-report-merger
Advanced tools
The junit-report-merger npm package is designed to merge multiple JUnit XML reports into a single report. This is particularly useful in continuous integration (CI) environments where tests are run in parallel and generate separate reports.
Merge JUnit XML Reports
This feature allows you to merge multiple JUnit XML reports into a single file. The `mergeFiles` function takes an array of input file paths and an output file path, and merges the input files into the output file.
const { mergeFiles } = require('junit-report-merger');
mergeFiles(['report1.xml', 'report2.xml'], 'merged-report.xml')
.then(() => console.log('Reports merged successfully!'))
.catch(err => console.error('Error merging reports:', err));
The junit-merge package also merges multiple JUnit XML reports into a single report. It is similar to junit-report-merger but offers a command-line interface (CLI) for easier integration into CI pipelines.
The junit-report-builder package allows you to create and merge JUnit XML reports programmatically. It provides more flexibility in terms of report generation and manipulation compared to junit-report-merger.
The xunit-file package is used to generate and merge xUnit XML reports, which are similar to JUnit reports. It is useful for projects that use xUnit format for test reporting and need to merge multiple reports.
Merges multiple JUnit XML reports into one.
Reporters of many testing frameworks generate JUnit XML reports. mocha-junit-reporter
, karma-junit-reporter
to name a few. Sometimes there is a need to combine multiple reports together in a single file. This is what junit-report-merger
does.
junit-report-merger
creates a new test results report in JUnit XML format by collecting all <testsuite>
elements from all XML reports and putting them together.
Package provides a jrm
binary, which you can use to merge multiple xml reports into one.
In a nutshell it is a tiny wrapper around mergeFiles api.
npm install -g junit-report-merger
In this case you'll be able to execute jrm
binary from within your shell.
npm install junit-report-merger --save-dev
In this case jrm
binary will be available only inside package.json
scripts:
scripts: {
"merge-reports": "jrm combined.xml \"results/*.xml\""
}
Assuming your JUnit test results are in ./results/units/
folder, and you want to get a combined test result file in ./results/combined.xml
:
jrm ./results/combined.xml "./results/units/*.xml"
You can also specify multiple glob patterns:
jrm ./results/combined.xml "./results/units/*.xml" "./results/e2e/*.xml"
NOTE
Make sure to wrap each pattern with double quotes ("
), otherwise your shell may try to expand it instead of passing to Node.js.
Package exports a single object with the following methods.
mergeFiles - Merges contents of multiple XML report files into a single XML report file.
mergeStreams - Merges contents of multiple XML report streams into a single XML report stream.
mergeToString - Merges multiple XML report strings into a single XML report string.
const path = require('path')
const { mergeFiles } = require('junit-report-merger')
const outputFile = path.join(__dirname, 'results', 'combined.xml')
const inputFiles = ['./results/units/*.xml', './results/e2e/*.xml']
try {
await mergeFiles(outputFile, inputFiles)
console.log('Merged, check ./results/combined.xml')
} catch (err) {
console.error(error)
}
mergeFiles
Signature:
mergeFiles(
destFilePath: string,
srcFilePathsOrGlobPatterns: string[],
options?: MergeFilesOptions
) => Promise<void>
mergeFiles(
destFilePath: string,
srcFilePathsOrGlobPatterns: string[],
options: MergeFilesOptions,
cb: (err?: Error) => void
) => void
Reads multiple files, merges their contents and write into the given file.
Param | Type | Description |
---|---|---|
destFilePath | string | Where the output should be stored. Denotes a path to file. If file already exists, it will be overwritten. |
srcFilePathsOrGlobPatterns | string[] | Paths to the files which should be merged. You can also specify glob patterns, such as results/**/report-*.xml |
[options] | MergeFilesOptions | Merge options. |
[cb] | (err?: Error) => void | Callback function which will be called at completion. Will receive error as first argument if any. |
Last argument - cb
is a Node.js style callback function. If callback function is not passed, function will return a promise. That is, all the following variants will work:
// options passed, callback style
mergeFiles(destFilePath, srcFilePaths, {}, (err) => {})
// options missing, callback style
mergeFiles(destFilePath, srcFilePaths, (err) => {})
// options passed, promise style
await mergeFiles(destFilePath, srcFilePaths, {})
// options missing, promise style
await mergeFiles(destFilePath, srcFilePaths)
MergeFilesOptions
These are the options accepted by mergeFiles
.
Signature:
type MergeFilesOptions = {
onFileMatched? (matchInfo: {
filePath: string
}) => void
}
onFileMatched
mergeFiles
calls function specified by the onFileMatched
option once for each file matched by srcFilePaths
, right before file processing begins.
Signature:
mergeStreams(
destStream: WritableStream,
srcStreams: ReadableStream[],
options?: {}
) => Promise<void>
mergeStreams(
destStream: WritableStream,
srcStreams: ReadableStream[],
options: {},
cb: (err?: Error) => void
) => void
Reads multiple streams, merges their contents and write into the given stream.
Param | Type | Description |
---|---|---|
destStream | WritableStream | A stream which will be used to write the merge result. |
srcStreams | ReadableStream[] | Streams which will be used to read data from. |
[options] | object | Merge options. Currently unused. |
[cb] | (err?: Error) => void | Callback function which will be called at completion. Will receive error as first argument if any. |
Last argument - cb
is a Node.js style callback function. If callback function is not passed, function will return a promise. That is, all the following variants will work:
// options passed, callback style
mergeStreams(destStream, srcStreams, {}, (err) => {})
// options missing, callback style
mergeStreams(destStream, srcStreams, (err) => {})
// options passed, promise style
await mergeStreams(destStream, srcStreams, {})
// options missing, promise style
await mergeStreams(destStream, srcStreams)
Signature:
mergeToString(
srcStrings: string[],
options?: {}
) => string
Merges given XML strings and returns the result.
Param | Type | Description |
---|---|---|
srcStrings | string[] | Array of strings to merge together. |
[options] | object | Merge options. Currently unused. |
Unfortunately, there is no official specification of JUnit XML file format.
The XML schema for the original JUnit XML format is here.
Over the time, various CI tools and test management software augmented original format with their own properties.
The most comprehensive overview of the format is put together by folks at Testmo here.
jrm
produces output conforming to that format and accepts files conforming to that format.
FAQs
Merges multiple JUnit XML reports into one.
The npm package junit-report-merger receives a total of 426,900 weekly downloads. As such, junit-report-merger popularity was classified as popular.
We found that junit-report-merger demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.