test-results-reporter / parser

Parse test results from JUnit, TestNG, xUnit and many more
https://www.testbeats.com
MIT License
12 stars 9 forks source link

Expose timestamp for a test suite from JUnit #85

Open tovbinm opened 3 weeks ago

tovbinm commented 3 weeks ago

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch test-results-parser@0.2.3 for the project I'm working on.

This change allows exposing timestamp for a test suite from JUnit.

Here is the diff that solved my problem:

diff --git a/node_modules/test-results-parser/src/index.d.ts b/node_modules/test-results-parser/src/index.d.ts
index f128d44..89c8ab5 100644
--- a/node_modules/test-results-parser/src/index.d.ts
+++ b/node_modules/test-results-parser/src/index.d.ts
@@ -22,6 +22,7 @@ export interface ITestSuite {
   errors: number;
   skipped: number;
   duration: number;
+  timestamp: string;
   status: string;
   tags: string[];
   metadata: object;
diff --git a/node_modules/test-results-parser/src/models/TestSuite.d.ts b/node_modules/test-results-parser/src/models/TestSuite.d.ts
index 2a7628a..6bd9389 100644
--- a/node_modules/test-results-parser/src/models/TestSuite.d.ts
+++ b/node_modules/test-results-parser/src/models/TestSuite.d.ts
@@ -8,6 +8,7 @@ declare class TestSuite {
   errors: number;
   skipped: number;
   duration: number;
+  timestamp: string;
   status: string;
   tags: string[];
   metadata: object;
diff --git a/node_modules/test-results-parser/src/models/TestSuite.js b/node_modules/test-results-parser/src/models/TestSuite.js
index 776c56f..182be8e 100644
--- a/node_modules/test-results-parser/src/models/TestSuite.js
+++ b/node_modules/test-results-parser/src/models/TestSuite.js
@@ -9,6 +9,7 @@ class TestSuite {
     this.errors = 0;
     this.skipped = 0;
     this.duration = 0;
+    this.timestamp = '';
     this.status = 'NA';
     this.tags = [];
     this.metadata = {};
diff --git a/node_modules/test-results-parser/src/parsers/junit.js b/node_modules/test-results-parser/src/parsers/junit.js
index 073d7a6..48f54a8 100644
--- a/node_modules/test-results-parser/src/parsers/junit.js
+++ b/node_modules/test-results-parser/src/parsers/junit.js
@@ -62,6 +62,7 @@ function getTestSuite(rawSuite) {
   suite.total = suite.total - suite.skipped;
   suite.passed = suite.total - suite.failed - suite.errors;
   suite.duration = rawSuite["@_time"] * 1000;
+  suite.timestamp = rawSuite["@_timestamp"];
   suite.status = suite.total === suite.passed ? 'PASS' : 'FAIL';
   setMetaData(rawSuite, suite);
   const raw_test_cases = rawSuite.testcase;

This issue body was partially generated by patch-package.