jest-junit
Advanced tools
Comparing version 15.0.0 to 16.0.0
@@ -21,2 +21,4 @@ 'use strict'; | ||
JEST_USE_PATH_FOR_SUITE_NAME: 'usePathForSuiteName', | ||
JEST_JUNIT_TEST_CASE_PROPERTIES_JSON_FILE: 'testCasePropertiesFile', | ||
JEST_JUNIT_TEST_CASE_PROPERTIES_DIR: 'testCasePropertiesDirectory', | ||
JEST_JUNIT_TEST_SUITE_PROPERTIES_JSON_FILE: 'testSuitePropertiesFile', | ||
@@ -41,2 +43,4 @@ JEST_JUNIT_TEST_SUITE_PROPERTIES_DIR: 'testSuitePropertiesDirectory', | ||
noStackTrace: 'false', | ||
testCasePropertiesFile: 'junitTestCaseProperties.js', | ||
testCasePropertiesDirectory: process.cwd(), | ||
testSuitePropertiesFile: 'junitProperties.js', | ||
@@ -43,0 +47,0 @@ testSuitePropertiesDirectory: process.cwd(), |
{ | ||
"name": "jest-junit", | ||
"version": "15.0.0", | ||
"version": "16.0.0", | ||
"description": "A jest reporter that generates junit xml files", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -63,3 +63,3 @@ [![Actions Status](https://github.com/jest-community/jest-junit/actions/workflows/nodejs.yml/badge.svg?branch=master)](https://github.com/jest-community/jest-junit/actions) | ||
| `JEST_SUITE_NAME` | `suiteName` | `name` attribute of `<testsuites>` | `"jest tests"` | N/A | ||
| `JEST_JUNIT_OUTPUT_DIR` | `outputDirectory` | Directory to save the output. | `process.cwd()` | 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 | ||
@@ -79,3 +79,5 @@ | `JEST_JUNIT_OUTPUT_FILE` | `outputFile` | Fullpath for the output. If defined, `outputDirectory` and `outputName` will be overridden | `undefined` | 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_SUITE_PROPERTIES_JSON_FILE` | `testSuitePropertiesFile` | Name of the custom testsuite properties file | `"junitProperties.js"` | 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 | ||
@@ -113,5 +115,5 @@ | ||
{ | ||
reporters: [ | ||
"default", | ||
[ "jest-junit", { suiteName: "jest tests" } ] | ||
reporters: [ | ||
"default", | ||
[ "jest-junit", { suiteName: "jest tests" } ] | ||
] | ||
@@ -241,6 +243,6 @@ } | ||
module.exports = () => { | ||
return { | ||
key: "value" | ||
} | ||
}); | ||
return { | ||
key: "value", | ||
}; | ||
}; | ||
``` | ||
@@ -253,3 +255,3 @@ | ||
<properties> | ||
<property name="key" value="value" /> | ||
<property name="key" value="value" /> | ||
</properties> | ||
@@ -262,2 +264,29 @@ <testcase classname="addition positive numbers should add up" name="addition positive numbers should add up" time="0.004"> | ||
#### Adding custom testcase properties | ||
Create a file in your project root directory named junitTestCaseProperties.js: | ||
```js | ||
module.exports = (testResult) => { | ||
return { | ||
"dd_tags[test.invocations]": testResult.invocations, | ||
}; | ||
}; | ||
``` | ||
Will render | ||
```xml | ||
<testsuites name="jest tests"> | ||
<testsuite name="addition" tests="1" errors="0" failures="0" skipped="0" timestamp="2017-07-13T09:42:28" time="0.161"> | ||
<testcase classname="addition positive numbers should add up" name="addition positive numbers should add up" time="0.004"> | ||
<properties> | ||
<property name="dd_tags[test.invocations]" value="1" /> | ||
</properties> | ||
</testcase> | ||
</testsuite> | ||
</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](https://docs.datadoghq.com/continuous_integration/tests/junit_upload/?tab=jenkins#providing-metadata-through-property-elements) | ||
[test-results-processor]: https://github.com/jest-community/jest-junit/discussions/158#discussioncomment-392985 |
@@ -8,2 +8,3 @@ 'use strict'; | ||
const getTestSuitePropertiesPath = require('./getTestSuitePropertiesPath'); | ||
const replaceRootDirInOutput = require('./getOptions').replaceRootDirInOutput; | ||
@@ -42,3 +43,17 @@ // Wrap the varName with template tags | ||
const generateTestCase = function(junitOptions, suiteOptions, tc, filepath, filename, suiteTitle, displayName){ | ||
const getTestCasePropertiesPath = (options, rootDir = null) => { | ||
const testCasePropertiesPath = replaceRootDirInOutput( | ||
rootDir, | ||
path.join( | ||
options.testCasePropertiesDirectory, | ||
options.testCasePropertiesFile, | ||
), | ||
); | ||
return path.isAbsolute(testCasePropertiesPath) | ||
? testCasePropertiesPath | ||
: path.resolve(testCasePropertiesPath); | ||
}; | ||
const generateTestCase = function(junitOptions, suiteOptions, tc, filepath, filename, suiteTitle, displayName, getGetCaseProperties){ | ||
const classname = tc.ancestorTitles.join(suiteOptions.ancestorSeparator); | ||
@@ -92,2 +107,26 @@ const testTitle = tc.title; | ||
if (getGetCaseProperties !== null) { | ||
let junitCaseProperties = getGetCaseProperties(tc); | ||
// Add any test suite properties | ||
let testCasePropertyMain = { | ||
'properties': [] | ||
}; | ||
Object.keys(junitCaseProperties).forEach((p) => { | ||
let testSuiteProperty = { | ||
'property': { | ||
_attr: { | ||
name: p, | ||
value: junitCaseProperties[p] | ||
} | ||
} | ||
}; | ||
testCasePropertyMain.properties.push(testSuiteProperty); | ||
}); | ||
testCase.testcase.push(testCasePropertyMain); | ||
} | ||
return testCase; | ||
@@ -121,2 +160,5 @@ } | ||
const testCasePropertiesPath = getTestCasePropertiesPath(options, rootDir) | ||
const getTestCaseProperties = fs.existsSync(testCasePropertiesPath) ? require(testCasePropertiesPath) : null | ||
// If the usePathForSuiteName option is true and the | ||
@@ -230,3 +272,12 @@ // suiteNameTemplate value is set to the default, overrides | ||
suite.testResults.forEach((tc) => { | ||
const testCase = generateTestCase(options, suiteOptions, tc, filepath, filename, suiteTitle, displayName) | ||
const testCase = generateTestCase( | ||
options, | ||
suiteOptions, | ||
tc, | ||
filepath, | ||
filename, | ||
suiteTitle, | ||
displayName, | ||
getTestCaseProperties | ||
); | ||
testSuite.testsuite.push(testCase); | ||
@@ -245,2 +296,3 @@ }); | ||
duration: 0, | ||
invocations: 1, | ||
}; | ||
@@ -254,3 +306,4 @@ const testCase = generateTestCase( | ||
suiteTitle, | ||
displayName | ||
displayName, | ||
getTestCaseProperties | ||
); | ||
@@ -257,0 +310,0 @@ testSuite.testsuite.push(testCase); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
41858
508
287
9