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

fix: total results in junit newman #19

Merged
merged 1 commit into from
Oct 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "test-results-parser",
"version": "0.1.1",
"version": "0.1.2",
"description": "Parse test results from JUnit, TestNG, xUnit, cucumber and many more",
"main": "src/index.js",
"types": "./src/index.d.ts",
Expand Down
3 changes: 3 additions & 0 deletions src/parsers/junit.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,13 @@ function getTestSuite(rawSuite) {
*/
function setAggregateResults(result) {
if (Number.isNaN(result.passed) || Number.isNaN(result.failed)) {
let total = 0;
let passed = 0;
let failed = 0;
let errors = 0;
let skipped = 0;
result.suites.forEach(_suite => {
total = _suite.total + total;
passed = _suite.passed + passed;
failed = _suite.failed + failed;
errors = _suite.errors + errors;
Expand All @@ -53,6 +55,7 @@ function setAggregateResults(result) {
result.failed = failed;
result.errors = errors;
result.skipped = skipped;
result.total = total;
}
}

Expand Down
13 changes: 13 additions & 0 deletions tests/data/junit/newman-failures.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuites name="MainApi" tests="2" time="37.506">
<testsuite name="Main / GetSectors" id="156d11f0-2897-4c14-a1c4-a35d9a686391" timestamp="2022-10-08T20:11:16.443Z" tests="2" failures="2" errors="0" time="0.446">
<testcase name="Sectors - Verify 'Residential' is in list" time="0.446" classname="MainApi">
<failure type="AssertionFailure" message="expected to include 'Residntial'">
</failure>
</testcase>
<testcase name="Sectors EndPoint - returns a JSON response" time="0.446" classname="MainApi"/>
</testsuite>
<testsuite name="Main / Verifyresponsedata-MarketAsset" id="47f011d3-ca6e-451d-a5c4-d43243b082fe" timestamp="2022-10-08T20:11:16.443Z" tests="1" failures="0" errors="0" time="0.634">
<testcase name="Market Asset(id-387) response - data is as expected" time="0.634" classname="MainApi"/>
</testsuite>
</testsuites>
87 changes: 87 additions & 0 deletions tests/parser.junit.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -327,4 +327,91 @@ describe('Parser - JUnit', () => {
});
});

it('parse newman with failures', () => {
const result = parse({ type: 'junit', files: ['tests/data/junit/newman-failures.xml'] });
console.log(JSON.stringify(result, null, 2))
assert.deepEqual(result, {
"id": "",
"name": "MainApi",
"total": 3,
"passed": 1,
"failed": 2,
"errors": 0,
"skipped": 0,
"retried": 0,
"duration": 37506,
"status": "FAIL",
"suites": [
{
"id": "",
"name": "Main / GetSectors",
"total": 2,
"passed": 0,
"failed": 2,
"errors": 0,
"skipped": 0,
"duration": 446,
"status": "FAIL",
"cases": [
{
"id": "",
"name": "Sectors - Verify 'Residential' is in list",
"total": 0,
"passed": 0,
"failed": 0,
"errors": 0,
"skipped": 0,
"duration": 446,
"status": "FAIL",
"failure": "expected to include 'Residntial'",
"stack_trace": "",
"steps": []
},
{
"id": "",
"name": "Sectors EndPoint - returns a JSON response",
"total": 0,
"passed": 0,
"failed": 0,
"errors": 0,
"skipped": 0,
"duration": 446,
"status": "PASS",
"failure": "",
"stack_trace": "",
"steps": []
}
]
},
{
"id": "",
"name": "Main / Verifyresponsedata-MarketAsset",
"total": 1,
"passed": 1,
"failed": 0,
"errors": 0,
"skipped": 0,
"duration": 634,
"status": "PASS",
"cases": [
{
"id": "",
"name": "Market Asset(id-387) response - data is as expected",
"total": 0,
"passed": 0,
"failed": 0,
"errors": 0,
"skipped": 0,
"duration": 634,
"status": "PASS",
"failure": "",
"stack_trace": "",
"steps": []
}
]
}
]
});
});

});