Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow custom properties via junitTestCaseProperties.js #274

Open
gabriel-cloud opened this issue Jan 23, 2025 · 0 comments · May be fixed by #275
Open

Allow custom properties via junitTestCaseProperties.js #274

gabriel-cloud opened this issue Jan 23, 2025 · 0 comments · May be fixed by #275

Comments

@gabriel-cloud
Copy link

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 pushed a commit to gabriel-cloud/jest-junit that referenced this issue Jan 23, 2025
@gabriel-cloud gabriel-cloud linked a pull request Jan 23, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant