Skip to content

Commit

Permalink
Merge pull request #18 from test-results-reporter/17-nan-in-my-report…
Browse files Browse the repository at this point in the history
…-using-newman

fix - junit report from newman
  • Loading branch information
ASaiAnudeep authored Oct 8, 2022
2 parents b1222df + b0c1998 commit 7d41646
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand All @@ -20,7 +20,9 @@
"testing",
"results",
"result",
"automation"
"automation",
"mocha",
"cucumber"
],
"author": "Anudeep <asa.anudeep4@gmail.com>",
"license": "MIT",
Expand Down
23 changes: 23 additions & 0 deletions src/parsers/junit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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;
}
Expand Down
6 changes: 6 additions & 0 deletions tests/data/junit/newman.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuites name="MyCollection" tests="1" time="32.937">
<testsuite name="1 - Authenticate " id="u68c4966-0877-4766-1e5b-uu96efb7f84" timestamp="2022-09-20T16:49:56.147Z" tests="1" failures="0" errors="0" time="0.807">
<testcase name="Teste" time="0.807" classname="TestePostamn"/>
</testsuite>
</testsuites>
45 changes: 45 additions & 0 deletions tests/parser.junit.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
]
}
]
});
});

});

0 comments on commit 7d41646

Please sign in to comment.