diff --git a/packages/playwright/src/common/config.ts b/packages/playwright/src/common/config.ts index 89a983f341..3b950cd25e 100644 --- a/packages/playwright/src/common/config.ts +++ b/packages/playwright/src/common/config.ts @@ -273,7 +273,7 @@ export function toReporters(reporters: BuiltInReporter | ReporterDescription[] | return reporters; } -export const builtInReporters = ['list', 'line', 'dot', 'json', 'junit', 'null', 'github', 'html', 'blob', 'markdown', 'lastrun'] as const; +export const builtInReporters = ['list', 'line', 'dot', 'json', 'junit', 'null', 'github', 'html', 'blob', 'markdown'] as const; export type BuiltInReporter = typeof builtInReporters[number]; export type ContextReuseMode = 'none' | 'when-possible'; diff --git a/packages/playwright/src/runner/reporters.ts b/packages/playwright/src/runner/reporters.ts index d3263480d3..cf0327ac72 100644 --- a/packages/playwright/src/runner/reporters.ts +++ b/packages/playwright/src/runner/reporters.ts @@ -47,7 +47,6 @@ export async function createReporters(config: FullConfigInternal, mode: 'list' | null: EmptyReporter, html: HtmlReporter, markdown: MarkdownReporter, - lastrun: LastRunReporter, }; const reporters: ReporterV2[] = []; descriptions ??= config.config.reporter; @@ -78,6 +77,12 @@ export async function createReporters(config: FullConfigInternal, mode: 'list' | else if (mode !== 'merge') reporters.unshift(!process.env.CI ? new LineReporter({ omitFailures: true }) : new DotReporter()); } + + if (!isTestServer && (mode === 'test' || mode === 'merge')) { + // If we are not in the test server, always add a last-run reporter. + reporters.push(new LastRunReporter(runOptions)); + } + return reporters; } diff --git a/packages/playwright/src/runner/runner.ts b/packages/playwright/src/runner/runner.ts index a1dde653a1..181aea26cc 100644 --- a/packages/playwright/src/runner/runner.ts +++ b/packages/playwright/src/runner/runner.ts @@ -94,9 +94,6 @@ export class Runner { if (modifiedResult && modifiedResult.status) status = modifiedResult.status; - if (!listOnly) - await writeLastRunInfo(testRun, status); - await reporter.onExit(); // Calling process.exit() might truncate large stdout/stderr output. @@ -150,24 +147,6 @@ export type LastRunInfo = { testDurations?: { [testId: string]: number }; }; -async function writeLastRunInfo(testRun: TestRun, status: FullResult['status']) { - const [project] = filterProjects(testRun.config.projects, testRun.config.cliProjectFilter); - if (!project) - return; - const outputDir = project.project.outputDir; - const lastRunReportFile = testRun.config.lastRunFile || path.join(outputDir, '.last-run.json'); - const lastRunReportFileDir = path.dirname(lastRunReportFile); - await fs.promises.mkdir(lastRunReportFileDir, { recursive: true }); - const failedTests = testRun.rootSuite?.allTests().filter(t => !t.ok()).map(t => t.id); - const testDurations = testRun.rootSuite?.allTests().reduce((map, t) => { - if (t.results.length) - map[t.id] = t.results.reduce((a, b) => a + b.duration, 0); - return map; - }, {} as { [testId: string]: number }); - const lastRunReport = JSON.stringify({ status, failedTests, testDurations }, undefined, 2); - await fs.promises.writeFile(lastRunReportFile, lastRunReport); -} - export async function readLastRunInfo(config: FullConfigInternal): Promise { const [project] = filterProjects(config.projects, config.cliProjectFilter); if (!project) diff --git a/tests/playwright-test/reporter-lastrun.spec.ts b/tests/playwright-test/reporter-lastrun.spec.ts index 4560684468..b75522634f 100644 --- a/tests/playwright-test/reporter-lastrun.spec.ts +++ b/tests/playwright-test/reporter-lastrun.spec.ts @@ -37,7 +37,7 @@ const testCases = { }; test('report lastrun info', async ({ runInlineTest }) => { - const result = await runInlineTest(testCases, { reporter: 'lastrun' }); + const result = await runInlineTest(testCases, { }); expect(result.exitCode).toBe(1); const lastRunFilename = test.info().outputPath('.last-run.json'); const lastRun = JSON.parse(await fs.promises.readFile(lastRunFilename, 'utf8')) as LastRunReport; @@ -49,7 +49,7 @@ test('report lastrun info', async ({ runInlineTest }) => { test('keep test-ids consistent when re-run', async ({ runInlineTest }) => { let lastRun: LastRunReport; { - const result = await runInlineTest(testCases, { reporter: 'lastrun' }); + const result = await runInlineTest(testCases, { }); expect(result.exitCode).toBe(1); const lastRunFilename = test.info().outputPath('.last-run.json'); const currentRun = JSON.parse(await fs.promises.readFile(lastRunFilename, 'utf8')) as LastRunReport; @@ -58,7 +58,7 @@ test('keep test-ids consistent when re-run', async ({ runInlineTest }) => { lastRun = currentRun; } { - const result = await runInlineTest(testCases, { reporter: 'lastrun' }); + const result = await runInlineTest(testCases, { }); expect(result.exitCode).toBe(1); const lastRunFilename = test.info().outputPath('.last-run.json'); const currentRun = JSON.parse(await fs.promises.readFile(lastRunFilename, 'utf8')) as LastRunReport; @@ -76,7 +76,6 @@ test('keep test-ids consistent when merging reports', async ({ runInlineTest, me ...testCases, 'playwright.config.ts': `module.exports = { reporter: [ - ['lastrun'], ['blob', { outputDir: 'blob-report' }], ] };`, @@ -103,7 +102,7 @@ test('keep test-ids consistent when merging reports', async ({ runInlineTest, me const reportFiles = await fs.promises.readdir(reportDir); reportFiles.sort(); expect(reportFiles).toEqual(['report-1.zip', 'report-2.zip']); - const result = await mergeReports(reportDir, { 'PLAYWRIGHT_HTML_OPEN': 'never' }, { additionalArgs: ['--reporter', 'lastrun'] }); + const result = await mergeReports(reportDir, { 'PLAYWRIGHT_HTML_OPEN': 'never' }); expect(result.exitCode).toBe(0); const lastRunFilename = test.info().outputPath('.last-run.json'); const lastRun = JSON.parse(await fs.promises.readFile(lastRunFilename, 'utf8')) as LastRunReport; @@ -124,7 +123,7 @@ test('keep existing test-ids when test files are modified', async ({ runInlineTe expect(1 + 1).toBe(2); }); ` - }, { reporter: 'lastrun' }); + }, { }); expect(result.exitCode).toBe(0); const lastRunFilename = test.info().outputPath('.last-run.json'); const lastRun = JSON.parse(await fs.promises.readFile(lastRunFilename, 'utf8')) as LastRunReport; @@ -147,7 +146,7 @@ test('keep existing test-ids when test files are modified', async ({ runInlineTe expect(1 + 1).toBe(2); }); ` - }, { reporter: 'lastrun' }); + }, { }); expect(result.exitCode).toBe(0); const lastRunFilename = test.info().outputPath('.last-run.json'); const lastRun = JSON.parse(await fs.promises.readFile(lastRunFilename, 'utf8')) as LastRunReport; @@ -167,7 +166,7 @@ test('ensure same tests in different files have distinct test-ids', async ({ run expect(1 + 1).toBe(2); }); ` - }, { reporter: 'lastrun' }, {}, { additionalArgs: ['a.test.js'] }); + }, { }, {}, { additionalArgs: ['a.test.js'] }); expect(result.exitCode).toBe(0); const lastRunFilename = test.info().outputPath('.last-run.json'); const lastRun = JSON.parse(await fs.promises.readFile(lastRunFilename, 'utf8')) as LastRunReport; @@ -183,7 +182,7 @@ test('ensure same tests in different files have distinct test-ids', async ({ run expect(1 + 1).toBe(2); }); ` - }, { reporter: 'lastrun' }, {}, { additionalArgs: ['b.test.js'] }); + }, { }, {}, { additionalArgs: ['b.test.js'] }); expect(result.exitCode).toBe(0); const lastRunFilename = test.info().outputPath('.last-run.json'); const lastRun = JSON.parse(await fs.promises.readFile(lastRunFilename, 'utf8')) as LastRunReport;