Gathering detailed insights and metrics for jest-junit
Gathering detailed insights and metrics for jest-junit
Gathering detailed insights and metrics for jest-junit
Gathering detailed insights and metrics for jest-junit
A Jest reporter that creates compatible junit xml files
npm install jest-junit
Typescript
Module System
Min. Node Version
Node Version
NPM Version
98.3
Supply Chain
99.5
Quality
78.2
Maintenance
100
Vulnerability
100
License
JavaScript (100%)
Total Downloads
890,904,462
Last Day
193,729
Last Week
5,665,602
Last Month
25,156,910
Last Year
263,523,111
Apache-2.0 License
495 Stars
311 Commits
115 Forks
5 Watchers
11 Branches
51 Contributors
Updated on May 28, 2025
Minified
Minified + Gzipped
Latest Version
16.0.0
Package Id
jest-junit@16.0.0
Unpacked Size
40.88 kB
Size
12.34 kB
File Count
10
NPM Version
8.5.5
Node Version
16.15.0
Published on
Apr 15, 2023
Cumulative downloads
Total Downloads
Last Day
-0%
193,729
Compared to previous day
Last Week
-9%
5,665,602
Compared to previous week
Last Month
1%
25,156,910
Compared to previous month
Last Year
14%
263,523,111
Compared to previous year
A Jest reporter that creates compatible junit xml files
Note: as of jest-junit 11.0.0 NodeJS >= 10.12.0 is required.
1yarn add --dev jest-junit
In your jest config add the following entry:
1{ 2 "reporters": [ "default", "jest-junit" ] 3}
Then simply run:
1jest
For your Continuous Integration you can simply do:
1jest --ci --reporters=default --reporters=jest-junit
The support for testResultsProcessor
is only kept for legacy reasons and might be removed in the future.
You should therefore prefer to configure jest-junit
as a reporter.
Should you still want to, add the following entry to your jest config:
1{ 2 "testResultsProcessor": "jest-junit" 3}
Then simply run:
1jest
For your Continuous Integration you can simply do:
1jest --ci --testResultsProcessor="jest-junit"
jest-junit
offers several configurations based on environment variables or a jest-junit
key defined in package.json
or a reporter option.
Environment variable and package.json configuration should be strings.
Reporter options should also be strings exception for suiteNameTemplate, classNameTemplate, titleNameTemplate that can also accept a function returning a string.
Environment Variable Name | Reporter Config Name | Description | Default | Possible Injection Values |
---|---|---|---|---|
JEST_SUITE_NAME | suiteName | name attribute of <testsuites> | "jest tests" | N/A |
JEST_JUNIT_OUTPUT_DIR | outputDirectory | Directory to save the output. Relative path outside of project root (e.g. in monorepos) has to be prefixed with <rootDir> literal, e.g. <rootDir>/../coverage | process.cwd() | N/A |
JEST_JUNIT_OUTPUT_NAME | outputName | File name for the output. | "junit.xml" | N/A |
JEST_JUNIT_OUTPUT_FILE | outputFile | Fullpath for the output. If defined, outputDirectory and outputName will be overridden | undefined | N/A |
JEST_JUNIT_UNIQUE_OUTPUT_NAME | uniqueOutputName | Create unique file name for the output leveraging the outputName as a prefix if given ${outputName}-${uuid}.xml or a default of junit-${uuid}.xml if outputName is not specified, overrides outputName | false | N/A |
JEST_JUNIT_SUITE_NAME | suiteNameTemplate | Template string for name attribute of the <testsuite> . | "{title}" | {title} , {filepath} , {filename} , {displayName} |
JEST_JUNIT_CLASSNAME | classNameTemplate | Template string for the classname attribute of <testcase> . | "{classname} {title}" | {classname} , {title} , {suitename} , {filepath} , {filename} , {displayName} |
JEST_JUNIT_TITLE | titleTemplate | Template string for the name attribute of <testcase> . | "{classname} {title}" | {classname} , {title} , {filepath} , {filename} , {displayName} |
JEST_JUNIT_ANCESTOR_SEPARATOR | ancestorSeparator | Character(s) used to join the describe blocks. | " " | N/A |
JEST_JUNIT_ADD_FILE_ATTRIBUTE | addFileAttribute | Add file attribute to the output (validated on CIRCLE CI and GitLab CI). Must be a string. | "false" | N/A |
JEST_JUNIT_FILE_PATH_PREFIX | filePathPrefix | Prefix to add to the test suite file path. The value will be prefixed using path.join . Useful in case of monorepo | "" | N/A |
JEST_JUNIT_INCLUDE_CONSOLE_OUTPUT | includeConsoleOutput | Adds console output to any testSuite that generates stdout during a test run. | false | N/A |
JEST_JUNIT_INCLUDE_SHORT_CONSOLE_OUTPUT | includeShortConsoleOutput | Adds short console output (only message value) to any testSuite that generates stdout during a test run. | false | N/A |
JEST_JUNIT_REPORT_TEST_SUITE_ERRORS | reportTestSuiteErrors | Reports test suites that failed to execute altogether as error . Note: since the suite name cannot be determined from files that fail to load, it will default to file path. | false | N/A |
JEST_JUNIT_NO_STACK_TRACE | noStackTrace | Omit stack traces from test failure reports, similar to jest --noStackTrace | false | N/A |
JEST_USE_PATH_FOR_SUITE_NAME | usePathForSuiteName | DEPRECATED. Use suiteNameTemplate instead. Use file path as the name attribute of <testsuite> | "false" | N/A |
JEST_JUNIT_TEST_CASE_PROPERTIES_JSON_FILE | testCasePropertiesFile | Name of the custom testcase properties file | "junitProperties.js" | N/A |
JEST_JUNIT_TEST_CASE_PROPERTIES_DIR | testCasePropertiesDirectory | Location of the custom testcase properties file | process.cwd() | N/A |
JEST_JUNIT_TEST_SUITE_PROPERTIES_JSON_FILE | testSuitePropertiesFile | Name of the custom testsuite properties file | "junitTestCaseProperties.js" | N/A |
JEST_JUNIT_TEST_SUITE_PROPERTIES_DIR | testSuitePropertiesDirectory | Location of the custom testsuite properties file | process.cwd() | N/A |
You can configure these options via the command line as seen below:
1JEST_SUITE_NAME="Jest JUnit Unit Tests" JEST_JUNIT_OUTPUT_DIR="./artifacts" jest
Or you can also define a jest-junit
key in your package.json
. All are string values.
{
...
"jest-junit": {
"suiteName": "jest tests",
"outputDirectory": ".",
"outputName": "junit.xml",
"uniqueOutputName": "false",
"classNameTemplate": "{classname}-{title}",
"titleTemplate": "{classname}-{title}",
"ancestorSeparator": " › ",
"usePathForSuiteName": "true"
}
}
Or you can define your options in your reporter configuration.
1// jest.config.js 2{ 3 reporters: [ 4 "default", 5 [ "jest-junit", { suiteName: "jest tests" } ] 6 ] 7}
If using the usePathForSuiteName
and suiteNameTemplate
, the usePathForSuiteName
value will take precedence. ie: if usePathForSuiteName=true
and suiteNameTemplate="{filename}"
, the filepath will be used as the name
attribute of the <testsuite>
in the rendered jest-junit.xml
).
Below are some example configuration values and the rendered .xml
to created by jest-junit
.
The following test defined in the file /__tests__/addition.test.js
will be used for all examples:
1describe('addition', () => { 2 describe('positive numbers', () => { 3 it('should add up', () => { 4 expect(1 + 2).toBe(3); 5 }); 6 }); 7});
The default output:
1<testsuites name="jest tests"> 2 <testsuite name="addition" tests="1" errors="0" failures="0" skipped="0" timestamp="2017-07-13T09:42:28" time="0.161"> 3 <testcase classname="addition positive numbers should add up" name="addition positive numbers should add up" time="0.004"> 4 </testcase> 5 </testsuite> 6</testsuites>
Using the classNameTemplate
and titleTemplate
:
1JEST_JUNIT_CLASSNAME="{classname}" JEST_JUNIT_TITLE="{title}" jest
renders
1<testsuites name="jest tests"> 2 <testsuite name="addition" tests="1" errors="0" failures="0" skipped="0" timestamp="2017-07-13T09:45:42" time="0.154"> 3 <testcase classname="addition positive numbers" name="should add up" time="0.005"> 4 </testcase> 5 </testsuite> 6</testsuites>
Using the ancestorSeparator
:
1JEST_JUNIT_ANCESTOR_SEPARATOR=" › " jest
renders
1<testsuites name="jest tests"> 2 <testsuite name="addition" tests="1" errors="0" failures="0" skipped="0" timestamp="2017-07-13T09:47:12" time="0.162"> 3 <testcase classname="addition › positive numbers should add up" name="addition › positive numbers should add up" time="0.004"> 4 </testcase> 5 </testsuite> 6</testsuites>
Using the suiteNameTemplate
:
1JEST_JUNIT_SUITE_NAME ="{filename}" jest
1<testsuites name="jest tests"> 2 <testsuite name="addition.test.js" tests="1" errors="0" failures="0" skipped="0" timestamp="2017-07-13T09:42:28" time="0.161"> 3 <testcase classname="addition positive numbers should add up" name="addition positive numbers should add up" time="0.004"> 4 </testcase> 5 </testsuite> 6</testsuites>
Using classNameTemplate
as a function in reporter options
1// jest.config.js 2{ 3 reporters: [ 4 "default", 5 [ 6 "jest-junit", 7 { 8 classNameTemplate: (vars) => { 9 return vars.classname.toUpperCase(); 10 } 11 } 12 ] 13 ] 14}
renders
1<testsuites name="jest tests"> 2 <testsuite name="addition" tests="1" errors="0" failures="0" skipped="0" timestamp="2017-07-13T09:42:28" time="0.161"> 3 <testcase classname="ADDITION POSITIVE NUMBERS" name="addition positive numbers should add up" time="0.004"> 4 </testcase> 5 </testsuite> 6</testsuites>
New feature as of jest-junit 11.0.0!
Create a file in your project root directory named junitProperties.js:
1module.exports = () => { 2 return { 3 key: "value", 4 }; 5};
Will render
1<testsuites name="jest tests"> 2 <testsuite name="addition" tests="1" errors="0" failures="0" skipped="0" timestamp="2017-07-13T09:42:28" time="0.161"> 3 <properties> 4 <property name="key" value="value" /> 5 </properties> 6 <testcase classname="addition positive numbers should add up" name="addition positive numbers should add up" time="0.004"> 7 </testcase> 8 </testsuite> 9</testsuites>
Create a file in your project root directory named junitTestCaseProperties.js:
1module.exports = (testResult) => { 2 return { 3 "dd_tags[test.invocations]": testResult.invocations, 4 }; 5};
Will render
1<testsuites name="jest tests"> 2 <testsuite name="addition" tests="1" errors="0" failures="0" skipped="0" timestamp="2017-07-13T09:42:28" time="0.161"> 3 <testcase classname="addition positive numbers should add up" name="addition positive numbers should add up" time="0.004"> 4 <properties> 5 <property name="dd_tags[test.invocations]" value="1" /> 6 </properties> 7 </testcase> 8 </testsuite> 9</testsuites>
WARNING: Properties for testcases is not following standard JUnit XML schema.
However, other consumers may support properties for testcases like DataDog metadata through <property>
elements
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
Found 8/12 approved changesets -- score normalized to 6
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
14 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-06-23
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More