diff --git a/README.md b/README.md index dbfa134..2189386 100644 --- a/README.md +++ b/README.md @@ -267,6 +267,7 @@ module.exports = (testResult) => { }; ``` + Will render ```xml @@ -280,6 +281,49 @@ Will render ``` +For custom attributes or sections (like CDATA) use an array of objects: +```js +module.exports = (testResult) => { + const properties = [ + { + _attr: { + name: 'testName1', + value: 'testValue1', + }, + }, + { + _attr: { + name: 'testName2', + value: 'testValue2', + }, + }, + { + _attr: { + name: 'testName3', + value: 'testValue3', + }, + _cdata: 'testCData 3', + }, + ]; + return properties; +}; +``` + +Will render: +```xml + + + + + + + + + + + + + WARNING: Properties for testcases is not following standard JUnit XML schema. However, other consumers may support properties for testcases like [DataDog metadata through `` elements](https://docs.datadoghq.com/continuous_integration/tests/junit_upload/?tab=jenkins#providing-metadata-through-property-elements) diff --git a/utils/buildJsonResults.js b/utils/buildJsonResults.js index 46d2378..d03298a 100644 --- a/utils/buildJsonResults.js +++ b/utils/buildJsonResults.js @@ -110,18 +110,26 @@ const generateTestCase = function(junitOptions, suiteOptions, tc, filepath, file 'properties': [] }; - Object.keys(junitCaseProperties).forEach((p) => { - let testSuiteProperty = { - 'property': { - _attr: { - name: p, - value: junitCaseProperties[p] - } - } - }; - - testCasePropertyMain.properties.push(testSuiteProperty); - }); + if (Array.isArray(junitCaseProperties)) { + junitCaseProperties.forEach((property) => { + let testSuiteProperty = { + property: property, + }; + testCasePropertyMain.properties.push(testSuiteProperty); + }); + } else { + Object.keys(junitCaseProperties).forEach((p) => { + let testSuiteProperty = { + property: { + _attr: { + name: p, + value: junitCaseProperties[p], + }, + }, + }; + testCasePropertyMain.properties.push(testSuiteProperty); + }); + } testCase.testcase.push(testCasePropertyMain); }