Skip to content

Commit

Permalink
Merge branch 'fix-empty-test-suites'
Browse files Browse the repository at this point in the history
  • Loading branch information
ethomson committed Jan 25, 2023
2 parents 6b9d55c + b266d9a commit aa6f1b8
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/test_parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,9 @@ export async function parseTap(data: string): Promise<TestResult> {
async function parseJunitXml(xml: any): Promise<TestResult> {
let testsuites

if (xml.testsuites) {
testsuites = xml.testsuites.testsuite
} else if (xml.testsuite) {
if ('testsuites' in xml) {
testsuites = xml.testsuites.testsuite || [ ]
} else if ('testsuite' in xml) {
testsuites = [ xml.testsuite ]
} else {
throw new Error("expected top-level testsuites or testsuite node")
Expand Down
20 changes: 19 additions & 1 deletion test/junit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,5 +105,23 @@ describe("junit", async () => {
expect(result.suites[0].cases[0].status).to.eql(TestStatus.Fail)
expect(result.suites[1].cases[0].name).to.eql("dummy/path/to/project/and/passing_test_target")
expect(result.suites[1].cases[0].status).to.eql(TestStatus.Pass)
})
})

it("parses empty testsuites", async () => {
const result = await parseJunitFile(`${resourcePath}/05-empty.xml`)

expect(result.counts.passed).to.eql(0)
expect(result.counts.failed).to.eql(0)
expect(result.counts.skipped).to.eql(0)
expect(result.suites.length).to.eql(0)
})

it("parses empty testsuite", async () => {
const result = await parseJunitFile(`${resourcePath}/06-empty.xml`)

expect(result.counts.passed).to.eql(0)
expect(result.counts.failed).to.eql(0)
expect(result.counts.skipped).to.eql(0)
expect(result.suites.length).to.eql(0)
})
})
1 change: 1 addition & 0 deletions test/resources/junit/05-empty.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<testsuites />
1 change: 1 addition & 0 deletions test/resources/junit/06-empty.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<testsuite />

0 comments on commit aa6f1b8

Please sign in to comment.