fix(reporters): improve detection of output folder clashes (#30607)

When comparing `outputDir` and html-reporter `outputFolder`, we now make
sure that both paths end with a forward-slash.

Fixes #28677

---------

Co-authored-by: Georg Unterholzner <georg.unterholzner@dynatrace.com>
This commit is contained in:
georg.dev 2024-05-02 17:32:57 +02:00 committed by GitHub
parent c1fbc753a7
commit 8173cdc485
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 26 additions and 1 deletions

View File

@ -87,7 +87,7 @@ class HtmlReporter extends EmptyReporter {
this._attachmentsBaseURL = attachmentsBaseURL;
const reportedWarnings = new Set<string>();
for (const project of this.config.projects) {
if (outputFolder.startsWith(project.outputDir) || project.outputDir.startsWith(outputFolder)) {
if (this._isSubdirectory(outputFolder, project.outputDir) || this._isSubdirectory(project.outputDir, outputFolder)) {
const key = outputFolder + '|' + project.outputDir;
if (reportedWarnings.has(key))
continue;
@ -113,6 +113,11 @@ class HtmlReporter extends EmptyReporter {
};
}
_isSubdirectory(parentDir: string, dir: string): boolean {
const relativePath = path.relative(parentDir, dir);
return !!relativePath && !relativePath.startsWith('..') && !path.isAbsolute(relativePath);
}
override onError(error: TestError): void {
this._topLevelErrors.push(error);
}

View File

@ -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);