From e4f339467c80511bfc768a7b863a8067511f0130 Mon Sep 17 00:00:00 2001 From: Craig Hammond Date: Fri, 28 Jun 2024 12:16:00 -0400 Subject: [PATCH] Check for key existence to identify junit file Add junit identity test for empty junit file --- src/test_parser.ts | 2 +- test/file.ts | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/test_parser.ts b/src/test_parser.ts index d94e21b..6265ebd 100644 --- a/src/test_parser.ts +++ b/src/test_parser.ts @@ -312,7 +312,7 @@ export async function parseFile(filename: string): Promise { const xml: any = await parser(data) - if (xml.testsuites || xml.testsuite) { + if ('testsuites' in xml || 'testsuite' in xml) { return await parseJunitXml(xml) } diff --git a/test/file.ts b/test/file.ts index 782505e..3b27665 100644 --- a/test/file.ts +++ b/test/file.ts @@ -55,4 +55,11 @@ describe("file", async () => { expect(result.counts.failed).to.eql(4) expect(result.counts.skipped).to.eql(2) }) + + it("identifies empty junit", async () => { + const result = await parseFile(`${junitResourcePath}/05-empty.xml`) + expect(result.counts.passed).to.eql(0) + expect(result.counts.failed).to.eql(0) + expect(result.counts.skipped).to.eql(0) + }) })