From 3846265f8fa39811915a305220daa794285cabee Mon Sep 17 00:00:00 2001 From: Gabe Date: Thu, 23 Jan 2025 15:15:21 +0000 Subject: [PATCH 1/2] Allow custom properties via junitTestCaseProperties.js Fixes #274 --- utils/buildJsonResults.js | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) 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); } From 4040b59db09b787acad15debe61d4058e38be6a2 Mon Sep 17 00:00:00 2001 From: Gabe Date: Thu, 23 Jan 2025 15:19:25 +0000 Subject: [PATCH 2/2] update readme --- README.md | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) 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)