Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

chore: reuse test server wire for reporter events (#29640)

Pavel Feldman6b5e273b6d64
diff --git a/packages/playwright/src/runner/loadUtils.ts b/packages/playwright/src/runner/loadUtils.ts
index bd2c45e35f..f6ecccb3d6 100644
--- a/packages/playwright/src/runner/loadUtils.ts
+++ b/packages/playwright/src/runner/loadUtils.ts
@@ -316,8 +316,8 @@ export function loadGlobalHook(config: FullConfigInternal, file: string): Promis
return requireOrImportDefaultFunction(path.resolve(config.config.rootDir, file), false);
}
-export function loadReporter(config: FullConfigInternal, file: string): Promise<new (arg?: any) => Reporter> {
- return requireOrImportDefaultFunction(path.resolve(config.config.rootDir, file), true);
+export function loadReporter(config: FullConfigInternal | undefined, file: string): Promise<new (arg?: any) => Reporter> {
+ return requireOrImportDefaultFunction(config ? path.resolve(config.config.rootDir, file) : file, true);
}
function sourceMapSources(file: string, cache: Map<string, string[]>): string[] {
diff --git a/packages/playwright/src/runner/testServer.ts b/packages/playwright/src/runner/testServer.ts
index 77cfded710..0b93adb7c5 100644
--- a/packages/playwright/src/runner/testServer.ts
+++ b/packages/playwright/src/runner/testServer.ts
@@ -32,6 +32,8 @@ import type { FullConfigInternal } from '../common/config';
import type { TestServerInterface } from './testServerInterface';
import { serializeError } from '../util';
import { prepareErrorStack } from '../reporters/base';
+import { loadReporter } from './loadUtils';
+import { wrapReporterAsV2 } from '../reporters/reporterV2';
export async function runTestServer() {
if (restartWithExperimentalTsEsm(undefined, true))
@@ -117,10 +119,10 @@ class Dispatcher implements TestServerInterface {
reporter: string;
env: NodeJS.ProcessEnv;
}) {
- this._syncEnv(params.env);
const config = await this._loadConfig(params.configFile);
config.cliArgs = params.locations || [];
- const reporter = new InternalReporter(new Multiplexer(await createReporters(config, 'list', [[params.reporter]])));
+ const wireReporter = await this._createReporter(params.reporter);
+ const reporter = new InternalReporter(new Multiplexer([wireReporter]));
const taskRunner = createTaskRunnerForList(config, reporter, 'out-of-process', { failOnLoadErrors: true });
const testRun = new TestRun(config, reporter);
reporter.onConfigure(config.config);
@@ -148,11 +150,9 @@ class Dispatcher implements TestServerInterface {
reuseContext?: boolean;
connectWsEndpoint?: string;
}) {
- this._syncEnv(params.env);
await this._stopTests();
const overrides: ConfigCLIOverrides = {
- additionalReporters: [[params.reporter]],
repeatEach: 1,
retries: 0,
preserveOutputDir: true,
@@ -171,7 +171,9 @@ class Dispatcher implements TestServerInterface {
config.cliGrep = params.grep;
config.cliProjectFilter = params.projects?.length ? params.projects : undefined;
- const reporter = new InternalReporter(new Multiplexer(await createReporters(config, 'run')));
+ const wireReporter = await this._createReporter(params.reporter);
+ const configReporters = await createReporters(config, 'run');
+ const reporter = new InternalReporter(new Multiplexer([...configReporters, wireReporter]));
const taskRunner = createTaskRunnerForTestServer(config, reporter);
const testRun = new TestRun(config, reporter);
reporter.onConfigure(config.config);
@@ -218,9 +220,10 @@ class Dispatcher implements TestServerInterface {
return loadConfig({ resolvedConfigFile: configFile, configDir: path.dirname(configFile) }, overrides);
}
- private _syncEnv(env: NodeJS.ProcessEnv) {
- for (const name in env)
- process.env[name] = env[name];
+ private async _createReporter(file: string) {
+ const reporterConstructor = await loadReporter(undefined, file);
+ const instance = new reporterConstructor((message: any) => this._dispatchEvent('report', message));
+ return wrapReporterAsV2(instance);
}
}
diff --git a/packages/playwright/src/runner/testServerInterface.ts b/packages/playwright/src/runner/testServerInterface.ts
index b1e0464f71..1e844d8123 100644
--- a/packages/playwright/src/runner/testServerInterface.ts
+++ b/packages/playwright/src/runner/testServerInterface.ts
@@ -34,14 +34,12 @@ export interface TestServerInterface {
configFile: string;
locations: string[];
reporter: string;
- env: NodeJS.ProcessEnv;
}): Promise<void>;
test(params: {
configFile: string;
locations: string[];
reporter: string;
- env: NodeJS.ProcessEnv;
headed?: boolean;
oneWorker?: boolean;
trace?: 'on' | 'off';
@@ -64,5 +62,6 @@ export interface TestServerInterface {
}
export interface TestServerEvents {
+ on(event: 'report', listener: (params: any) => void): void;
on(event: 'stdio', listener: (params: { type: 'stdout' | 'stderr', text?: string, buffer?: string }) => void): void;
}