junit-report-merger
v9.0.4
Published
Merges multiple JUnit XML reports into one.
Maintainers
Readme
junit-report-merger
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.
CLI
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.
Installing
Globally
npm install -g junit-report-mergerIn this case you'll be able to execute jrm binary from within your shell.
Locally
npm install junit-report-merger --save-devIn this case jrm binary will be available only inside package.json scripts:
scripts: {
"merge-reports": "jrm combined.xml \"results/*.xml\""
}Usage
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.
API
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.
Usage
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
) => voidReads 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;
sumTime: boolean;
}onFileMatched
mergeFiles calls function specified by the onFileMatched option once for each file matched by srcFilePaths, right before file processing begins.
sumTime
When true, the time attribute of the top-level testsuites element will be aggregated using sum instead of max.
This sums the run times from all testsuites and represents the time it took to perform all tests, without accounting for parallelization. The actual time it took to perform all tests may be shorter when testsuites ran in parallel.
When false (default), the time attribute of the top-level testsuites element contains the longest time a test testsuite took to run which is probably closer to the real execution time in case all testsuites ran in parallel.
mergeStreams
Signature:
mergeStreams(
destStream: WritableStream,
srcStreams: ReadableStream[],
options?: MergeStreamsOptions
) => Promise<void>;
mergeStreams(
destStream: WritableStream,
srcStreams: ReadableStream[],
options: MergeStreamsOptions,
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] | MergeStreamsOptions | 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
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)MergeStreamsOptions
These are the options accepted by mergeStreams.
Signature:
type MergeStreamsOptions = {
sumTime: boolean
}sumTime
When true, the time attribute of the top-level testsuites element will be aggregated using sum instead of max.
This sums the run times from all testsuites and represents the time it took to perform all tests, without accounting for parallelization. The actual time it took to perform all tests may be shorter when testsuites ran in parallel.
When false (default), the time attribute of the top-level testsuites element contains the longest time a test testsuite took to run which is probably closer to the real execution time in case all testsuites ran in parallel.
mergeToString
Signature:
mergeToString(
srcStrings: string[],
options?: MergeToStringOptions
) => stringMerges given XML strings and returns the result.
| Param | Type | Description | | ---------- | ---------------------------------------------------------- | ----------------------------------- | | srcStrings | string[] | Array of strings to merge together. | | [options] | MergeToStringOptions | Merge options. |
MergeToStringOptions
These are the options accepted by mergeToString.
Signature:
type MergeToStringOptions = {
sumTime: boolean
}sumTime
When true, the time attribute of the top-level testsuites element will be aggregated using sum instead of max.
This sums the run times from all testsuites and represents the time it took to perform all tests, without accounting for parallelization. The actual time it took to perform all tests may be shorter when testsuites ran in parallel.
When false (default), the time attribute of the top-level testsuites element contains the longest time a test testsuite took to run which is probably closer to the real execution time in case all testsuites ran in parallel.
JUnit XML Format
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.
License
MIT (http://www.opensource.org/licenses/mit-license.php)
