diff --git a/.changeset/beige-timers-juggle.md b/.changeset/beige-timers-juggle.md new file mode 100644 index 000000000..bb55a0e97 --- /dev/null +++ b/.changeset/beige-timers-juggle.md @@ -0,0 +1,5 @@ +--- +'@web/test-runner-junit-reporter': minor +--- + +Update result format to match JUnit Schema definitions diff --git a/packages/test-runner-junit-reporter/src/junitReporter.ts b/packages/test-runner-junit-reporter/src/junitReporter.ts index 7ba8d5b79..96b3f3dd3 100644 --- a/packages/test-runner-junit-reporter/src/junitReporter.ts +++ b/packages/test-runner-junit-reporter/src/junitReporter.ts @@ -31,7 +31,6 @@ interface TestCaseXMLAttributes { _attr: { name: string; time: number; - file: string; line?: string; classname: string; }; @@ -62,7 +61,8 @@ interface TestSuiteXMLAttributes { skipped: number; errors: number; failures: number; - time: number; + time: string; + file: string; }; } @@ -120,8 +120,6 @@ const getTestName: TestMetaGetter = test => test.name; const getSuiteName: TestMetaGetter = test => test.suiteName; -const getTestFile: TestMetaGetter = test => test.testFile; - const getTestDurationInSeconds = ({ duration }: TestResult): number => (typeof duration === 'undefined' ? 0 : duration) / 1000; @@ -161,18 +159,13 @@ function testFailureXMLElement(test: TestResultWithMetadata): TestFailureXMLElem * Makes attributes for a `` element * @param test Test Result */ -function testCaseXMLAttributes( - test: TestResultWithMetadata, - rootDir: string, -): TestCaseXMLAttributes { +function testCaseXMLAttributes(test: TestResultWithMetadata): TestCaseXMLAttributes { const name = getTestName(test); const time = getTestDurationInSeconds(test); const classname = getSuiteName(test); - const file = getTestFile(test).replace(`${rootDir}${path.sep}`, ''); - const [, line] = stripXMLInvalidChars(test.error?.stack ?? '').match(/(\d+):\d+/m) ?? []; return { @@ -180,7 +173,6 @@ function testCaseXMLAttributes( name, time, classname, - file, ...(!!line && { line }), }, }; @@ -189,8 +181,8 @@ function testCaseXMLAttributes( /** * Makes a `` element */ -function testCaseXMLElement(test: TestResultWithMetadata, rootDir: string): TestCaseXMLElement { - const attributes = testCaseXMLAttributes(test, rootDir); +function testCaseXMLElement(test: TestResultWithMetadata): TestCaseXMLElement { + const attributes = testCaseXMLAttributes(test); // prettier-ignore if (isSkippedTest(test)) @@ -211,6 +203,8 @@ function testSuiteXMLAttributes( name: string, id: number, results: TestResultWithMetadata[], + testFile: string, + rootDir: string, ): TestSuiteXMLAttributes { const tests = results.length; @@ -220,7 +214,9 @@ function testSuiteXMLAttributes( const failures = results.filter(isFailedTest).length; - const time = results.reduce(addSuiteTime, 0); + const time = results.reduce(addSuiteTime, 0).toFixed(3); + + const file = testFile.replace(`${rootDir}${path.sep}`, ''); return { _attr: { @@ -231,6 +227,7 @@ function testSuiteXMLAttributes( errors, failures, time, + file, }, }; } @@ -303,11 +300,11 @@ function getTestRunXML({ const launcherType = browser.type ?? ''; - const attributes = testSuiteXMLAttributes(name, testRun, tests); + const attributes = testSuiteXMLAttributes(name, testRun, tests, testFile, rootDir); const properties = testSuitePropertiesXMLElement(testFile, browserName, launcherType, rootDir); - const testcases = tests.map(t => testCaseXMLElement(t, rootDir)); + const testcases = tests.map(testCaseXMLElement); const systemOut = !reportLogs ? [] : tests.flatMap(escapeLogs).map(x => ({ 'system-out': x })); diff --git a/packages/test-runner-junit-reporter/test/fixtures/multiple/expected.xml b/packages/test-runner-junit-reporter/test/fixtures/multiple/expected.xml index 88dd3f7a4..6e4ce1472 100644 --- a/packages/test-runner-junit-reporter/test/fixtures/multiple/expected.xml +++ b/packages/test-runner-junit-reporter/test/fixtures/multiple/expected.xml @@ -1,28 +1,28 @@ - + - + - + - - - + + + (packages/test-runner-junit-reporter/test/fixtures/multiple/simple-test.js:15:29)]]> - + - + - + \ No newline at end of file diff --git a/packages/test-runner-junit-reporter/test/fixtures/nested/expected.xml b/packages/test-runner-junit-reporter/test/fixtures/nested/expected.xml index d1633aa04..e8260fb00 100644 --- a/packages/test-runner-junit-reporter/test/fixtures/nested/expected.xml +++ b/packages/test-runner-junit-reporter/test/fixtures/nested/expected.xml @@ -1,11 +1,11 @@ - + - + - + \ No newline at end of file diff --git a/packages/test-runner-junit-reporter/test/fixtures/simple/expected.xml b/packages/test-runner-junit-reporter/test/fixtures/simple/expected.xml index d2293173b..34fc363a1 100644 --- a/packages/test-runner-junit-reporter/test/fixtures/simple/expected.xml +++ b/packages/test-runner-junit-reporter/test/fixtures/simple/expected.xml @@ -1,25 +1,25 @@ - + - - - + + + (packages/test-runner-junit-reporter/test/fixtures/simple/simple-test.js:17:29)]]> - + - - + + (packages/test-runner-junit-reporter/test/fixtures/simple/simple-test.js:33:17)]]> - + \ No newline at end of file