From 0cd273e73507a198ac3c4258e208f68253a19069 Mon Sep 17 00:00:00 2001 From: Georg Unterholzner Date: Tue, 30 Apr 2024 16:47:00 +0200 Subject: [PATCH] fix(reporters): improve detection of output folder clashes When comparing outputDir and html-reporter outputFolder, we now make sure that both paths end with a forward-slash. Fixes #28677 --- packages/playwright/src/reporters/html.ts | 6 +++++- tests/playwright-test/reporter-html.spec.ts | 20 ++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/packages/playwright/src/reporters/html.ts b/packages/playwright/src/reporters/html.ts index 8cad4e0eb21b9..baa5045f607f4 100644 --- a/packages/playwright/src/reporters/html.ts +++ b/packages/playwright/src/reporters/html.ts @@ -87,7 +87,11 @@ class HtmlReporter extends EmptyReporter { this._attachmentsBaseURL = attachmentsBaseURL; const reportedWarnings = new Set(); for (const project of this.config.projects) { - if (outputFolder.startsWith(project.outputDir) || project.outputDir.startsWith(outputFolder)) { + if ( + outputFolder.startsWith(project.outputDir.replace(/\/?$/, '/')) || + project.outputDir.startsWith(outputFolder.replace(/\/?$/, '/')) || + outputFolder === project.outputDir + ) { const key = outputFolder + '|' + project.outputDir; if (reportedWarnings.has(key)) continue; diff --git a/tests/playwright-test/reporter-html.spec.ts b/tests/playwright-test/reporter-html.spec.ts index 0f8505889e39a..beee86eebf79a 100644 --- a/tests/playwright-test/reporter-html.spec.ts +++ b/tests/playwright-test/reporter-html.spec.ts @@ -1094,6 +1094,26 @@ for (const useIntermediateMergeReport of [false] as const) { expect(output).toContain('html-report'); }); + test('it should only identify exact matches as clashing folders', async ({ runInlineTest, useIntermediateMergeReport }) => { + test.skip(useIntermediateMergeReport); + const result = await runInlineTest({ + 'playwright.config.ts': ` + module.exports = { + reporter: [['html', { outputFolder: 'test-results-html' }]] + } + `, + 'a.test.js': ` + import { test, expect } from '@playwright/test'; + test('passes', async ({}) => { + }); + `, + }); + expect(result.exitCode).toBe(0); + const output = result.output; + expect(output).not.toContain('Configuration Error'); + expect(output).toContain('test-results-html'); + }); + test.describe('report location', () => { test('with config should create report relative to config', async ({ runInlineTest, useIntermediateMergeReport }, testInfo) => { test.skip(useIntermediateMergeReport);