From 7e22e3a19dc31a4db247268f3a4ccac73b4e28d8 Mon Sep 17 00:00:00 2001 From: Yury Semikhatsky Date: Wed, 1 May 2024 09:23:48 -0700 Subject: [PATCH] Do not delete dir --- packages/playwright/src/reporters/base.ts | 5 +++++ tests/playwright-test/reporter-blob.spec.ts | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/packages/playwright/src/reporters/base.ts b/packages/playwright/src/reporters/base.ts index 9635c0cc1be73..0c023e876138b 100644 --- a/packages/playwright/src/reporters/base.ts +++ b/packages/playwright/src/reporters/base.ts @@ -556,6 +556,8 @@ function resolveFromEnv(name: string): string | undefined { return undefined; } +// In addition to `outputFile` the function returns `outputDir` which should +// be cleaned up if present by some reporters contract. export function resolveOutputFile(reporterName: string, options: { configDir: string, outputDir?: string, @@ -572,6 +574,9 @@ export function resolveOutputFile(reporterName: string, options: { outputFile = path.resolve(options.configDir, options.outputFile); if (!outputFile) outputFile = resolveFromEnv(`PLAYWRIGHT_${name}_OUTPUT_FILE`); + // Return early to avoid deleting outputDir. + if (outputFile) + return { outputFile }; let outputDir; if (options.outputDir) diff --git a/tests/playwright-test/reporter-blob.spec.ts b/tests/playwright-test/reporter-blob.spec.ts index 6ed8fdf9e7341..0e5757bd01983 100644 --- a/tests/playwright-test/reporter-blob.spec.ts +++ b/tests/playwright-test/reporter-blob.spec.ts @@ -1292,12 +1292,18 @@ test('support PLAYWRIGHT_BLOB_OUTPUT_FILE environment variable', async ({ runInl test('math 1 @smoke', async ({}) => {}); `, }; + const defaultDir = test.info().outputPath('blob-report'); + fs.mkdirSync(defaultDir, { recursive: true }); + const file = path.join(defaultDir, 'some.file'); + fs.writeFileSync(file, 'content'); await runInlineTest(files, { shard: `1/2` }, { PLAYWRIGHT_BLOB_OUTPUT_FILE: 'subdir/report-one.zip' }); await runInlineTest(files, { shard: `2/2` }, { PLAYWRIGHT_BLOB_OUTPUT_FILE: test.info().outputPath('subdir/report-two.zip') }); const reportDir = test.info().outputPath('subdir'); const reportFiles = await fs.promises.readdir(reportDir); expect(reportFiles.sort()).toEqual(['report-one.zip', 'report-two.zip']); + + expect(fs.existsSync(file), 'Default directory should not be cleaned up if output file is specified.').toBe(true); }); test('keep projects with same name different bot name separate', async ({ runInlineTest, mergeReports, showReport, page }) => {