Skip to content

Commit

Permalink
fix(html): don't conflate file names (#33600)
Browse files Browse the repository at this point in the history
  • Loading branch information
Skn0tt authored Nov 20, 2024
1 parent 50c8fbf commit f1ddd37
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
5 changes: 1 addition & 4 deletions packages/playwright/src/reporters/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,12 +241,9 @@ class HtmlBuilder {
async build(metadata: Metadata, projectSuites: Suite[], result: FullResult, topLevelErrors: TestError[]): Promise<{ ok: boolean, singleTestId: string | undefined }> {
const data = new Map<string, { testFile: TestFile, testFileSummary: TestFileSummary }>();
for (const projectSuite of projectSuites) {
const testDir = projectSuite.project()!.testDir;
for (const fileSuite of projectSuite.suites) {
const fileName = this._relativeLocation(fileSuite.location)!.file;
// Preserve file ids computed off the testDir.
const relativeFile = path.relative(testDir, fileSuite.location!.file);
const fileId = calculateSha1(toPosixPath(relativeFile)).slice(0, 20);
const fileId = calculateSha1(toPosixPath(fileName)).slice(0, 20);
let fileEntry = data.get(fileId);
if (!fileEntry) {
fileEntry = {
Expand Down
27 changes: 27 additions & 0 deletions tests/playwright-test/reporter-html.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2563,6 +2563,33 @@ for (const useIntermediateMergeReport of [true, false] as const) {
await expect(page.locator('#fallback-error')).toContainText('The Playwright Trace Viewer must be loaded over the http:// or https:// protocols.');
await expect(page.locator('#fallback-error')).toContainText(`npx playwright show-report ${reportPath.replace(/\\/g, '\\\\')}`);
});

test('should not collate identical file names in different project directories', async ({ runInlineTest, page }) => {
await runInlineTest({
'playwright.config.ts': `
export default {
projects: [
{ name: 'a', testDir: './tests/a' },
{ name: 'b', testDir: './tests/b' },
],
}
`,
'tests/a/test.spec.ts': `
import { test } from '@playwright/test';
test('passes', ({ page }) => {});
`,
'tests/b/test.spec.ts': `
import { test } from '@playwright/test';
test('passes', ({ page }) => {});
`,
}, { reporter: 'dot,html' }, { PLAYWRIGHT_HTML_OPEN: 'never' });
const reportPath = path.join(test.info().outputPath(), 'playwright-report', 'index.html');
await page.goto(url.pathToFileURL(reportPath).toString());
await expect(page.getByRole('main')).toMatchAriaSnapshot(`
- button "tests/a/test.spec.ts"
- button "tests/b/test.spec.ts"
`);
});
});
}

Expand Down

0 comments on commit f1ddd37

Please sign in to comment.