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: bundle runner, worker, loader (#40130)
Pavel Feldman06742513fe6a
diff --git a/eslint.config.mjs b/eslint.config.mjsindex 1b3179ba81..f699bbcca9 100644--- a/eslint.config.mjs+++ b/eslint.config.mjs@@ -60,7 +60,6 @@ const ignores = ["test-results/","tests/assets/","tests/components/",- "tests/config/ghaMarkdownReporter.ts","tests/installation/fixture-scripts/","tests/third_party/","utils/",diff --git a/packages/playwright/package.json b/packages/playwright/package.jsonindex fef2ad0fff..34a9e71382 100644--- a/packages/playwright/package.json+++ b/packages/playwright/package.json@@ -23,10 +23,7 @@"./lib/fsWatcher": "./lib/fsWatcher.js","./lib/mcp/index": "./lib/mcp/index.js","./lib/program": "./lib/program.js",- "./lib/reporters/base": "./lib/reporters/base.js",- "./lib/reporters/list": "./lib/reporters/list.js",- "./lib/plugins": "./lib/plugins/index.js",- "./lib/runner/testRunner": "./lib/runner/testRunner.js",+ "./lib/runner": "./lib/runner/index.js","./jsx-runtime": {"import": "./jsx-runtime.mjs","require": "./jsx-runtime.js",diff --git a/packages/playwright/src/cli/reportActions.ts b/packages/playwright/src/cli/reportActions.tsindex 845a51a771..7d1e7b94d3 100644--- a/packages/playwright/src/cli/reportActions.ts+++ b/packages/playwright/src/cli/reportActions.ts@@ -19,13 +19,12 @@ import path from 'path';import { gracefullyProcessExitDoNotHang } from '@utils/processLauncher';import { builtInReporters, config as commonConfig, configLoader } from '../common';-import { showHTMLReport } from '../reporters/html';-import { createMergedReport } from '../reporters/merge';+import { html, merge } from '../runner';import type { ReporterDescription } from '../../types/test';export async function showReport(report: string | undefined, host: string, port: number) {- await showHTMLReport(report, host, port);+ await html.showHTMLReport(report, host, port);}export async function mergeReports(reportDir: string | undefined, opts: { [key: string]: any }) {@@ -44,7 +43,7 @@ export async function mergeReports(reportDir: string | undefined, opts: { [key:if (!reporterDescriptions)reporterDescriptions = [[commonConfig.defaultReporter]];const rootDirOverride = configFile ? config.config.rootDir : undefined;- await createMergedReport(config, dir, reporterDescriptions!, rootDirOverride);+ await merge.createMergedReport(config, dir, reporterDescriptions!, rootDirOverride);gracefullyProcessExitDoNotHang(0);}diff --git a/packages/playwright/src/cli/testActions.ts b/packages/playwright/src/cli/testActions.tsindex a1b710a863..25eae98827 100644--- a/packages/playwright/src/cli/testActions.ts+++ b/packages/playwright/src/cli/testActions.ts@@ -21,12 +21,7 @@ import { gracefullyProcessExitDoNotHang } from '@utils/processLauncher';import { startProfiling, stopProfiling } from '@utils/profiler';import { builtInReporters, configLoader, ipc } from '../common';-import { terminalScreen } from '../reporters/base';-import { filterProjects } from '../runner/projectUtils';-import * as testServer from '../runner/testServer';-import { runWatchModeLoop } from '../runner/watchMode';-import { runAllTestsWithConfig, TestRunner } from '../runner/testRunner';-import { createErrorCollectingReporter } from '../runner/reporters';+import { base, projectUtils, testServer, watchMode, testRunner, runnerReporters } from '../runner';import type { ReporterDescription } from '../../types/test';import type { TestRunOptions } from '../runner/tasks';@@ -49,7 +44,7 @@ export async function runTests(args: string[], opts: { [key: string]: any }) {};// Evaluate project filters against config before starting execution. This enables a consistent error message across run modes- filterProjects(config.projects, options.projectFilter);+ projectUtils.filterProjects(config.projects, options.projectFilter);if (opts.ui || opts.uiHost || opts.uiPort) {if (opts.onlyChanged)@@ -74,7 +69,7 @@ export async function runTests(args: string[], opts: { [key: string]: any }) {if (opts.onlyChanged)throw new Error(`--only-changed is not supported in watch mode. If you'd like that to change, file an issue and let us know about your usecase for it.`);- const status = await runWatchModeLoop(+ const status = await watchMode.runWatchModeLoop(configLoader.resolveConfigLocation(opts.config),{projects: opts.project,@@ -88,7 +83,7 @@ export async function runTests(args: string[], opts: { [key: string]: any }) {return;}- const status = await runAllTestsWithConfig(config, options);+ const status = await testRunner.runAllTestsWithConfig(config, options);await stopProfiling('runner');const exitCode = status === 'interrupted' ? 130 : (status === 'passed' ? 0 : 1);gracefullyProcessExitDoNotHang(exitCode);@@ -103,8 +98,8 @@ export async function runTestServerAction(opts: { [key: string]: any }) {}export async function clearCache(opts: { [key: string]: any }) {- const runner = new TestRunner(configLoader.resolveConfigLocation(opts.config), {});- const { status } = await runner.clearCache(createErrorCollectingReporter(terminalScreen));+ const runner = new testRunner.TestRunner(configLoader.resolveConfigLocation(opts.config), {});+ const { status } = await runner.clearCache(runnerReporters.createErrorCollectingReporter(base.terminalScreen));const exitCode = status === 'interrupted' ? 130 : (status === 'passed' ? 0 : 1);gracefullyProcessExitDoNotHang(exitCode);}diff --git a/packages/playwright/src/mcp/test/seed.ts b/packages/playwright/src/mcp/test/seed.tsindex 27680bba24..9381eeef91 100644--- a/packages/playwright/src/mcp/test/seed.ts+++ b/packages/playwright/src/mcp/test/seed.ts@@ -19,13 +19,13 @@ import path from 'path';import { mkdirIfNeeded } from '@utils/fileUtils';-import { collectFilesForProject, findTopLevelProjects } from '../../runner/projectUtils';+import { projectUtils } from '../../runner';import type { config, FullConfigInternal } from '../../common';export function seedProject(fullConfig: FullConfigInternal, projectName?: string) {if (!projectName)- return findTopLevelProjects(fullConfig)[0];+ return projectUtils.findTopLevelProjects(fullConfig)[0];const project = fullConfig.projects.find(p => p.project.name === projectName);if (!project)throw new Error(`Project ${projectName} not found`);@@ -33,7 +33,7 @@ export function seedProject(fullConfig: FullConfigInternal, projectName?: string}export async function findSeedFile(project: config.FullProjectInternal) {- const files = await collectFilesForProject(project);+ const files = await projectUtils.collectFilesForProject(project);return files.find(file => path.basename(file).includes('seed'));}diff --git a/packages/playwright/src/mcp/test/testContext.ts b/packages/playwright/src/mcp/test/testContext.tsindex 6ff5f3fc83..5057e35822 100644--- a/packages/playwright/src/mcp/test/testContext.ts+++ b/packages/playwright/src/mcp/test/testContext.ts@@ -25,17 +25,13 @@ import { ManualPromise } from '@isomorphic/manualPromise';import { escapeRegExp } from '@isomorphic/stringUtils';import { toPosixPath } from '@utils/fileUtils';-import { terminalScreen } from '../../reporters/base';-import ListReporter from '../../reporters/list';+import { base, ListReporter, testRunner } from '../../runner';import { StringWriteStream } from './streams';import { fileExistsAsync } from '../../util';-import { TestRunner, TestRunnerEvent } from '../../runner/testRunner';import { ensureSeedFile, seedProject } from './seed';import { configLoader } from '../../common';import type { ConfigLocation } from '../../common';-import type { TerminalScreen } from '../../reporters/base';-import type { FullResultStatus, RunTestsParams } from '../../runner/testRunner';import type { BrowserMCPRequest, BrowserMCPResponse } from './browserBackend';export type SeedFile = {@@ -80,8 +76,8 @@ ${step.code}}type TestRunnerAndScreen = {- testRunner: TestRunner;- screen: TerminalScreen;+ testRunner: testRunner.TestRunner;+ screen: base.TerminalScreen;claimStdio: () => void;releaseStdio: () => void;output: string[];@@ -109,7 +105,7 @@ export class TestContext {this.computedHeaded = !process.env.CI && !(os.platform() === 'linux' && !process.env.DISPLAY);}- existingTestRunner(): TestRunner | undefined {+ existingTestRunner(): testRunner.TestRunner | undefined {return this._testRunnerAndScreen?.testRunner;}@@ -129,17 +125,17 @@ export class TestContext {async createTestRunner() {await this._cleanupTestRunner();- const testRunner = new TestRunner(this._configLocation, {});- await testRunner.initialize({});+ const runner = new testRunner.TestRunner(this._configLocation, {});+ await runner.initialize({});const testPaused = new ManualPromise<void>();const testRunnerAndScreen: TestRunnerAndScreen = {...createScreen(),- testRunner,+ testRunner: runner,waitForTestPaused: () => testPaused,};this._testRunnerAndScreen = testRunnerAndScreen;- testRunner.on(TestRunnerEvent.TestPaused, params => {+ runner.on(testRunner.TestRunnerEvent.TestPaused, params => {testRunnerAndScreen.sendMessageToPausedTest = params.sendMessage;testPaused.resolve();});@@ -148,8 +144,8 @@ export class TestContext {async getOrCreateSeedFile(seedFile: string | undefined, projectName: string | undefined) {const configDir = this._configLocation.configDir;- const { testRunner } = await this.createTestRunner();- const config = await testRunner.loadConfig();+ const { testRunner: runner } = await this.createTestRunner();+ const config = await runner.loadConfig();const project = seedProject(config, projectName);if (!seedFile) {@@ -180,7 +176,7 @@ export class TestContext {};}- async runSeedTest(seedFile: string, projectName: string): Promise<{ output: string, status: FullResultStatus | 'paused' }> {+ async runSeedTest(seedFile: string, projectName: string): Promise<{ output: string, status: testRunner.FullResultStatus | 'paused' }> {const result = await this.runTestsWithGlobalSetupAndPossiblePause({headed: this.computedHeaded,locations: ['/' + escapeRegExp(seedFile) + '/'],@@ -198,27 +194,27 @@ export class TestContext {return result;}- async runTestsWithGlobalSetupAndPossiblePause(params: RunTestsParams): Promise<{ output: string, status: FullResultStatus | 'paused' }> {+ async runTestsWithGlobalSetupAndPossiblePause(params: testRunner.RunTestsParams): Promise<{ output: string, status: testRunner.FullResultStatus | 'paused' }> {const configDir = this._configLocation.configDir;const testRunnerAndScreen = await this.createTestRunner();- const { testRunner, screen, claimStdio, releaseStdio } = testRunnerAndScreen;+ const { testRunner: runner, screen, claimStdio, releaseStdio } = testRunnerAndScreen;claimStdio();try {const setupReporter = new MCPListReporter({ configDir, screen, includeTestId: true });- const { status } = await testRunner.runGlobalSetup([setupReporter]);+ const { status } = await runner.runGlobalSetup([setupReporter]);if (status !== 'passed')return { output: testRunnerAndScreen.output.join('\n'), status };} finally {releaseStdio();}- let status: FullResultStatus | 'paused' = 'passed';+ let status: testRunner.FullResultStatus | 'paused' = 'passed';const cleanup = async () => {claimStdio();try {- const result = await testRunner.runGlobalTeardown();+ const result = await runner.runGlobalTeardown();if (status === 'passed')status = result.status;} finally {@@ -229,7 +225,7 @@ export class TestContext {try {const reporter = new MCPListReporter({ configDir, screen, includeTestId: true });status = await Promise.race([- testRunner.runTests(reporter, params).then(result => result.status),+ runner.runTests(reporter, params).then(result => result.status),testRunnerAndScreen.waitForTestPaused().then(() => 'paused' as const),]);@@ -277,7 +273,7 @@ export function createScreen() {const stderr = new StringWriteStream(output, 'stderr');const screen = {- ...terminalScreen,+ ...base.terminalScreen,isTTY: false,colors: noColors,stdout: stdout as unknown as NodeJS.WriteStream,diff --git a/packages/playwright/src/mcp/test/testTools.ts b/packages/playwright/src/mcp/test/testTools.tsindex 4774353006..7109c601f4 100644--- a/packages/playwright/src/mcp/test/testTools.ts+++ b/packages/playwright/src/mcp/test/testTools.ts@@ -15,7 +15,7 @@*/import * as z from 'zod';-import ListModeReporter from '../../reporters/listModeReporter';+import { ListModeReporter } from '../../runner';import { defineTestTool } from './testTool';export const listTests = defineTestTool({diff --git a/packages/playwright/src/reporters/markdown.ts b/packages/playwright/src/reporters/markdown.tsdeleted file mode 100644index 23bc643b1a..0000000000--- a/packages/playwright/src/reporters/markdown.ts+++ /dev/null@@ -1,147 +0,0 @@-/**- * Copyright (c) Microsoft Corporation.- *- * Licensed under the Apache License, Version 2.0 (the "License");- * you may not use this file except in compliance with the License.- * You may obtain a copy of the License at- *- * http://www.apache.org/licenses/LICENSE-2.0- *- * Unless required by applicable law or agreed to in writing, software- * distributed under the License is distributed on an "AS IS" BASIS,- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.- * See the License for the specific language governing permissions and- * limitations under the License.- */--import fs from 'fs';-import path from 'path';--import type { FullConfig, FullResult, Reporter, Suite, TestCase, TestError } from '@playwright/test/reporter';--type MarkdownReporterOptions = {- configDir: string, // TODO: make it public?- outputFile?: string;-};--class MarkdownReporter implements Reporter {- private _options: MarkdownReporterOptions;- private _fatalErrors: TestError[] = [];- protected _config!: FullConfig;- private _suite!: Suite;-- constructor(options: MarkdownReporterOptions) {- this._options = options;- }-- printsToStdio() {- return false;- }-- onBegin(config: FullConfig, suite: Suite) {- this._config = config;- this._suite = suite;- }-- onError(error: TestError) {- this._fatalErrors.push(error);- }-- async onEnd(result: FullResult) {- const summary = this._generateSummary();- const lines: string[] = [];- if (this._fatalErrors.length)- lines.push(`**${this._fatalErrors.length} fatal errors, not part of any test**`);- if (summary.unexpected.length) {- lines.push(`**${summary.unexpected.length} failed**`);- this._printTestList(':x:', summary.unexpected, lines);- }- if (summary.flaky.length) {- lines.push(`<details>`);- lines.push(`<summary><b>${summary.flaky.length} flaky</b></summary>`);- this._printTestList(':warning:', summary.flaky, lines, ' <br/>');- lines.push(`</details>`);- lines.push(``);- }- if (summary.interrupted.length) {- lines.push(`<details>`);- lines.push(`<summary><b>${summary.interrupted.length} interrupted</b></summary>`);- this._printTestList(':warning:', summary.interrupted, lines, ' <br/>');- lines.push(`</details>`);- lines.push(``);- }- const skipped = summary.skipped ? `, ${summary.skipped} skipped` : '';- const didNotRun = summary.didNotRun ? `, ${summary.didNotRun} did not run` : '';- lines.push(`**${summary.expected} passed${skipped}${didNotRun}**`);- lines.push(``);-- await this.publishReport(lines.join('\n'));- }-- protected async publishReport(report: string): Promise<void> {- const maybeRelativeFile = this._options.outputFile || 'report.md';- const reportFile = path.resolve(this._options.configDir, maybeRelativeFile);- await fs.promises.mkdir(path.dirname(reportFile), { recursive: true });- await fs.promises.writeFile(reportFile, report);- }-- protected _generateSummary() {- let didNotRun = 0;- let skipped = 0;- let expected = 0;- const interrupted: TestCase[] = [];- const interruptedToPrint: TestCase[] = [];- const unexpected: TestCase[] = [];- const flaky: TestCase[] = [];-- this._suite.allTests().forEach(test => {- switch (test.outcome()) {- case 'skipped': {- if (test.results.some(result => result.status === 'interrupted')) {- if (test.results.some(result => !!result.error))- interruptedToPrint.push(test);- interrupted.push(test);- } else if (!test.results.length || test.expectedStatus !== 'skipped') {- ++didNotRun;- } else {- ++skipped;- }- break;- }- case 'expected': ++expected; break;- case 'unexpected': unexpected.push(test); break;- case 'flaky': flaky.push(test); break;- }- });-- return {- didNotRun,- skipped,- expected,- interrupted,- unexpected,- flaky,- };- }-- private _printTestList(prefix: string, tests: TestCase[], lines: string[], suffix?: string) {- for (const test of tests)- lines.push(`${prefix} ${formatTestTitle(this._config.rootDir, test)}${suffix || ''}`);- lines.push(``);- }-}--function formatTestTitle(rootDir: string, test: TestCase): string {- // root, project, file, ...describes, test- const [, projectName, , ...titles] = test.titlePath();- const relativeTestPath = path.relative(rootDir, test.location.file);- // intentionally leave out column to prevent writing test.spec.ts:100:5 - GitHub turns that into 💯- const location = `${relativeTestPath}:${test.location.line}`;- const projectTitle = projectName ? `[${projectName}] › ` : '';- const testTitle = `${projectTitle}${location} › ${titles.join(' › ')}`;- const extraTags = test.tags.filter(t => !testTitle.includes(t));- const formattedTags = extraTags.map(t => `\`${t}\``).join(' ');- return `${testTitle}${extraTags.length ? ' ' + formattedTags : ''}`;-}--export default MarkdownReporter;diff --git a/packages/playwright/src/runner/index.ts b/packages/playwright/src/runner/index.tsnew file mode 100644index 0000000000..deca5ea337--- /dev/null+++ b/packages/playwright/src/runner/index.ts@@ -0,0 +1,38 @@+/**+ * Copyright (c) Microsoft Corporation.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++// Public surface of the bundled runner/ + reporters/ + plugins/ module.+// Only modules consumed from outside these three directories are+// re-exported here. Files inside the bundle keep using direct relative+// imports.++export * as testRunner from './testRunner';+export * as testServer from './testServer';+export * as watchMode from './watchMode';+export * as projectUtils from './projectUtils';+export * as runnerReporters from './reporters';+export * as base from '../reporters/base';+export * as html from '../reporters/html';+export * as merge from '../reporters/merge';+export { default as ListReporter } from '../reporters/list';+export { default as ListModeReporter } from '../reporters/listModeReporter';+export type { ReporterV2 } from '../reporters/reporterV2';++// Public re-export of TestServerConnection used by external test fixtures.+export { TestServerConnection } from '../isomorphic/testServerConnection';++// Public re-export of webServer plugin used by test fixtures.+export { webServer } from '../plugins/webServerPlugin';diff --git a/packages/playwright/src/runner/reporters.ts b/packages/playwright/src/runner/reporters.tsindex 7c68f86da9..253dbd4648 100644--- a/packages/playwright/src/runner/reporters.ts+++ b/packages/playwright/src/runner/reporters.ts@@ -65,8 +65,13 @@ export async function createReporters(config: FullConfigInternal, mode: 'list' |}}if (process.env.PW_TEST_REPORTER) {- const reporterConstructor = await loadReporter(config, process.env.PW_TEST_REPORTER);- reporters.push(wrapReporterAsV2(new reporterConstructor(reportOptions)));+ const name = process.env.PW_TEST_REPORTER;+ if (name in defaultReporters) {+ reporters.push(new defaultReporters[name as keyof typeof defaultReporters](reportOptions));+ } else {+ const reporterConstructor = await loadReporter(config, name);+ reporters.push(wrapReporterAsV2(new reporterConstructor(reportOptions)));+ }}const someReporterPrintsToStdio = reporters.some(r => r.printsToStdio ? r.printsToStdio() : true);@@ -81,13 +86,6 @@ export async function createReporters(config: FullConfigInternal, mode: 'list' |return reporters;}-export async function createReporterForTestServer(file: string, messageSink: (message: any) => void): Promise<ReporterV2> {- const reporterConstructor = await loadReporter(null, file);- return wrapReporterAsV2(new reporterConstructor({- _send: messageSink,- }));-}-interface ErrorCollectingReporter extends ReporterV2 {errors(): TestError[];}diff --git a/packages/playwright/src/runner/testServer.ts b/packages/playwright/src/runner/testServer.tsindex 75b23542a1..8e74453ff6 100644--- a/packages/playwright/src/runner/testServer.ts+++ b/packages/playwright/src/runner/testServer.ts@@ -26,9 +26,11 @@ import { gracefullyProcessExitDoNotHang } from '@utils/processLauncher';import { configLoader, ipc } from '../common';import ListReporter from '../reporters/list';-import { createReporterForTestServer } from './reporters';import { SigIntWatcher } from './sigIntWatcher';import { TestRunner, TestRunnerEvent } from './testRunner';+import UIModeReporter from './uiModeReporter';+import { loadReporter } from './loadUtils';+import { wrapReporterAsV2 } from '../reporters/reporterV2';import type { Transport } from '@utils/httpServer';import type * as reporterTypes from '../../types/testReporter';@@ -93,7 +95,7 @@ export type RunTestsParams = {export class TestServerDispatcher implements TestServerInterface {readonly transport: Transport;- private _serializer = require.resolve('./uiModeReporter');+ private _serializer: string | undefined;private _closeOnDisconnect = false;private _testRunner: TestRunner;private _globalSetupReport: ReportEntry[] | undefined;@@ -129,7 +131,7 @@ export class TestServerDispatcher implements TestServerInterface {async initialize(params: Parameters<TestServerInterface['initialize']>[0]): ReturnType<TestServerInterface['initialize']> {// Note: this method can be called multiple times, for example from a new connection after UI mode reload.- this._serializer = params.serializer || require.resolve('./uiModeReporter');+ this._serializer = params.serializer;this._closeOnDisconnect = !!params.closeOnDisconnect;await this._testRunner.initialize({...params,@@ -328,3 +330,10 @@ function chunkToPayload(type: 'stdout' | 'stderr', chunk: Buffer | string): Stdireturn { type, buffer: chunk.toString('base64') };return { type, text: chunk };}++async function createReporterForTestServer(file: string | undefined, messageSink: (message: any) => void): Promise<ReporterV2> {+ const reporterConstructor = file ? await loadReporter(null, file) : UIModeReporter;+ return wrapReporterAsV2(new reporterConstructor({+ _send: messageSink,+ }));+}diff --git a/tests/config/ghaMarkdownReporter.ts b/tests/config/ghaMarkdownReporter.tsindex e90151c714..fdd223b543 100644--- a/tests/config/ghaMarkdownReporter.ts+++ b/tests/config/ghaMarkdownReporter.ts@@ -14,10 +14,137 @@* limitations under the License.*/-import MarkdownReporter from '../../packages/playwright/src/reporters/markdown';+import fs from 'fs';+import path from 'path';import type { MetadataWithCommitInfo } from '@testIsomorphic/types';import type { IssueCommentEdge, Repository } from '@octokit/graphql-schema';+import type { FullConfig, FullResult, Reporter, Suite, TestCase } from '@playwright/test/reporter';++type MarkdownReporterOptions = {+ configDir: string, // TODO: make it public?+ outputFile?: string;+};++class MarkdownReporter implements Reporter {+ private _options: MarkdownReporterOptions;+ private _fatalErrors: TestError[] = [];+ protected _config!: FullConfig;+ private _suite!: Suite;++ constructor(options: MarkdownReporterOptions) {+ this._options = options;+ }++ printsToStdio() {+ return false;+ }++ onBegin(config: FullConfig, suite: Suite) {+ this._config = config;+ this._suite = suite;+ }++ onError(error: TestError) {+ this._fatalErrors.push(error);+ }++ async onEnd(result: FullResult) {+ const summary = this._generateSummary();+ const lines: string[] = [];+ if (this._fatalErrors.length)+ lines.push(`**${this._fatalErrors.length} fatal errors, not part of any test**`);+ if (summary.unexpected.length) {+ lines.push(`**${summary.unexpected.length} failed**`);+ this._printTestList(':x:', summary.unexpected, lines);+ }+ if (summary.flaky.length) {+ lines.push(`<details>`);+ lines.push(`<summary><b>${summary.flaky.length} flaky</b></summary>`);+ this._printTestList(':warning:', summary.flaky, lines, ' <br/>');+ lines.push(`</details>`);+ lines.push(``);+ }+ if (summary.interrupted.length) {+ lines.push(`<details>`);+ lines.push(`<summary><b>${summary.interrupted.length} interrupted</b></summary>`);+ this._printTestList(':warning:', summary.interrupted, lines, ' <br/>');+ lines.push(`</details>`);+ lines.push(``);+ }+ const skipped = summary.skipped ? `, ${summary.skipped} skipped` : '';+ const didNotRun = summary.didNotRun ? `, ${summary.didNotRun} did not run` : '';+ lines.push(`**${summary.expected} passed${skipped}${didNotRun}**`);+ lines.push(``);++ await this.publishReport(lines.join('\n'));+ }++ protected async publishReport(report: string): Promise<void> {+ const maybeRelativeFile = this._options.outputFile || 'report.md';+ const reportFile = path.resolve(this._options.configDir, maybeRelativeFile);+ await fs.promises.mkdir(path.dirname(reportFile), { recursive: true });+ await fs.promises.writeFile(reportFile, report);+ }++ protected _generateSummary() {+ let didNotRun = 0;+ let skipped = 0;+ let expected = 0;+ const interrupted: TestCase[] = [];+ const interruptedToPrint: TestCase[] = [];+ const unexpected: TestCase[] = [];+ const flaky: TestCase[] = [];++ this._suite.allTests().forEach(test => {+ switch (test.outcome()) {+ case 'skipped': {+ if (test.results.some(result => result.status === 'interrupted')) {+ if (test.results.some(result => !!result.error))+ interruptedToPrint.push(test);+ interrupted.push(test);+ } else if (!test.results.length || test.expectedStatus !== 'skipped') {+ ++didNotRun;+ } else {+ ++skipped;+ }+ break;+ }+ case 'expected': ++expected; break;+ case 'unexpected': unexpected.push(test); break;+ case 'flaky': flaky.push(test); break;+ }+ });++ return {+ didNotRun,+ skipped,+ expected,+ interrupted,+ unexpected,+ flaky,+ };+ }++ private _printTestList(prefix: string, tests: TestCase[], lines: string[], suffix?: string) {+ for (const test of tests)+ lines.push(`${prefix} ${formatTestTitle(this._config.rootDir, test)}${suffix || ''}`);+ lines.push(``);+ }+}++function formatTestTitle(rootDir: string, test: TestCase): string {+ // root, project, file, ...describes, test+ const [, projectName, , ...titles] = test.titlePath();+ const relativeTestPath = path.relative(rootDir, test.location.file);+ // intentionally leave out column to prevent writing test.spec.ts:100:5 - GitHub turns that into 💯+ const location = `${relativeTestPath}:${test.location.line}`;+ const projectTitle = projectName ? `[${projectName}] › ` : '';+ const testTitle = `${projectTitle}${location} › ${titles.join(' › ')}`;+ const extraTags = test.tags.filter(t => !testTitle.includes(t));+ const formattedTags = extraTags.map(t => `\`${t}\``).join(' ');+ return `${testTitle}${extraTags.length ? ' ' + formattedTags : ''}`;+}class GHAMarkdownReporter extends MarkdownReporter {private octokit: ReturnType<typeof import('@actions/github').getOctokit>;diff --git a/tests/playwright-test/basic.spec.ts b/tests/playwright-test/basic.spec.tsindex 73ce104ba0..13959c2765 100644--- a/tests/playwright-test/basic.spec.ts+++ b/tests/playwright-test/basic.spec.ts@@ -63,7 +63,7 @@ test('should succeed', async ({ runInlineTest }) => {test('should report suite errors', async ({ runInlineTest }) => {const { exitCode, failed, output } = await runInlineTest({'suite-error.spec.ts': `- if (new Error().stack.includes('workerMain'))+ if (new Error().stack.includes('workerProcess'))throw new Error('Suite error');import { test, expect } from '@playwright/test';diff --git a/tests/playwright-test/fit-to-width.spec.ts b/tests/playwright-test/fit-to-width.spec.tsindex bf7a2aa4d0..9aa6125fd1 100644--- a/tests/playwright-test/fit-to-width.spec.ts+++ b/tests/playwright-test/fit-to-width.spec.ts@@ -14,7 +14,8 @@* limitations under the License.*/-import { fitToWidth } from '../../packages/playwright/lib/reporters/base';+import { base } from '../../packages/playwright/lib/runner';+const { fitToWidth } = base;import { test, expect } from './playwright-test-fixtures';test('chinese characters', () => {diff --git a/tests/playwright-test/playwright-test-fixtures.ts b/tests/playwright-test/playwright-test-fixtures.tsindex f2e6826ec7..9668eaf37b 100644--- a/tests/playwright-test/playwright-test-fixtures.ts+++ b/tests/playwright-test/playwright-test-fixtures.ts@@ -147,7 +147,7 @@ async function runPlaywrightTest(childProcess: CommonFixtures['childProcess'], bconst reportFile = path.join(baseDir, 'report.json');// When we have useIntermediateMergeReport, we want the JSON reporter only at the merge step.const envWithJsonReporter = {- PW_TEST_REPORTER: path.join(__dirname, '../../packages/playwright/lib/reporters/json.js'),+ PW_TEST_REPORTER: 'json',PLAYWRIGHT_JSON_OUTPUT_NAME: reportFile,...env,};diff --git a/tests/playwright-test/reporter-blob.spec.ts b/tests/playwright-test/reporter-blob.spec.tsindex 19135feaf6..fbc3c8f9d1 100644--- a/tests/playwright-test/reporter-blob.spec.ts+++ b/tests/playwright-test/reporter-blob.spec.ts@@ -17,7 +17,8 @@import * as fs from 'fs';import type { PlaywrightTestConfig } from '@playwright/test';import path from 'path';-import { startHtmlReportServer } from '../../packages/playwright/lib/reporters/html';+import { html } from '../../packages/playwright/lib/runner';+const { startHtmlReportServer } = html;import { expect as baseExpect, test as baseTest, stripAnsi } from './playwright-test-fixtures';import extractZip from '../../packages/playwright-core/bundles/utils/src/third_party/extract-zip';import * as yazl from '../../packages/playwright-core/bundles/utils/node_modules/yazl';diff --git a/tests/playwright-test/reporter-html.spec.ts b/tests/playwright-test/reporter-html.spec.tsindex 0f614ab37d..951d3d826e 100644--- a/tests/playwright-test/reporter-html.spec.ts+++ b/tests/playwright-test/reporter-html.spec.ts@@ -18,7 +18,8 @@ import fs from 'fs';import path from 'path';import url from 'url';import { test as baseTest, expect as baseExpect, createImage } from './playwright-test-fixtures';-import { startHtmlReportServer } from '../../packages/playwright/lib/reporters/html';+import { html } from '../../packages/playwright/lib/runner';+const { startHtmlReportServer } = html;import { iso, utils } from '../../packages/playwright-core/lib/coreBundle';type HttpServer = utils.HttpServer;diff --git a/tests/playwright-test/reporter-markdown.spec.ts b/tests/playwright-test/reporter-markdown.spec.tsdeleted file mode 100644index 9b6ebf9556..0000000000--- a/tests/playwright-test/reporter-markdown.spec.ts+++ /dev/null@@ -1,205 +0,0 @@-/**- * Copyright (c) Microsoft Corporation.- *- * Licensed under the Apache License, Version 2.0 (the "License");- * you may not use this file except in compliance with the License.- * You may obtain a copy of the License at- *- * http://www.apache.org/licenses/LICENSE-2.0- *- * Unless required by applicable law or agreed to in writing, software- * distributed under the License is distributed on an "AS IS" BASIS,- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.- * See the License for the specific language governing permissions and- * limitations under the License.- */--import fs from 'fs';-import path from 'path';-import { expect, test } from './playwright-test-fixtures';--const markdownReporter = require.resolve('../../packages/playwright/lib/reporters/markdown');--test('simple report', async ({ runInlineTest }) => {- const files = {- 'playwright.config.ts': `- module.exports = {- retries: 1,- reporter: ${JSON.stringify(markdownReporter)},- };- `,- 'dir1/a.test.js': `- import { test, expect } from '@playwright/test';- test('math 1', async ({}) => {- expect(1 + 1).toBe(2);- });- test('failing 1', async ({}) => {- expect(1).toBe(2);- });- test('flaky 1', async ({}) => {- expect(test.info().retry).toBe(1);- });- test.skip('skipped 1', async ({}) => {});- `,- 'dir2/b.test.js': `- import { test, expect } from '@playwright/test';- test('math 2', async ({}) => {- expect(1 + 1).toBe(2);- });- test('failing 2', async ({}) => {- expect(1).toBe(2);- });- test.skip('skipped 2', async ({}) => {});- `,- 'c.test.js': `- import { test, expect } from '@playwright/test';- test('math 3', async ({}) => {- expect(1 + 1).toBe(2);- });- test('flaky 2', async ({}) => {- expect(test.info().retry).toBe(1);- });- test.skip('skipped 3', async ({}) => {});- `- };- const { exitCode } = await runInlineTest(files);- expect(exitCode).toBe(1);- const reportFile = await fs.promises.readFile(test.info().outputPath('report.md'));- expect(reportFile.toString()).toContain(`**2 failed**-:x: dir1${path.sep}a.test.js:6 › failing 1-:x: dir2${path.sep}b.test.js:6 › failing 2--<details>-<summary><b>2 flaky</b></summary>-:warning: c.test.js:6 › flaky 2 <br/>-:warning: dir1${path.sep}a.test.js:9 › flaky 1 <br/>--</details>--**3 passed, 3 skipped**-`);-});--test('custom report file', async ({ runInlineTest }) => {- const files = {- 'playwright.config.ts': `- module.exports = {- reporter: [[${JSON.stringify(markdownReporter)}, { outputFile: 'my-report.md' }]],- };- `,- 'a.test.js': `- import { test, expect } from '@playwright/test';- test('math 1', async ({}) => {- expect(1 + 1).toBe(2);- });- `,- };-- const { exitCode } = await runInlineTest(files);- expect(exitCode).toBe(0);- const reportFile = await fs.promises.readFile(test.info().outputPath('my-report.md'));- expect(reportFile.toString()).toBe(`**1 passed**-`);-});--test('report error without snippet', async ({ runInlineTest }) => {- const files = {- 'playwright.config.ts': `- module.exports = {- retries: 1,- reporter: ${JSON.stringify(markdownReporter)},- };- `,- 'a.test.js': `- import { test, expect } from '@playwright/test';- test('math 1', async ({}) => {- const e = new Error('My error');- e.stack = null;- throw e;- });- `,- };-- await runInlineTest(files);- const reportFile = await fs.promises.readFile(test.info().outputPath('report.md'));- expect(reportFile.toString()).toContain(`**1 failed**-:x: a.test.js:3 › math 1--**0 passed**-`);-});--test('report with worker error', async ({ runInlineTest }) => {- const files = {- 'playwright.config.ts': `- module.exports = {- retries: 1,- reporter: ${JSON.stringify(markdownReporter)},- };- `,- 'a.test.js': `- import { test, expect } from '@playwright/test';- throw new Error('My error 1');- `,- 'b.test.js': `- import { test, expect } from '@playwright/test';- throw new Error('My error 2');- `,- };-- const { exitCode } = await runInlineTest(files);- expect(exitCode).toBe(1);- const reportFile = await fs.promises.readFile(test.info().outputPath('report.md'));- expect(reportFile.toString()).toContain(`**3 fatal errors, not part of any test**-**0 passed**-`);-});--test('report with annotations', async ({ runInlineTest }) => {- const files = {- 'playwright.config.ts': `- module.exports = {- retries: 0,- reporter: ${JSON.stringify(markdownReporter)},- };- `,- 'a.test.js': `- import { test, expect } from '@playwright/test';-- test('test login page', {- annotation: {- type: 'issue',- description: 'https://github.com/microsoft/playwright/issues/23180',- },- tag: '@login',- }, async ({ page }) => {- expect(1 + 1).toBe(2);- });-- test('failing test with annotation', {- annotation: [- { type: 'bug', description: 'Known issue' },- { type: 'performance', description: 'slow test' }- ],- tag: '@slow',- }, async ({ page }) => {- expect(1).toBe(2);- });- `,- };-- const { exitCode } = await runInlineTest(files);- expect(exitCode).toBe(1);- const reportFile = await fs.promises.readFile(test.info().outputPath('report.md'));- const reportContent = reportFile.toString();-- // Check that failed tests are reported with tags- expect(reportContent).toContain(`**1 failed**-:x: a.test.js:14 › failing test with annotation \`@slow\``);-- // Check that passed tests are reported (but without individual titles)- expect(reportContent).toContain(`**1 passed**`);-- // Check that tags are included in the failed test output- expect(reportContent).toContain('`@slow`');-});diff --git a/tests/playwright-test/runner.spec.ts b/tests/playwright-test/runner.spec.tsindex 7c43691184..1d91cb9d8d 100644--- a/tests/playwright-test/runner.spec.ts+++ b/tests/playwright-test/runner.spec.ts@@ -140,7 +140,7 @@ test('sigint should stop workers', async ({ interactWithTestRunner }) => {});`,}, { 'workers': 2, 'reporter': 'line,json' }, {- PW_TEST_REPORTER: path.join(__dirname, '../../packages/playwright/lib/reporters/json.js'),+ PW_TEST_REPORTER: 'json',PLAYWRIGHT_JSON_OUTPUT_NAME: 'report.json',});await testProcess.waitForOutput('%%SEND-SIGINT%%', 2);diff --git a/tests/playwright-test/test-server.spec.ts b/tests/playwright-test/test-server.spec.tsindex 17ac351070..8fe901ac69 100644--- a/tests/playwright-test/test-server.spec.ts+++ b/tests/playwright-test/test-server.spec.ts@@ -17,7 +17,7 @@// @ts-nocheckimport { test as baseTest, expect } from './ui-mode-fixtures';-import { TestServerConnection } from '../../packages/playwright/lib/isomorphic/testServerConnection';+import { TestServerConnection } from '../../packages/playwright/lib/runner';import { playwrightCtConfigText } from './playwright-test-fixtures';import ws from 'ws';import type { TestChildProcess } from '../config/commonFixtures';diff --git a/tests/playwright-test/web-server.spec.ts b/tests/playwright-test/web-server.spec.tsindex 608d27bd1a..c171637bad 100644--- a/tests/playwright-test/web-server.spec.ts+++ b/tests/playwright-test/web-server.spec.ts@@ -624,7 +624,7 @@ test.describe('baseURL with plugins', () => {});`,'playwright.config.ts': `- import { webServer } from 'playwright/lib/plugins';+ import { webServer } from 'playwright/lib/runner';module.exports = {_plugins: [webServer({@@ -649,7 +649,7 @@ test.describe('baseURL with plugins', () => {});`,'playwright.config.ts': `- import { webServer } from 'playwright/lib/plugins';+ import { webServer } from 'playwright/lib/runner';module.exports = {webServer: {command: 'node ${JSON.stringify(SIMPLE_SERVER_PATH)} ${port}',diff --git a/tests/tsconfig.json b/tests/tsconfig.jsonindex 2512b062de..2ed521bcea 100644--- a/tests/tsconfig.json+++ b/tests/tsconfig.json@@ -34,5 +34,5 @@"skipLibCheck": true,},"include": ["**/*.spec.js", "**/*.ts"],- "exclude": ["components/", "installation/fixture-scripts/", "packages/playwright-core/lib/", "config/ghaMarkdownReporter.ts"]+ "exclude": ["components/", "installation/fixture-scripts/", "packages/playwright-core/lib/"]}diff --git a/utils/build/build.js b/utils/build/build.jsindex 151bffddaa..ba2f71a2d1 100644--- a/utils/build/build.js+++ b/utils/build/build.js@@ -753,15 +753,7 @@ steps.push(new EsbuildStep({filePath('packages/playwright/src/*.ts'),filePath('packages/playwright/src/agents/**/*.ts'),filePath('packages/playwright/src/cli/**/*.ts'),- filePath('packages/playwright/src/common/**/*.ts'),- filePath('packages/playwright/src/isomorphic/**/*.ts'),- filePath('packages/playwright/src/loader/**/*.ts'),filePath('packages/playwright/src/mcp/**/*.ts'),- filePath('packages/playwright/src/plugins/**/*.ts'),- filePath('packages/playwright/src/reporters/**/*.ts'),- filePath('packages/playwright/src/runner/**/*.ts'),- filePath('packages/playwright/src/transform/**/*.ts'),- filePath('packages/playwright/src/worker/**/*.ts'),],outdir: filePath('packages/playwright/lib'),sourcemap: withSourceMaps ? 'linked' : false,@@ -787,10 +779,7 @@ steps.push(new EsbuildStep({plugins: [dynamicImportToRequirePlugin],}, [filePath('packages/playwright/src')]));-// playwright/lib/common/index.js — bundled common barrel. Inlines all of-// common/* and transform/* (the barrel re-exports both). Externalizes-// sibling lib/ files so state-holding singletons (currentTestInfo, config,-// compilation cache) live exactly once at runtime.+// playwright/lib/common/index.js — bundled common barrel.steps.push(new EsbuildStep({bundle: true,entryPoints: [filePath('packages/playwright/src/common/index.ts')],@@ -809,6 +798,70 @@ steps.push(new EsbuildStep({plugins: [dynamicImportToRequirePlugin],}, [filePath('packages/playwright/src')]));+// playwright/lib/runner/index.js — bundled runner barrel.+steps.push(new EsbuildStep({+ bundle: true,+ entryPoints: [filePath('packages/playwright/src/runner/index.ts')],+ outfile: filePath('packages/playwright/lib/runner/index.js'),+ sourcemap: withSourceMaps ? 'linked' : false,+ platform: 'node',+ format: 'cjs',+ external: [+ 'playwright-core',+ 'playwright-core/*',+ '../common',+ '../globals',+ '../package',+ '../util',+ '../matchers/expect',+ '../loader/loaderProcessEntry.js',+ '../worker/workerProcessEntry.js',+ ],+ plugins: [dynamicImportToRequirePlugin],+}, [filePath('packages/playwright/src')]));++// playwright/lib/loader/loaderProcessEntry.js — bundled loader process+// entry. Output sits at the same depth as the source so '../X' externals+// resolve to lib/X.js naturally.+steps.push(new EsbuildStep({+ bundle: true,+ entryPoints: [filePath('packages/playwright/src/loader/loaderProcessEntry.ts')],+ outfile: filePath('packages/playwright/lib/loader/loaderProcessEntry.js'),+ sourcemap: withSourceMaps ? 'linked' : false,+ platform: 'node',+ format: 'cjs',+ external: [+ 'playwright-core',+ 'playwright-core/*',+ '../common',+ '../globals',+ '../package',+ '../util',+ ],+ plugins: [dynamicImportToRequirePlugin],+}, [filePath('packages/playwright/src')]));++// playwright/lib/worker/workerProcessEntry.js — bundled worker process+// entry. Output sits at the same depth as the source so '../X' externals+// resolve to lib/X.js naturally.+steps.push(new EsbuildStep({+ bundle: true,+ entryPoints: [filePath('packages/playwright/src/worker/workerProcessEntry.ts')],+ outfile: filePath('packages/playwright/lib/worker/workerProcessEntry.js'),+ sourcemap: withSourceMaps ? 'linked' : false,+ platform: 'node',+ format: 'cjs',+ external: [+ 'playwright-core',+ 'playwright-core/*',+ '../common',+ '../globals',+ '../package',+ '../utils',+ ],+ plugins: [dynamicImportToRequirePlugin],+}, [filePath('packages/playwright/src')]));+// Build the Electron preload loader as a standalone CJS file. It runs inside// the Electron process (via `electron -r loader.js`) and must not depend on// coreBundle. `electron` is resolved at runtime by the Electron process.