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
chore: dedup mergeReport fixture (#23762)
Yury Semikhatsky426d6dde0ec6
diff --git a/tests/playwright-test/playwright-test-fixtures.ts b/tests/playwright-test/playwright-test-fixtures.tsindex 45a63463de..32e0143f70 100644--- a/tests/playwright-test/playwright-test-fixtures.ts+++ b/tests/playwright-test/playwright-test-fixtures.ts@@ -85,27 +85,6 @@ export async function writeFiles(testInfo: TestInfo, files: Files, initial: boolexport const cliEntrypoint = path.join(__dirname, '../../packages/playwright-test/cli.js');-const mergeReports = async (childProcess: CommonFixtures['childProcess'], cwd: string, env: NodeJS.ProcessEnv = {}, reporter: string | undefined, configFile: string | undefined) => {- const command = ['node', cliEntrypoint, 'merge-reports'];- if (reporter)- command.push('--reporter', reporter);- if (configFile)- command.push('--config', configFile);- command.push('blob-report');- const testProcess = childProcess({- command,- env: cleanEnv({- PW_TEST_DEBUG_REPORTERS: '1',- PW_TEST_DEBUG_REPORTERS_PRINT_STEPS: '1',- PWTEST_TTY_WIDTH: '80',- ...env- }),- cwd,- });- const { exitCode } = await testProcess.exited;- return { exitCode, output: testProcess.output.toString() };-};-const configFile = (baseDir: string, files: Files): string | undefined => {for (const [name, content] of Object.entries(files)) {if (name.includes('playwright.config')) {@@ -116,7 +95,7 @@ const configFile = (baseDir: string, files: Files): string | undefined => {return undefined;};-async function runPlaywrightTest(childProcess: CommonFixtures['childProcess'], baseDir: string, params: any, env: NodeJS.ProcessEnv, options: RunOptions, files: Files, useIntermediateMergeReport: boolean): Promise<RunResult> {+async function runPlaywrightTest(childProcess: CommonFixtures['childProcess'], baseDir: string, params: any, env: NodeJS.ProcessEnv, options: RunOptions, files: Files, mergeReports: (reportFolder: string, env?: NodeJS.ProcessEnv, options?: RunOptions) => Promise<CliRunResult>, useIntermediateMergeReport: boolean): Promise<RunResult> {let reporter;if (useIntermediateMergeReport) {reporter = params.reporter;@@ -148,7 +127,13 @@ async function runPlaywrightTest(childProcess: CommonFixtures['childProcess'], b}, options.sendSIGINTAfter);if (useIntermediateMergeReport) {- const mergeResult = await mergeReports(childProcess, cwd, env, reporter, configFile(baseDir, files));+ const additionalArgs = [];+ if (reporter)+ additionalArgs.push('--reporter', reporter);+ const config = configFile(baseDir, files);+ if (config)+ additionalArgs.push('--config', config);+ const mergeResult = await mergeReports('blob-report', env, { cwd, additionalArgs });expect(mergeResult.exitCode).toBe(0);output = mergeResult.output;}@@ -290,6 +275,7 @@ type Fixtures = {runListFiles: (files: Files) => Promise<{ output: string, exitCode: number }>;runWatchTest: (files: Files, env?: NodeJS.ProcessEnv, options?: RunOptions) => Promise<TestChildProcess>;runTSC: (files: Files) => Promise<TSCResult>;+ mergeReports: (reportFolder: string, env?: NodeJS.ProcessEnv, options?: RunOptions) => Promise<CliRunResult>useIntermediateMergeReport: boolean;nodeVersion: { major: number, minor: number, patch: number };};@@ -309,11 +295,11 @@ export const test = base});},- runInlineTest: async ({ childProcess, useIntermediateMergeReport }, use, testInfo: TestInfo) => {+ runInlineTest: async ({ childProcess, mergeReports, useIntermediateMergeReport }, use, testInfo: TestInfo) => {const cacheDir = await fs.promises.mkdtemp(path.join(os.tmpdir(), 'playwright-test-cache-'));await use(async (files: Files, params: Params = {}, env: NodeJS.ProcessEnv = {}, options: RunOptions = {}) => {const baseDir = await writeFiles(testInfo, files, true);- return await runPlaywrightTest(childProcess, baseDir, params, { ...env, PWTEST_CACHE_DIR: cacheDir }, options, files, useIntermediateMergeReport);+ return await runPlaywrightTest(childProcess, baseDir, params, { ...env, PWTEST_CACHE_DIR: cacheDir }, options, files, mergeReports, useIntermediateMergeReport);});await removeFolderAsync(cacheDir);},@@ -354,6 +340,28 @@ export const test = base});},+ mergeReports: async ({ childProcess }, use) => {+ await use(async (reportFolder: string, env: NodeJS.ProcessEnv = {}, options: RunOptions = {}) => {+ const command = ['node', cliEntrypoint, 'merge-reports', reportFolder];+ if (options.additionalArgs)+ command.push(...options.additionalArgs);++ const cwd = options.cwd ? path.resolve(test.info().outputDir, options.cwd) : test.info().outputDir;+ const testProcess = childProcess({+ command,+ env: cleanEnv({+ PW_TEST_DEBUG_REPORTERS: '1',+ PW_TEST_DEBUG_REPORTERS_PRINT_STEPS: '1',+ PWTEST_TTY_WIDTH: '80',+ ...env+ }),+ cwd,+ });+ const { exitCode } = await testProcess.exited;+ return { exitCode, output: testProcess.output.toString() };+ });+ },+nodeVersion: async ({}, use) => {const [major, minor, patch] = process.versions.node.split('.');await use({ major: +major, minor: +minor, patch: +patch });diff --git a/tests/playwright-test/reporter-blob.spec.ts b/tests/playwright-test/reporter-blob.spec.tsindex 1ad51d1d3c..bd7a91e623 100644--- a/tests/playwright-test/reporter-blob.spec.ts+++ b/tests/playwright-test/reporter-blob.spec.ts@@ -15,21 +15,19 @@*/import * as fs from 'fs';+import type { PlaywrightTestConfig } from 'packages/playwright-test';import path from 'path';import url from 'url';import type { HttpServer } from '../../packages/playwright-core/src/utils';import { startHtmlReportServer } from '../../packages/playwright-test/lib/reporters/html';-import { type CliRunResult, type RunOptions, stripAnsi } from './playwright-test-fixtures';-import { cleanEnv, cliEntrypoint, expect as baseExpect, test as baseTest } from './playwright-test-fixtures';-import type { PlaywrightTestConfig } from 'packages/playwright-test';+import { expect as baseExpect, test as baseTest, stripAnsi } from './playwright-test-fixtures';const DOES_NOT_SUPPORT_UTF8_IN_TERMINAL = process.platform === 'win32' && process.env.TERM_PROGRAM !== 'vscode' && !process.env.WT_SESSION;const POSITIVE_STATUS_MARK = DOES_NOT_SUPPORT_UTF8_IN_TERMINAL ? 'ok' : '✓ ';const NEGATIVE_STATUS_MARK = DOES_NOT_SUPPORT_UTF8_IN_TERMINAL ? 'x ' : '✘ ';const test = baseTest.extend<{- showReport: (reportFolder?: string) => Promise<void>,- mergeReports: (reportFolder: string, env?: NodeJS.ProcessEnv, options?: RunOptions) => Promise<CliRunResult>+ showReport: (reportFolder?: string) => Promise<void>}>({showReport: async ({ page }, use) => {let server: HttpServer | undefined;@@ -40,22 +38,6 @@ const test = baseTest.extend<{await page.goto(location);});await server?.stop();- },- mergeReports: async ({ childProcess }, use) => {- await use(async (reportFolder: string, env: NodeJS.ProcessEnv = {}, options: RunOptions = {}) => {- const command = ['node', cliEntrypoint, 'merge-reports', reportFolder];- if (options.additionalArgs)- command.push(...options.additionalArgs);-- const cwd = options.cwd ? path.resolve(test.info().outputDir, options.cwd) : test.info().outputDir;- const testProcess = childProcess({- command,- env: cleanEnv(env),- cwd,- });- const { exitCode } = await testProcess.exited;- return { exitCode, output: testProcess.output.toString() };- });}});@@ -379,7 +361,7 @@ test('merge into list report by default', async ({ runInlineTest, mergeReports }const reportFiles = await fs.promises.readdir(reportDir);reportFiles.sort();expect(reportFiles).toEqual([expect.stringMatching(/report-1-of-3.*.zip/), expect.stringMatching(/report-2-of-3.*.zip/), expect.stringMatching(/report-3-of-3.*.zip/), 'resources']);- const { exitCode, output } = await mergeReports(reportDir, { PW_TEST_DEBUG_REPORTERS: '1', PW_TEST_DEBUG_REPORTERS_PRINT_STEPS: '1', PWTEST_TTY_WIDTH: '80' }, { additionalArgs: ['--reporter', 'list'] });+ const { exitCode, output } = await mergeReports(reportDir, undefined, { additionalArgs: ['--reporter', 'list'] });expect(exitCode).toBe(0);const text = stripAnsi(output);@@ -662,7 +644,7 @@ test('multiple output reports', async ({ runInlineTest, mergeReports, showReportconst reportFiles = await fs.promises.readdir(reportDir);reportFiles.sort();expect(reportFiles).toEqual([expect.stringMatching(/report-1-of-2.*.zip/), 'resources']);- const { exitCode, output } = await mergeReports(reportDir, { 'PW_TEST_HTML_REPORT_OPEN': 'never', 'PW_TEST_DEBUG_REPORTERS': '1' }, { additionalArgs: ['--reporter', 'html,line'] });+ const { exitCode, output } = await mergeReports(reportDir, { 'PW_TEST_HTML_REPORT_OPEN': 'never' }, { additionalArgs: ['--reporter', 'html,line'] });expect(exitCode).toBe(0);// Check that line reporter was called.@@ -723,7 +705,7 @@ test('multiple output reports based on config', async ({ runInlineTest, mergeRepconst reportFiles = await fs.promises.readdir(reportDir);reportFiles.sort();expect(reportFiles).toEqual([expect.stringMatching(/report-1-of-2.*.zip/), expect.stringMatching(/report-2-of-2.*.zip/), 'resources']);- const { exitCode, output } = await mergeReports(reportDir, { 'PW_TEST_DEBUG_REPORTERS': '1' }, { additionalArgs: ['--config', test.info().outputPath('merged/playwright.config.ts')] });+ const { exitCode, output } = await mergeReports(reportDir, undefined, { additionalArgs: ['--config', test.info().outputPath('merged/playwright.config.ts')] });expect(exitCode).toBe(0);// Check that line reporter was called.