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

This commit is contained in:
Pavel Feldman 2022-02-01 11:01:52 -08:00 committed by GitHub
parent c2f6462a6b
commit 3a5e8184b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 4 deletions

View File

@ -151,7 +151,13 @@ class RawReporter {
testMatch: serializePatterns(project.testMatch), testMatch: serializePatterns(project.testMatch),
timeout: project.timeout, 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()) { for (const file of this.stepsInFile.keys()) {
let source: string; let source: string;
@ -181,14 +187,13 @@ class RawReporter {
return report; return report;
} }
private _serializeSuite(suite: Suite): JsonSuite { private _serializeSuite(suite: Suite, fileId: string): JsonSuite {
const location = this._relativeLocation(suite.location); const location = this._relativeLocation(suite.location);
const fileId = calculateSha1(location!.file.split(path.sep).join('/'));
return { return {
title: suite.title, title: suite.title,
fileId, fileId,
location, 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)), tests: suite.tests.map(t => this._serializeTest(t, fileId)),
hooks: [], hooks: [],
}; };

View File

@ -461,3 +461,21 @@ test('should group similar / loop steps', async ({ runInlineTest, showReport, pa
/expect\.toEqual.*20/, /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/,
]);
});