From b0c1998707821d595e74ca5d385b60644262e616 Mon Sep 17 00:00:00 2001 From: Anudeep Date: Sat, 8 Oct 2022 15:53:24 +0530 Subject: [PATCH] fix - junit report from newman --- package-lock.json | 2 +- package.json | 8 ++++--- src/parsers/junit.js | 23 +++++++++++++++++++ tests/data/junit/newman.xml | 6 +++++ tests/parser.junit.spec.js | 45 +++++++++++++++++++++++++++++++++++++ 5 files changed, 80 insertions(+), 4 deletions(-) create mode 100644 tests/data/junit/newman.xml diff --git a/package-lock.json b/package-lock.json index 5252f7b..de6608e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "test-results-parser", - "version": "0.1.0", + "version": "0.1.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index e07a642..4dbfb59 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "test-results-parser", - "version": "0.1.0", - "description": "Parse test results from JUnit, TestNG, xUnit and many more", + "version": "0.1.1", + "description": "Parse test results from JUnit, TestNG, xUnit, cucumber and many more", "main": "src/index.js", "types": "./src/index.d.ts", "scripts": { @@ -20,7 +20,9 @@ "testing", "results", "result", - "automation" + "automation", + "mocha", + "cucumber" ], "author": "Anudeep ", "license": "MIT", diff --git a/src/parsers/junit.js b/src/parsers/junit.js index b941117..2fd89e4 100644 --- a/src/parsers/junit.js +++ b/src/parsers/junit.js @@ -34,6 +34,28 @@ function getTestSuite(rawSuite) { return suite; } +/** + * @param {TestResult} result + */ +function setAggregateResults(result) { + if (Number.isNaN(result.passed) || Number.isNaN(result.failed)) { + let passed = 0; + let failed = 0; + let errors = 0; + let skipped = 0; + result.suites.forEach(_suite => { + passed = _suite.passed + passed; + failed = _suite.failed + failed; + errors = _suite.errors + errors; + skipped = _suite.skipped + skipped; + }); + result.passed = passed; + result.failed = failed; + result.errors = errors; + result.skipped = skipped; + } +} + function getTestResult(json) { const result = new TestResult(); const rawResult = json["testsuites"][0]; @@ -56,6 +78,7 @@ function getTestResult(json) { for (let i = 0; i < filteredSuites.length; i++) { result.suites.push(getTestSuite(filteredSuites[i])); } + setAggregateResults(result); result.status = result.total === result.passed ? 'PASS' : 'FAIL'; return result; } diff --git a/tests/data/junit/newman.xml b/tests/data/junit/newman.xml new file mode 100644 index 0000000..774feee --- /dev/null +++ b/tests/data/junit/newman.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/tests/parser.junit.spec.js b/tests/parser.junit.spec.js index 25de08c..0cd488f 100644 --- a/tests/parser.junit.spec.js +++ b/tests/parser.junit.spec.js @@ -282,4 +282,49 @@ describe('Parser - JUnit', () => { }); }); + it('parse newman reporter', () => { + const result = parse({ type: 'junit', files: ['tests/data/junit/newman.xml'] }); + assert.deepEqual(result, { + id: '', + name: 'MyCollection', + total: 1, + passed: 1, + failed: 0, + errors: 0, + skipped: 0, + retried: 0, + duration: 32937, + status: 'PASS', + suites: [ + { + id: '', + name: '1 - Authenticate', + total: 1, + passed: 1, + failed: 0, + errors: 0, + skipped: 0, + duration: 807, + status: 'PASS', + cases: [ + { + duration: 807, + errors: 0, + failed: 0, + failure: "", + id: "", + name: "Teste", + passed: 0, + skipped: 0, + stack_trace: "", + status: "PASS", + steps: [], + total: 0 + } + ] + } + ] + }); + }); + }); \ No newline at end of file