jest-junit icon indicating copy to clipboard operation
jest-junit copied to clipboard

Allow custom properties via junitTestCaseProperties.js

Open gabriel-cloud opened this issue 10 months ago • 0 comments

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch [email protected] for the project I'm working on.

The current implementation only allows you to add name and value to a <property/>. My test management software (Testmo) needs a CDATA section inside a `. https://docs.testmo.com/docs/automation/advanced/test-fields

Here is the diff that solved my problem, which handles both the current implementation (which doesn't break any existing use cases, and the new implementation. I'll create a PR soon

diff --git a/node_modules/jest-junit/.DS_Store b/node_modules/jest-junit/.DS_Store
new file mode 100644
index 0000000..e69de29
diff --git a/node_modules/jest-junit/utils/buildJsonResults.js b/node_modules/jest-junit/utils/buildJsonResults.js
index 46d2378..7d842a1 100644
--- a/node_modules/jest-junit/utils/buildJsonResults.js
+++ b/node_modules/jest-junit/utils/buildJsonResults.js
@@ -109,19 +109,27 @@ const generateTestCase = function(junitOptions, suiteOptions, tc, filepath, file
     let testCasePropertyMain = {
       'properties': []
     };
-
-    Object.keys(junitCaseProperties).forEach((p) => {
-      let testSuiteProperty = {
-        'property': {
-          _attr: {
-            name: p,
-            value: junitCaseProperties[p]
-          }
+    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);
+      });
+    }
 
-      testCasePropertyMain.properties.push(testSuiteProperty);
-    });
 
     testCase.testcase.push(testCasePropertyMain);
   }

This issue body was partially generated by patch-package.

gabriel-cloud avatar Jan 23 '25 12:01 gabriel-cloud