mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
chore: fix plugin reporting, rearrange steps (#20616)
This commit is contained in:
parent
8b5e55d432
commit
b0b9b08167
@ -121,7 +121,7 @@ export class ConfigLoader {
|
|||||||
this._fullConfig.shard = takeFirst(config.shard, baseFullConfig.shard);
|
this._fullConfig.shard = takeFirst(config.shard, baseFullConfig.shard);
|
||||||
this._fullConfig._internal.ignoreSnapshots = takeFirst(config.ignoreSnapshots, baseFullConfig._internal.ignoreSnapshots);
|
this._fullConfig._internal.ignoreSnapshots = takeFirst(config.ignoreSnapshots, baseFullConfig._internal.ignoreSnapshots);
|
||||||
this._fullConfig.updateSnapshots = takeFirst(config.updateSnapshots, baseFullConfig.updateSnapshots);
|
this._fullConfig.updateSnapshots = takeFirst(config.updateSnapshots, baseFullConfig.updateSnapshots);
|
||||||
this._fullConfig._internal.pluginRegistrations = (config as any)._plugins || [];
|
this._fullConfig._internal.plugins = ((config as any)._plugins || []).map((p: any) => ({ factory: p }));
|
||||||
|
|
||||||
const workers = takeFirst(config.workers, '50%');
|
const workers = takeFirst(config.workers, '50%');
|
||||||
if (typeof workers === 'string') {
|
if (typeof workers === 'string') {
|
||||||
@ -449,7 +449,7 @@ export const baseFullConfig: FullConfigInternal = {
|
|||||||
storeDir: '',
|
storeDir: '',
|
||||||
maxConcurrentTestGroups: 0,
|
maxConcurrentTestGroups: 0,
|
||||||
ignoreSnapshots: false,
|
ignoreSnapshots: false,
|
||||||
pluginRegistrations: [],
|
plugins: [],
|
||||||
testTitleMatcher: () => true,
|
testTitleMatcher: () => true,
|
||||||
testFileFilters: [],
|
testFileFilters: [],
|
||||||
listOnly: false,
|
listOnly: false,
|
||||||
|
|||||||
@ -48,7 +48,7 @@ type ConfigInternal = {
|
|||||||
maxConcurrentTestGroups: number;
|
maxConcurrentTestGroups: number;
|
||||||
ignoreSnapshots: boolean;
|
ignoreSnapshots: boolean;
|
||||||
webServers: Exclude<FullConfigPublic['webServer'], null>[];
|
webServers: Exclude<FullConfigPublic['webServer'], null>[];
|
||||||
pluginRegistrations: TestRunnerPluginRegistration[];
|
plugins: TestRunnerPluginRegistration[];
|
||||||
listOnly: boolean;
|
listOnly: boolean;
|
||||||
testFileFilters: TestFileFilter[];
|
testFileFilters: TestFileFilter[];
|
||||||
testTitleMatcher: Matcher;
|
testTitleMatcher: Matcher;
|
||||||
|
|||||||
@ -24,7 +24,10 @@ export interface TestRunnerPlugin {
|
|||||||
teardown?(): Promise<void>;
|
teardown?(): Promise<void>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type TestRunnerPluginRegistration = TestRunnerPlugin | (() => TestRunnerPlugin | Promise<TestRunnerPlugin>);
|
export type TestRunnerPluginRegistration = {
|
||||||
|
factory: TestRunnerPlugin | (() => TestRunnerPlugin | Promise<TestRunnerPlugin>);
|
||||||
|
instance?: TestRunnerPlugin;
|
||||||
|
};
|
||||||
|
|
||||||
export { webServer } from './webServerPlugin';
|
export { webServer } from './webServerPlugin';
|
||||||
export { gitCommitInfo } from './gitCommitInfoPlugin';
|
export { gitCommitInfo } from './gitCommitInfoPlugin';
|
||||||
|
|||||||
@ -53,9 +53,9 @@ export class Runner {
|
|||||||
const deadline = config.globalTimeout ? monotonicTime() + config.globalTimeout : 0;
|
const deadline = config.globalTimeout ? monotonicTime() + config.globalTimeout : 0;
|
||||||
|
|
||||||
// Legacy webServer support.
|
// Legacy webServer support.
|
||||||
config._internal.pluginRegistrations.push(...webServerPluginsForConfig(config));
|
webServerPluginsForConfig(config).forEach(p => config._internal.plugins.push({ factory: p }));
|
||||||
// Docker support.
|
// Docker support.
|
||||||
config._internal.pluginRegistrations.push(dockerPlugin);
|
config._internal.plugins.push({ factory: dockerPlugin });
|
||||||
|
|
||||||
const reporter = await createReporter(config, listOnly);
|
const reporter = await createReporter(config, listOnly);
|
||||||
const taskRunner = listOnly ? createTaskRunnerForList(config, reporter)
|
const taskRunner = listOnly ? createTaskRunnerForList(config, reporter)
|
||||||
@ -64,7 +64,6 @@ export class Runner {
|
|||||||
const context: TaskRunnerState = {
|
const context: TaskRunnerState = {
|
||||||
config,
|
config,
|
||||||
reporter,
|
reporter,
|
||||||
plugins: [],
|
|
||||||
phases: [],
|
phases: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -19,7 +19,7 @@ import path from 'path';
|
|||||||
import { promisify } from 'util';
|
import { promisify } from 'util';
|
||||||
import { debug, rimraf } from 'playwright-core/lib/utilsBundle';
|
import { debug, rimraf } from 'playwright-core/lib/utilsBundle';
|
||||||
import { Dispatcher } from './dispatcher';
|
import { Dispatcher } from './dispatcher';
|
||||||
import type { TestRunnerPlugin, TestRunnerPluginRegistration } from '../plugins';
|
import type { TestRunnerPluginRegistration } from '../plugins';
|
||||||
import type { Multiplexer } from '../reporters/multiplexer';
|
import type { Multiplexer } from '../reporters/multiplexer';
|
||||||
import type { TestGroup } from '../runner/testGroups';
|
import type { TestGroup } from '../runner/testGroups';
|
||||||
import { createTestGroups } from '../runner/testGroups';
|
import { createTestGroups } from '../runner/testGroups';
|
||||||
@ -41,7 +41,6 @@ type ProjectWithTestGroups = {
|
|||||||
export type TaskRunnerState = {
|
export type TaskRunnerState = {
|
||||||
reporter: Multiplexer;
|
reporter: Multiplexer;
|
||||||
config: FullConfigInternal;
|
config: FullConfigInternal;
|
||||||
plugins: TestRunnerPlugin[];
|
|
||||||
rootSuite?: Suite;
|
rootSuite?: Suite;
|
||||||
phases: {
|
phases: {
|
||||||
dispatcher: Dispatcher,
|
dispatcher: Dispatcher,
|
||||||
@ -52,25 +51,20 @@ export type TaskRunnerState = {
|
|||||||
export function createTaskRunner(config: FullConfigInternal, reporter: Multiplexer): TaskRunner<TaskRunnerState> {
|
export function createTaskRunner(config: FullConfigInternal, reporter: Multiplexer): TaskRunner<TaskRunnerState> {
|
||||||
const taskRunner = new TaskRunner<TaskRunnerState>(reporter, config.globalTimeout);
|
const taskRunner = new TaskRunner<TaskRunnerState>(reporter, config.globalTimeout);
|
||||||
|
|
||||||
for (const plugin of config._internal.pluginRegistrations)
|
for (const plugin of config._internal.plugins)
|
||||||
taskRunner.addTask('plugin setup', createPluginSetupTask(plugin));
|
taskRunner.addTask('plugin setup', createPluginSetupTask(plugin));
|
||||||
if (config.globalSetup || config.globalTeardown)
|
|
||||||
taskRunner.addTask('global setup', createGlobalSetupTask());
|
|
||||||
taskRunner.addTask('load tests', createLoadTask());
|
taskRunner.addTask('load tests', createLoadTask());
|
||||||
taskRunner.addTask('shard tests', createTestGroupsTask());
|
taskRunner.addTask('clear output', createRemoveOutputDirsTask());
|
||||||
taskRunner.addTask('prepare to run', createRemoveOutputDirsTask());
|
taskRunner.addTask('prepare workers', createTestGroupsTask());
|
||||||
taskRunner.addTask('plugin begin', async ({ rootSuite, plugins }) => {
|
for (const plugin of config._internal.plugins)
|
||||||
for (const plugin of plugins)
|
taskRunner.addTask('plugin begin', async ({ rootSuite }) => plugin.instance?.begin?.(rootSuite!));
|
||||||
await plugin.begin?.(rootSuite!);
|
|
||||||
});
|
|
||||||
|
|
||||||
taskRunner.addTask('report begin', async ({ reporter, rootSuite }) => {
|
taskRunner.addTask('report begin', async ({ reporter, rootSuite }) => {
|
||||||
reporter.onBegin?.(config, rootSuite!);
|
reporter.onBegin?.(config, rootSuite!);
|
||||||
return () => reporter.onEnd();
|
return () => reporter.onEnd();
|
||||||
});
|
});
|
||||||
|
if (config.globalSetup || config.globalTeardown)
|
||||||
|
taskRunner.addTask('global setup', createGlobalSetupTask());
|
||||||
taskRunner.addTask('test suite', createRunTestsTask());
|
taskRunner.addTask('test suite', createRunTestsTask());
|
||||||
|
|
||||||
return taskRunner;
|
return taskRunner;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,16 +78,14 @@ export function createTaskRunnerForList(config: FullConfigInternal, reporter: Mu
|
|||||||
return taskRunner;
|
return taskRunner;
|
||||||
}
|
}
|
||||||
|
|
||||||
function createPluginSetupTask(pluginRegistration: TestRunnerPluginRegistration): Task<TaskRunnerState> {
|
function createPluginSetupTask(plugin: TestRunnerPluginRegistration): Task<TaskRunnerState> {
|
||||||
return async ({ config, reporter, plugins }) => {
|
return async ({ config, reporter }) => {
|
||||||
let plugin: TestRunnerPlugin;
|
if (typeof plugin.factory === 'function')
|
||||||
if (typeof pluginRegistration === 'function')
|
plugin.instance = await plugin.factory();
|
||||||
plugin = await pluginRegistration();
|
|
||||||
else
|
else
|
||||||
plugin = pluginRegistration;
|
plugin.instance = plugin.factory;
|
||||||
plugins.push(plugin);
|
await plugin.instance?.setup?.(config, config._internal.configDir, reporter);
|
||||||
await plugin.setup?.(config, config._internal.configDir, reporter);
|
return () => plugin.instance?.teardown?.();
|
||||||
return () => plugin.teardown?.();
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user