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

JUnit support for testsuite as root node #47

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
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
7 changes: 7 additions & 0 deletions tests/data/junit/testCafe.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8" ?>
<testsuite name="TestCafe Tests" tests="2" failures="0" skipped="0" errors="0" time="211.682" timestamp="Tue, 13 Feb 2024 10:28:58 GMT" >
<testcase classname="Tests" file="/home/vsts/work/1/s/testcafe/tests/test1.js" name="Test1" time="15.513">
</testcase>
<testcase classname="Tests" file="/home/vsts/work/1/s/testcafe/tests/test1.js" name="Test2" time="193.695">
</testcase>
</testsuite>
7 changes: 7 additions & 0 deletions tests/parser.junit.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down
Loading