From fd904241712353dc6767e3a4abf0f4fbb234c62b Mon Sep 17 00:00:00 2001 From: Mathias Leppich Date: Thu, 30 May 2024 08:48:54 +0200 Subject: [PATCH] Feedback use outputLines --- .../playwright-test-fixtures.ts | 14 +++++- tests/playwright-test/reporter-blob.spec.ts | 43 +++++++++---------- 2 files changed, 33 insertions(+), 24 deletions(-) diff --git a/tests/playwright-test/playwright-test-fixtures.ts b/tests/playwright-test/playwright-test-fixtures.ts index 62e20d6945..4f0350cb59 100644 --- a/tests/playwright-test/playwright-test-fixtures.ts +++ b/tests/playwright-test/playwright-test-fixtures.ts @@ -31,6 +31,7 @@ export { countTimes } from '../config/commonFixtures'; type CliRunResult = { exitCode: number, output: string, + outputLines: string[], }; export type RunResult = { @@ -330,7 +331,12 @@ export const test = base cwd, }); const { exitCode } = await testProcess.exited; - return { exitCode, output: testProcess.output.toString() }; + const output = testProcess.output.toString(); + return { + exitCode, + output, + outputLines: parseOutputLines(output), + }; }); }, @@ -416,6 +422,10 @@ export function expectTestHelper(result: RunResult) { }; } +function parseOutputLines(output: string): string[] { + return output.split('\n').filter(line => line.startsWith('%%')).map(line => line.substring(2).trim()); +} + export function parseTestRunnerOutput(output: string) { const summary = (re: RegExp) => { let result = 0; @@ -436,7 +446,7 @@ export function parseTestRunnerOutput(output: string) { const strippedOutput = stripAnsi(output); return { output: strippedOutput, - outputLines: strippedOutput.split('\n').filter(line => line.startsWith('%%')).map(line => line.substring(2).trim()), + outputLines: parseOutputLines(strippedOutput), rawOutput: output, passed, failed, diff --git a/tests/playwright-test/reporter-blob.spec.ts b/tests/playwright-test/reporter-blob.spec.ts index 29928a01f5..4cc9b41886 100644 --- a/tests/playwright-test/reporter-blob.spec.ts +++ b/tests/playwright-test/reporter-blob.spec.ts @@ -32,18 +32,18 @@ const NEGATIVE_STATUS_MARK = DOES_NOT_SUPPORT_UTF8_IN_TERMINAL ? 'x ' : '✘ '; const test = baseTest.extend<{ showReport: (reportFolder?: string) => Promise - }>({ - showReport: async ({ page }, use) => { - let server: HttpServer | undefined; - await use(async (reportFolder?: string) => { - reportFolder ??= test.info().outputPath('playwright-report'); - server = startHtmlReportServer(reportFolder) as HttpServer; - await server.start(); - await page.goto(server.urlPrefix('precise')); - }); - await server?.stop(); - } - }); +}>({ + showReport: async ({ page }, use) => { + let server: HttpServer | undefined; + await use(async (reportFolder?: string) => { + reportFolder ??= test.info().outputPath('playwright-report'); + server = startHtmlReportServer(reportFolder) as HttpServer; + await server.start(); + await page.goto(server.urlPrefix('precise')); + }); + await server?.stop(); + } +}); test.use({ channel: 'chrome' }); test.slow(!!process.env.CI); @@ -1818,7 +1818,7 @@ test('merge reports must not change test ids when there is no need to', async ({ 'echo-test-id-reporter.js': ` export default class EchoTestIdReporter { onTestBegin(test) { - console.log('test.id:', test.id); + console.log('%%' + test.id); } }; `, @@ -1859,28 +1859,27 @@ test('merge reports must not change test ids when there is no need to', async ({ let testIdsFromShard1: string[]; let testIdsFromShard2: string[]; let testIdsFromMergedReport: string[]; - const parseTestIdsFromOutput = (output: string) => output.split('\n').filter(s => s.startsWith('test.id:')).map(s => s.split('test.id:')[1].trim()).sort(); { - const { exitCode, output } = await runInlineTest(files, { workers: 1 }, undefined, { additionalArgs: ['--config', test.info().outputPath('single-run.config.ts')] }); + const { exitCode, outputLines } = await runInlineTest(files, { workers: 1 }, undefined, { additionalArgs: ['--config', test.info().outputPath('single-run.config.ts')] }); expect(exitCode).toBe(0); - testIdsFromSingleRun = parseTestIdsFromOutput(output); + testIdsFromSingleRun = outputLines.sort(); expect(testIdsFromSingleRun.length).toEqual(3); } { - const { exitCode, output } = await runInlineTest(files, { workers: 1 }, {}, { additionalArgs: ['--config', test.info().outputPath('shard-1.config.ts')] }); + const { exitCode, outputLines } = await runInlineTest(files, { workers: 1 }, {}, { additionalArgs: ['--config', test.info().outputPath('shard-1.config.ts')] }); expect(exitCode).toBe(0); - testIdsFromShard1 = parseTestIdsFromOutput(output); + testIdsFromShard1 = outputLines.sort(); } { - const { exitCode, output } = await runInlineTest(files, { workers: 1 }, { PWTEST_BLOB_DO_NOT_REMOVE: '1' }, { additionalArgs: ['--config', test.info().outputPath('shard-2.config.ts')] }); + const { exitCode, outputLines } = await runInlineTest(files, { workers: 1 }, { PWTEST_BLOB_DO_NOT_REMOVE: '1' }, { additionalArgs: ['--config', test.info().outputPath('shard-2.config.ts')] }); expect(exitCode).toBe(0); - testIdsFromShard2 = parseTestIdsFromOutput(output); + testIdsFromShard2 = outputLines.sort(); expect([...testIdsFromShard1, ...testIdsFromShard2].sort()).toEqual(testIdsFromSingleRun); } { - const { exitCode, output } = await mergeReports(test.info().outputPath('blob-report'), undefined, { additionalArgs: ['--config', test.info().outputPath('merge.config.ts')] }); + const { exitCode, outputLines } = await mergeReports(test.info().outputPath('blob-report'), undefined, { additionalArgs: ['--config', test.info().outputPath('merge.config.ts')] }); expect(exitCode).toBe(0); - testIdsFromMergedReport = parseTestIdsFromOutput(output); + testIdsFromMergedReport = outputLines.sort(); expect(testIdsFromMergedReport).toEqual(testIdsFromSingleRun); } });