Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/beige-timers-juggle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@web/test-runner-junit-reporter': minor
---

Update result format to match JUnit Schema definitions
29 changes: 13 additions & 16 deletions packages/test-runner-junit-reporter/src/junitReporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ interface TestCaseXMLAttributes {
_attr: {
name: string;
time: number;
file: string;
line?: string;
classname: string;
};
Expand Down Expand Up @@ -62,7 +61,8 @@ interface TestSuiteXMLAttributes {
skipped: number;
errors: number;
failures: number;
time: number;
time: string;
file: string;
};
}

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -161,26 +159,20 @@ function testFailureXMLElement(test: TestResultWithMetadata): TestFailureXMLElem
* Makes attributes for a `<testcase>` 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 {
_attr: {
name,
time,
classname,
file,
...(!!line && { line }),
},
};
Expand All @@ -189,8 +181,8 @@ function testCaseXMLAttributes(
/**
* Makes a `<testcase>` 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))
Expand All @@ -211,6 +203,8 @@ function testSuiteXMLAttributes(
name: string,
id: number,
results: TestResultWithMetadata[],
testFile: string,
rootDir: string,
): TestSuiteXMLAttributes {
const tests = results.length;

Expand All @@ -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: {
Expand All @@ -231,6 +227,7 @@ function testSuiteXMLAttributes(
errors,
failures,
time,
file,
},
};
}
Expand Down Expand Up @@ -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 }));

Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
<testsuite name="Chrome_puppeteer_/packages/test-runner-junit-reporter/test/fixtures/multiple/nested-test.js" id="0" tests="1" skipped="0" errors="0" failures="0" time="0.001">
<testsuite name="Chrome_puppeteer_/packages/test-runner-junit-reporter/test/fixtures/multiple/nested-test.js" id="0" tests="1" skipped="0" errors="0" failures="0" time="0.001" file="packages/test-runner-junit-reporter/test/fixtures/multiple/nested-test.js">
<properties>
<property name="test.fileName" value="packages/test-runner-junit-reporter/test/fixtures/multiple/nested-test.js"/>
<property name="browser.name" value="Chrome"/>
<property name="browser.launcher" value="puppeteer"/>
</properties>
<testcase name="is equivalent to map (f.g) f a" time="<<computed>>" classname="given a functor f and a function a -&gt; b map f map g f a" file="packages/test-runner-junit-reporter/test/fixtures/multiple/nested-test.js"/>
<testcase name="is equivalent to map (f.g) f a" time="<<computed>>" classname="given a functor f and a function a -&gt; b map f map g f a"/>
</testsuite>
<testsuite name="Chrome_puppeteer_/packages/test-runner-junit-reporter/test/fixtures/multiple/simple-test.js" id="0" tests="5" skipped="1" errors="1" failures="1" time="0.001">
<testsuite name="Chrome_puppeteer_/packages/test-runner-junit-reporter/test/fixtures/multiple/simple-test.js" id="0" tests="5" skipped="1" errors="1" failures="1" time="0.001" file="packages/test-runner-junit-reporter/test/fixtures/multiple/simple-test.js">
<properties>
<property name="test.fileName" value="packages/test-runner-junit-reporter/test/fixtures/multiple/simple-test.js"/>
<property name="browser.name" value="Chrome"/>
<property name="browser.launcher" value="puppeteer"/>
</properties>
<testcase name="under addition" time="0.001" classname="real numbers forming a monoid" file="packages/test-runner-junit-reporter/test/fixtures/multiple/simple-test.js"/>
<testcase name="null hypothesis" time="0.001" classname="off-by-one boolean logic errors" file="packages/test-runner-junit-reporter/test/fixtures/multiple/simple-test.js"/>
<testcase name="asserts error" time="0.001" classname="off-by-one boolean logic errors" file="packages/test-runner-junit-reporter/test/fixtures/multiple/simple-test.js" line="15">
<testcase name="under addition" time="0.001" classname="real numbers forming a monoid"/>
<testcase name="null hypothesis" time="0.001" classname="off-by-one boolean logic errors"/>
<testcase name="asserts error" time="0.001" classname="off-by-one boolean logic errors" line="15">
<failure message="expected false to be true" type="AssertionError"><![CDATA[AssertionError: expected false to be true
at o.<anonymous> (packages/test-runner-junit-reporter/test/fixtures/multiple/simple-test.js:15:29)]]></failure>
</testcase>
<testcase name="tbd: confirm true positive" time="0" classname="off-by-one boolean logic errors" file="packages/test-runner-junit-reporter/test/fixtures/multiple/simple-test.js">
<testcase name="tbd: confirm true positive" time="0" classname="off-by-one boolean logic errors">
<skipped/>
</testcase>
<testcase name="reports logs to JUnit" time="0.001" classname="logging during a test" file="packages/test-runner-junit-reporter/test/fixtures/multiple/simple-test.js"/>
<testcase name="reports logs to JUnit" time="0.001" classname="logging during a test"/>
</testsuite>
</testsuites>
</testsuites>
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
<testsuite name="Chrome_puppeteer_/packages/test-runner-junit-reporter/test/fixtures/nested/nested-test.js" id="0" tests="1" skipped="0" errors="0" failures="0" time="0.001">
<testsuite name="Chrome_puppeteer_/packages/test-runner-junit-reporter/test/fixtures/nested/nested-test.js" id="0" tests="1" skipped="0" errors="0" failures="0" time="0.001" file="packages/test-runner-junit-reporter/test/fixtures/nested/nested-test.js">
<properties>
<property name="test.fileName" value="packages/test-runner-junit-reporter/test/fixtures/nested/nested-test.js"/>
<property name="browser.name" value="Chrome"/>
<property name="browser.launcher" value="puppeteer"/>
</properties>
<testcase name="is equivalent to map (f.g) f a" time="<<computed>>" classname="given a functor f and a function a -&gt; b map f map g f a" file="packages/test-runner-junit-reporter/test/fixtures/nested/nested-test.js"/>
<testcase name="is equivalent to map (f.g) f a" time="<<computed>>" classname="given a functor f and a function a -&gt; b map f map g f a"/>
</testsuite>
</testsuites>
</testsuites>
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
<testsuite name="Chrome_puppeteer_/packages/test-runner-junit-reporter/test/fixtures/simple/simple-test.js" id="0" tests="6" skipped="1" errors="2" failures="2" time="0.001">
<testsuite name="Chrome_puppeteer_/packages/test-runner-junit-reporter/test/fixtures/simple/simple-test.js" id="0" tests="6" skipped="1" errors="2" failures="2" time="0.001" file="packages/test-runner-junit-reporter/test/fixtures/simple/simple-test.js">
<properties>
<property name="test.fileName" value="packages/test-runner-junit-reporter/test/fixtures/simple/simple-test.js"/>
<property name="browser.name" value="Chrome"/>
<property name="browser.launcher" value="puppeteer"/>
</properties>
<testcase name="under addition" time="0.001" classname="real numbers forming a monoid" file="packages/test-runner-junit-reporter/test/fixtures/simple/simple-test.js"/>
<testcase name="null hypothesis" time="0.001" classname="off-by-one boolean logic errors" file="packages/test-runner-junit-reporter/test/fixtures/simple/simple-test.js"/>
<testcase name="asserts error" time="0.001" classname="off-by-one boolean logic errors" file="packages/test-runner-junit-reporter/test/fixtures/simple/simple-test.js" line="17">
<testcase name="under addition" time="0.001" classname="real numbers forming a monoid"/>
<testcase name="null hypothesis" time="0.001" classname="off-by-one boolean logic errors"/>
<testcase name="asserts error" time="0.001" classname="off-by-one boolean logic errors" line="17">
<failure message="expected false to be true" type="AssertionError"><![CDATA[AssertionError: expected false to be true
at o.<anonymous> (packages/test-runner-junit-reporter/test/fixtures/simple/simple-test.js:17:29)]]></failure>
</testcase>
<testcase name="tbd: confirm true positive" time="0" classname="off-by-one boolean logic errors" file="packages/test-runner-junit-reporter/test/fixtures/simple/simple-test.js">
<testcase name="tbd: confirm true positive" time="0" classname="off-by-one boolean logic errors">
<skipped/>
</testcase>
<testcase name="reports logs to JUnit" time="0.001" classname="logging during a test" file="packages/test-runner-junit-reporter/test/fixtures/simple/simple-test.js"/>
<testcase name="fails with source trace" time="<<computed>>" classname="logging during a test" file="packages/test-runner-junit-reporter/test/fixtures/simple/simple-test.js" line="2">
<testcase name="reports logs to JUnit" time="0.001" classname="logging during a test"/>
<testcase name="fails with source trace" time="<<computed>>" classname="logging during a test" line="2">
<failure message="failed" type="Error"><![CDATA[Error: failed
at fail (packages/test-runner-junit-reporter/test/fixtures/simple/simple-source.js:2:9)
at o.<anonymous> (packages/test-runner-junit-reporter/test/fixtures/simple/simple-test.js:33:17)]]></failure>
</testcase>
</testsuite>
</testsuites>
</testsuites>