Skip to content

Commit

Permalink
implementation for junit top-level suite test-results-reporter#46
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanbcook committed Feb 13, 2024
1 parent 6c52936 commit d7de0f6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
17 changes: 11 additions & 6 deletions src/parsers/junit.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ function setAggregateResults(result) {
*/
function getTestResult(json) {
const result = new TestResult();
const rawResult = json["testsuites"][0];
const rawResult = json["testsuites"] ? json["testsuites"][0] : json["testsuite"];
result.name = rawResult["@_name"] || '';
result.total = rawResult["@_tests"];
result.failed = rawResult["@_failures"];
Expand All @@ -111,13 +111,18 @@ function getTestResult(json) {
result.total = result.total - result.skipped;
result.passed = result.total - result.failed - result.errors;
result.duration = rawResult["@_time"] * 1000;
const rawSuites = rawResult["testsuite"];
if (!(typeof rawSuites === "undefined")) { // Don't filter if there are no testsuite objects
const filteredSuites = rawSuites.filter(suite => suite.testcase);
for (let i = 0; i < filteredSuites.length; i++) {
result.suites.push(getTestSuite(filteredSuites[i]));
if (json["testsuites"]) { // top-level element is testsuites
const rawSuites = rawResult["testsuite"];
if (!(typeof rawSuites === "undefined")) { // Don't filter if there are no testsuite objects
const filteredSuites = rawSuites.filter(suite => suite.testcase);
for (let i = 0; i < filteredSuites.length; i++) {
result.suites.push(getTestSuite(filteredSuites[i]));
}
}
} else { // top level element is testsuite
result.suites.push(getTestSuite(rawResult));
}

setAggregateResults(result);
result.status = result.total === result.passed ? 'PASS' : 'FAIL';
return result;
Expand Down
2 changes: 1 addition & 1 deletion tests/parser.junit.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ describe('Parser - JUnit', () => {
});
});

it('parse testcafe with testSuite root node', () => {
it('parse testcafe with testsuite root node', () => {
const result = parse({ type: 'junit', files: [`${testDataPath}/testCafe.xml`] });

assert.equal(result.suites.length, 1);
Expand Down

0 comments on commit d7de0f6

Please sign in to comment.