Skip to content

feat(test-runner-junit-reporter): Add support for flat test files to junit-reporter #2904

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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/rotten-brooms-carry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@web/test-runner-junit-reporter': minor
---

chore: Add support for flat test files to junit reporter
10 changes: 7 additions & 3 deletions packages/test-runner-junit-reporter/src/junitReporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ interface TestSuiteXMLAttributes {
const assignSessionAndSuitePropertiesToTests = ({
testResults,
...rest
}: TestSession): TestResultWithMetadata[] => {
}: TestSession, rootDir: string): TestResultWithMetadata[] => {
const assignToTest =
(parentSuiteName: string) =>
(test: TestResult): TestResultWithMetadata => {
Expand All @@ -87,7 +87,11 @@ const assignSessionAndSuitePropertiesToTests = ({

const suites = testResults?.suites ?? [];

return suites.flatMap(assignToSuite(''));
const testsWithoutSuite = testResults?.tests ?? [];

const suiteName = `${rest.browser.name}_${rest.browser.type}_${rest.testFile.replace(rootDir, '')}`;

return [...suites.flatMap(assignToSuite('')), ...testsWithoutSuite.flatMap(assignToTest(suiteName))];
};

const toResultsWithMetadataByBrowserTestFileName = (
Expand Down Expand Up @@ -291,7 +295,7 @@ function getTestRunXML({
}): string {
const testsuites = Object.entries(
sessions
.flatMap(assignSessionAndSuitePropertiesToTests)
.flatMap(s => assignSessionAndSuitePropertiesToTests(s, rootDir))
.reduce(
toResultsWithMetadataByBrowserTestFileName,
{} as TestResultsWithMetadataByBrowserTestFileName,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
<testsuite name="Chrome_puppeteer_/packages/test-runner-junit-reporter/test/fixtures/flat/flat-test.js" id="0" tests="5" skipped="1" errors="1" failures="1" time="<<computed>>">
<properties>
<property name="test.fileName" value="packages/test-runner-junit-reporter/test/fixtures/flat/flat-test.js"/>
<property name="browser.name" value="Chrome"/>
<property name="browser.launcher" value="puppeteer"/>
</properties>
<testcase name="under addition" time="<<computed>>" classname="Chrome_puppeteer_/packages/test-runner-junit-reporter/test/fixtures/flat/flat-test.js" file="packages/test-runner-junit-reporter/test/fixtures/flat/flat-test.js"/>
<testcase name="null hypothesis" time="<<computed>>" classname="Chrome_puppeteer_/packages/test-runner-junit-reporter/test/fixtures/flat/flat-test.js" file="packages/test-runner-junit-reporter/test/fixtures/flat/flat-test.js"/>
<testcase name="asserts error" time="<<computed>>" classname="Chrome_puppeteer_/packages/test-runner-junit-reporter/test/fixtures/flat/flat-test.js" file="packages/test-runner-junit-reporter/test/fixtures/flat/flat-test.js" line="12">
<failure message="expected false to be true" type="AssertionError"><![CDATA[AssertionError: expected false to be true
at <<anonymous>> (packages/test-runner-junit-reporter/test/fixtures/flat/flat-test.js:12:27)]]></failure>
</testcase>
<testcase name="tbd: confirm true positive" time="<<computed>>" classname="Chrome_puppeteer_/packages/test-runner-junit-reporter/test/fixtures/flat/flat-test.js" file="packages/test-runner-junit-reporter/test/fixtures/flat/flat-test.js">
<skipped/>
</testcase>
<testcase name="reports logs to JUnit" time="<<computed>>" classname="Chrome_puppeteer_/packages/test-runner-junit-reporter/test/fixtures/flat/flat-test.js" file="packages/test-runner-junit-reporter/test/fixtures/flat/flat-test.js"/>
</testsuite>
</testsuites>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import '../../../../../node_modules/chai/chai.js';

it('under addition', function () {
chai.expect(1 + 1).to.equal(2);
});

it('null hypothesis', function () {
chai.expect(true).to.be.true;
});

it('asserts error', function () {
chai.expect(false).to.be.true;
});

it.skip('tbd: confirm true positive', function () {
chai.expect(false).to.be.false;
});

it('reports logs to JUnit', function () {
const actual = '🤷‍♂️';
console.log('actual is ', actual);
chai.expect(typeof actual).to.equal('string');
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
<testsuite name="Chrome_puppeteer_/packages/test-runner-junit-reporter/test/fixtures/multiple/flat-test.js" id="0" tests="5" skipped="1" errors="1" failures="1" time="<<computed>>">
<properties>
<property name="test.fileName" value="packages/test-runner-junit-reporter/test/fixtures/multiple/flat-test.js"/>
<property name="browser.name" value="Chrome"/>
<property name="browser.launcher" value="puppeteer"/>
</properties>
<testcase name="under addition" time="<<computed>>" classname="Chrome_puppeteer_/packages/test-runner-junit-reporter/test/fixtures/multiple/flat-test.js" file="packages/test-runner-junit-reporter/test/fixtures/multiple/flat-test.js"/>
<testcase name="null hypothesis" time="<<computed>>" classname="Chrome_puppeteer_/packages/test-runner-junit-reporter/test/fixtures/multiple/flat-test.js" file="packages/test-runner-junit-reporter/test/fixtures/multiple/flat-test.js"/>
<testcase name="asserts error" time="<<computed>>" classname="Chrome_puppeteer_/packages/test-runner-junit-reporter/test/fixtures/multiple/flat-test.js" file="packages/test-runner-junit-reporter/test/fixtures/multiple/flat-test.js" line="12">
<failure message="expected false to be true" type="AssertionError"><![CDATA[AssertionError: expected false to be true
at <<anonymous>> (packages/test-runner-junit-reporter/test/fixtures/multiple/flat-test.js:12:27)]]></failure>
</testcase>
<testcase name="tbd: confirm true positive" time="<<computed>>" classname="Chrome_puppeteer_/packages/test-runner-junit-reporter/test/fixtures/multiple/flat-test.js" file="packages/test-runner-junit-reporter/test/fixtures/multiple/flat-test.js">
<skipped/>
</testcase>
<testcase name="reports logs to JUnit" time="<<computed>>" classname="Chrome_puppeteer_/packages/test-runner-junit-reporter/test/fixtures/multiple/flat-test.js" file="packages/test-runner-junit-reporter/test/fixtures/multiple/flat-test.js"/>
</testsuite>
<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="<<computed>>">
<properties>
<property name="test.fileName" value="packages/test-runner-junit-reporter/test/fixtures/multiple/nested-test.js"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import '../../../../../node_modules/chai/chai.js';

it('under addition', function () {
chai.expect(1 + 1).to.equal(2);
});

it('null hypothesis', function () {
chai.expect(true).to.be.true;
});

it('asserts error', function () {
chai.expect(false).to.be.true;
});

it.skip('tbd: confirm true positive', function () {
chai.expect(false).to.be.false;
});

it('reports logs to JUnit', function () {
const actual = '🤷‍♂️';
console.log('actual is ', actual);
chai.expect(typeof actual).to.equal('string');
});
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,12 @@ describe('junitReporter', function () {
expect(actual).to.equal(expected);
});
});

describe('for flat test files', function () {
const fixtureDir = path.join(__dirname, 'fixtures/flat');
it('produces expected results', async function () {
const { actual, expected } = await run(fixtureDir);
expect(actual).to.equal(expected);
});
});
});