Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

fix(html-reporter): open tests from required file (#11784)

Pavel Feldman3a5e8184b58d
diff --git a/packages/playwright-test/src/reporters/raw.ts b/packages/playwright-test/src/reporters/raw.ts
index ab8ca6a633..dad07522c3 100644
--- a/packages/playwright-test/src/reporters/raw.ts
+++ b/packages/playwright-test/src/reporters/raw.ts
@@ -151,7 +151,13 @@ class RawReporter {
testMatch: serializePatterns(project.testMatch),
timeout: project.timeout,
},
- suites: suite.suites.map(s => this._serializeSuite(s))
+ suites: suite.suites.map(fileSuite => {
+ // fileId is based on the location of the enclosing file suite.
+ // Don't use the file in test/suite location, it can be different
+ // due to the source map / require.
+ const fileId = calculateSha1(fileSuite.location!.file.split(path.sep).join('/'));
+ return this._serializeSuite(fileSuite, fileId);
+ })
};
for (const file of this.stepsInFile.keys()) {
let source: string;
@@ -181,14 +187,13 @@ class RawReporter {
return report;
}
- private _serializeSuite(suite: Suite): JsonSuite {
+ private _serializeSuite(suite: Suite, fileId: string): JsonSuite {
const location = this._relativeLocation(suite.location);
- const fileId = calculateSha1(location!.file.split(path.sep).join('/'));
return {
title: suite.title,
fileId,
location,
- suites: suite.suites.map(s => this._serializeSuite(s)),
+ suites: suite.suites.map(s => this._serializeSuite(s, fileId)),
tests: suite.tests.map(t => this._serializeTest(t, fileId)),
hooks: [],
};
diff --git a/tests/playwright-test/reporter-html.spec.ts b/tests/playwright-test/reporter-html.spec.ts
index b88c489097..19e47b1693 100644
--- a/tests/playwright-test/reporter-html.spec.ts
+++ b/tests/playwright-test/reporter-html.spec.ts
@@ -461,3 +461,21 @@ test('should group similar / loop steps', async ({ runInlineTest, showReport, pa
/expect\.toEqual.*20/,
]);
});
+
+test('open tests from required file', async ({ runInlineTest, showReport, page }) => {
+ test.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/11742' });
+ const result = await runInlineTest({
+ 'inner.js': `
+ const { test, expect } = pwt;
+ test('sample', async ({}) => { expect(2).toBe(2); });
+ `,
+ 'a.spec.js': `require('./inner')`
+ }, { 'reporter': 'dot,html' });
+ expect(result.exitCode).toBe(0);
+ await showReport();
+
+ await page.locator('text=sample').first().click();
+ await expect(page.locator('.tree-item-title')).toContainText([
+ /expect\.toBe/,
+ ]);
+});