From 6c529360b8b5536fc20acbd7165c6efac21e3b0a Mon Sep 17 00:00:00 2001 From: bryan cook <3217452+bryanbcook@users.noreply.github.com> Date: Tue, 13 Feb 2024 11:36:37 -0500 Subject: [PATCH 1/2] Added failing test --- tests/data/junit/testCafe.xml | 7 +++++++ tests/parser.junit.spec.js | 7 +++++++ 2 files changed, 14 insertions(+) create mode 100644 tests/data/junit/testCafe.xml diff --git a/tests/data/junit/testCafe.xml b/tests/data/junit/testCafe.xml new file mode 100644 index 0000000..eb8a784 --- /dev/null +++ b/tests/data/junit/testCafe.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/tests/parser.junit.spec.js b/tests/parser.junit.spec.js index 057e842..b28569c 100644 --- a/tests/parser.junit.spec.js +++ b/tests/parser.junit.spec.js @@ -529,6 +529,13 @@ describe('Parser - JUnit', () => { }); }); + it('parse testcafe with testSuite root node', () => { + const result = parse({ type: 'junit', files: [`${testDataPath}/testCafe.xml`] }); + + assert.equal(result.suites.length, 1); + assert.equal(result.suites[0].cases.length, 2); + }); + it('empty suite with no tests', () => { const result = parse({ type: 'junit', files: [`${testDataPath}/no-suites.xml`] }); assert.deepEqual(result, { From d7de0f65f0b2212f8562a16cedc88359f4e59de9 Mon Sep 17 00:00:00 2001 From: bryan cook <3217452+bryanbcook@users.noreply.github.com> Date: Tue, 13 Feb 2024 13:01:42 -0500 Subject: [PATCH 2/2] implementation for junit top-level suite #46 --- src/parsers/junit.js | 17 +++++++++++------ tests/parser.junit.spec.js | 2 +- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/parsers/junit.js b/src/parsers/junit.js index b733077..0d39c68 100644 --- a/src/parsers/junit.js +++ b/src/parsers/junit.js @@ -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"]; @@ -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; diff --git a/tests/parser.junit.spec.js b/tests/parser.junit.spec.js index b28569c..ae5add7 100644 --- a/tests/parser.junit.spec.js +++ b/tests/parser.junit.spec.js @@ -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);