Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
fix(list mode): keep outputDir intact (#12291)
Dmitry Gozman114edecd3a8f
diff --git a/packages/playwright-test/src/runner.ts b/packages/playwright-test/src/runner.tsindex 5b6546a20d..94e40a0a7e 100644--- a/packages/playwright-test/src/runner.ts+++ b/packages/playwright-test/src/runner.ts@@ -302,12 +302,7 @@ export class Runner {if (!total)fatalErrors.push(createNoTestsError());- // 8. Fail when output fails.- await Promise.all(Array.from(outputDirs).map(outputDir => removeFolderAsync(outputDir).catch(e => {- fatalErrors.push(serializeError(e));- })));-- // 9. Compute shards.+ // 8. Compute shards.let testGroups = createTestGroups(rootSuite);const shard = config.shard;@@ -341,20 +336,27 @@ export class Runner {}(config as any).__testGroupsCount = testGroups.length;- // 10. Report begin+ // 9. Report beginthis._reporter.onBegin?.(config, rootSuite);- // 11. Bail out on errors prior to running global setup.+ // 10. Bail out on errors prior to running global setup.if (fatalErrors.length) {for (const error of fatalErrors)this._reporter.onError?.(error);return { status: 'failed' };}- // 12. Bail out if list mode only, don't do any work.+ // 11. Bail out if list mode only, don't do any work.if (list)return { status: 'passed' };+ // 12. Remove output directores.+ try {+ await Promise.all(Array.from(outputDirs).map(outputDir => removeFolderAsync(outputDir)));+ } catch (e) {+ this._reporter.onError?.(serializeError(e));+ return { status: 'failed' };+ }// 13. Run Global setup.let globalTearDown: (() => Promise<void>) | undefined;diff --git a/tests/playwright-test/list-mode.spec.ts b/tests/playwright-test/list-mode.spec.tsindex b2bbe5098b..c6eaac536d 100644--- a/tests/playwright-test/list-mode.spec.ts+++ b/tests/playwright-test/list-mode.spec.ts@@ -15,6 +15,8 @@*/import { test, expect } from './playwright-test-fixtures';+import path from 'path';+import fs from 'fs';test('should list tests', async ({ runInlineTest }) => {const result = await runInlineTest({@@ -105,3 +107,36 @@ test('globalSetup and globalTeardown should not run', async ({ runInlineTest })`Total: 2 tests in 2 files`,].join('\n'));});++test('outputDir should not be removed', async ({ runInlineTest }, testInfo) => {+ const outputDir = testInfo.outputPath('dummy-output-dir');++ const result1 = await runInlineTest({+ 'playwright.config.ts': `+ module.exports = { outputDir: ${JSON.stringify(outputDir)} };+ `,+ 'a.test.js': `+ const { test } = pwt;+ test('my test', async ({}, testInfo) => {+ console.log(testInfo.outputDir);+ require('fs').writeFileSync(testInfo.outputPath('myfile.txt'), 'hello');+ });+ `,+ }, {}, {}, { usesCustomOutputDir: true });+ expect(result1.exitCode).toBe(0);+ expect(fs.existsSync(path.join(outputDir, 'a-my-test', 'myfile.txt'))).toBe(true);++ const result2 = await runInlineTest({+ 'playwright.config.ts': `+ module.exports = { outputDir: ${JSON.stringify(outputDir)} };+ `,+ 'a.test.js': `+ const { test } = pwt;+ test('my test', async ({}, testInfo) => {+ console.log(testInfo.outputDir);+ });+ `,+ }, { list: true }, {}, { usesCustomOutputDir: true });+ expect(result2.exitCode).toBe(0);+ expect(fs.existsSync(path.join(outputDir, 'a-my-test', 'myfile.txt'))).toBe(true);+});