Skip to content

Commit 8537f48

Browse files
committed
Fix bug with empty testsuites
1 parent d48ae5e commit 8537f48

4 files changed

Lines changed: 11 additions & 9 deletions

File tree

package-lock.json

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "live-spec",
3-
"version": "0.0.5",
3+
"version": "0.0.6",
44
"description": "[WIP] Generate live spec from feature files & JUnit test results",
55
"bin": "cli.js",
66
"scripts": {
@@ -50,4 +50,4 @@
5050
"ts-jest": "^27.1.3",
5151
"typescript": "4.5.x"
5252
}
53-
}
53+
}

src/__tests__/junit.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ describe('junit', () => {
1010

1111
const VALID_JUNIT_XML = `<?xml version="1.0" encoding="UTF-8"?>
1212
<testsuites name="my testsuites">
13+
<testsuite name="empty testsuire" errors="0" failures="0" skipped="0" tests="0" timestamp="2022-03-01T08:00:00">
14+
</testsuite>
1315
<testsuite name="my first testsuite" errors="1" failures="1" skipped="1" tests="4" timestamp="2022-03-01T08:00:00">
1416
<testcase name="my ok testcase">
1517
</testcase>

src/junit.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ function testcaseDetails(from: ErrorOrFailure): string | undefined {
5454
export async function parseJunitXml(xml: string): Promise<Testsuite[]> {
5555
const { testsuites } = await parseXml(xml);
5656
return (testsuites?.testsuite || []).map(
57-
({ $: { name, timestamp, failures, errors }, testcase: testcases }: JUnitTestsuite) => ({
57+
({ $: { name, timestamp, failures, errors }, testcase: testcases }: JUnitTestsuite) => ((testcases == null || testcases.length == 0) ? null : {
5858
name,
5959
timestamp,
6060
status: Number.parseInt(failures) + Number.parseInt(errors) > 0 ? 'failure' : 'success',
@@ -65,7 +65,7 @@ export async function parseJunitXml(xml: string): Promise<Testsuite[]> {
6565
details: testcaseDetails((error || [])[0] || (failure || [])[0])
6666
}))
6767
})
68-
);
68+
).filter((ts: unknown) => ts != null);
6969
}
7070

7171
// loads a XML file and parses its contents into a list of testsuites

0 commit comments

Comments
 (0)