Skip to content

Commit b7ef112

Browse files
authored
JUnit fixes for root suite "testsuite" (#100)
* tests to reproduce #98 and #99 * switch single test to passing test * fix for #98 and #99 * additional specificity (helped to identify #99)
1 parent c31c776 commit b7ef112

File tree

5 files changed

+41
-4
lines changed

5 files changed

+41
-4
lines changed

src/helpers/helper.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ const FORCED_ARRAY_KEYS = [
1919
"testsuites.testsuite.testcase.error",
2020
"testsuites.testsuite.testcase.system-err",
2121
"testsuites.testsuite.testcase.properties.property",
22+
"testsuite.testcase",
23+
"testsuite.testcase.failure",
24+
"testsuite.testcase.error",
25+
"testsuite.testcase.system-err",
26+
"testsuite.testcase.properties.property",
2227
"assemblies",
2328
"assemblies.assembly",
2429
"assemblies.assembly.collection",

tests/data/junit/playwright-failures.xml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
<testcase name="has title" classname="example.spec.ts" time="0.475">
1818
</testcase>
1919
<testcase name="get started link" classname="example.spec.ts" time="5.433">
20-
<failure message="example.spec.ts:10:5 get started link" type="FAILURE">
21-
<![CDATA[ [chromium] › example.spec.ts:10:5 › get started link ─────────────────────────────────────────────
20+
<failure message="example.spec.ts:10:5 get started link" type="FAILURE"><![CDATA[ [chromium] › example.spec.ts:10:5 › get started link ─────────────────────────────────────────────
2221
2322
Error: Timed out 5000ms waiting for expect(locator).toBeVisible()
2423
@@ -42,8 +41,7 @@
4241
attachment #1: screenshot (image/png) ──────────────────────────────────────────────────────────
4342
test-results/example-get-started-link-chromium/test-failed-1.png
4443
────────────────────────────────────────────────────────────────────────────────────────────────
45-
]]>
46-
</failure>
44+
]]></failure>
4745
<system-out>
4846
<![CDATA[
4947
[[ATTACHMENT|example-get-started-link-chromium/test-failed-1.png]]
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<testsuite name="com.example.SampleTests" time="0.122" tests="2" errors="0" skipped="0" failures="1">
3+
<testcase name="failingTest" classname="com.example.SampleTests" time="0.021">
4+
<failure message="This test failed intentially" type="org.opentest4j.AssertionFailedError"><![CDATA[org.opentest4j.AssertionFailedError: This test failed intentially
5+
at org.junit.jupiter.api.AssertionUtils.fail(AssertionUtils.java:38)
6+
at org.junit.jupiter.api.Assertions.fail(Assertions.java:134)
7+
at com.example.SampleTests.failingTest(SampleTests.java:19)
8+
at java.base/java.lang.reflect.Method.invoke(Method.java:569)
9+
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
10+
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
11+
]]></failure>
12+
</testcase>
13+
<testcase name="x" classname="com.example.SampleTests" time="0.101"/>
14+
</testsuite>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<testsuite name="com.example.SampleTests" time="0.122" tests="1" errors="0" skipped="0" failures="0">
3+
<testcase name="failingTest" classname="com.example.SampleTests" time="0.021"/>
4+
</testsuite>

tests/parser.junit.spec.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,21 @@ describe('Parser - JUnit', () => {
496496
assert.equal(result.suites[0].cases.length, 2);
497497
});
498498

499+
it('can detect failures with testsuite root node', () => {
500+
const result = parse({ type: 'junit', files: [`${testDataPath}/testsuite-with-error.xml`] });
501+
502+
assert.equal(result.total, 2);
503+
assert.equal(result.failed, 1);
504+
assert.equal(result.suites[0].cases[0].status, 'FAIL');
505+
})
506+
507+
it('can detect single suite and single test case', () => {
508+
const result = parse({ type: 'junit', files: [`${testDataPath}/testsuite-with-singletest.xml`] });
509+
510+
assert.equal(result.total, 1);
511+
assert.equal(result.suites[0].cases[0].status, 'PASS');
512+
})
513+
499514
it('empty suite with no tests', () => {
500515
const result = parse({ type: 'junit', files: [`${testDataPath}/no-suites.xml`] });
501516
assert.deepEqual(result, {
@@ -638,6 +653,7 @@ describe('Parser - JUnit', () => {
638653
assert.equal(result.status, 'FAIL');
639654
assert.equal(result.suites[1].cases[1].attachments[0].name, `test-failed-1.png`);
640655
assert.equal(result.suites[1].cases[1].attachments[0].path, `example-get-started-link-chromium/test-failed-1.png`);
656+
assert.equal(result.suites[1].cases[1].status, 'FAIL');
641657
});
642658

643659

0 commit comments

Comments
 (0)