chore: remove plugin registration sink (#20460)

This commit is contained in:
Pavel Feldman 2023-01-27 14:36:41 -08:00 committed by GitHub
parent 76cb09675a
commit 2c27bd3b07
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 138 additions and 136 deletions

View File

@ -14,18 +14,18 @@
* limitations under the License.
*/
const { test: baseTest, expect, devices, _addRunnerPlugin, defineConfig } = require('@playwright/test');
const { test: baseTest, expect, devices, defineConfig: originalDefineConfig } = require('@playwright/test');
const { fixtures } = require('@playwright/test/lib/mount');
const path = require('path');
_addRunnerPlugin(() => {
const plugin = () => {
// Only fetch upon request to avoid resolution in workers.
const { createPlugin } = require('@playwright/test/lib/plugins/vitePlugin');
return createPlugin(
path.join(__dirname, 'registerSource.mjs'),
() => import('@vitejs/plugin-react').then(plugin => plugin.default()));
});
};
const defineConfig = config => originalDefineConfig({ ...config, _plugins: [plugin] });
const test = baseTest.extend(fixtures);
module.exports = { test, expect, devices, defineConfig };

View File

@ -14,18 +14,18 @@
* limitations under the License.
*/
const { test: baseTest, expect, devices, _addRunnerPlugin, defineConfig } = require('@playwright/test');
const { test: baseTest, expect, devices, defineConfig: originalDefineConfig } = require('@playwright/test');
const { fixtures } = require('@playwright/test/lib/mount');
const path = require('path');
_addRunnerPlugin(() => {
const plugin = () => {
// Only fetch upon request to avoid resolution in workers.
const { createPlugin } = require('@playwright/test/lib/plugins/vitePlugin');
return createPlugin(
path.join(__dirname, 'registerSource.mjs'),
() => import('vite-plugin-solid').then(plugin => plugin.default()));
});
};
const defineConfig = config => originalDefineConfig({ ...config, _plugins: [plugin] });
const test = baseTest.extend(fixtures);
module.exports = { test, expect, devices, defineConfig };

View File

@ -14,18 +14,18 @@
* limitations under the License.
*/
const { test: baseTest, expect, devices, _addRunnerPlugin, defineConfig } = require('@playwright/test');
const { test: baseTest, expect, devices, defineConfig: originalDefineConfig } = require('@playwright/test');
const { fixtures } = require('@playwright/test/lib/mount');
const path = require('path');
_addRunnerPlugin(() => {
const plugin = () => {
// Only fetch upon request to avoid resolution in workers.
const { createPlugin } = require('@playwright/test/lib/plugins/vitePlugin');
return createPlugin(
path.join(__dirname, 'registerSource.mjs'),
() => import('@sveltejs/vite-plugin-svelte').then(plugin => plugin.svelte()));
});
};
const defineConfig = config => originalDefineConfig({ ...config, _plugins: [plugin] });
const test = baseTest.extend(fixtures);
module.exports = { test, expect, devices, defineConfig };

View File

@ -14,18 +14,18 @@
* limitations under the License.
*/
const { test: baseTest, expect, devices, _addRunnerPlugin, defineConfig } = require('@playwright/test');
const { test: baseTest, expect, devices, defineConfig: originalDefineConfig } = require('@playwright/test');
const { fixtures } = require('@playwright/test/lib/mount');
const path = require('path');
_addRunnerPlugin(() => {
const plugin = () => {
// Only fetch upon request to avoid resolution in workers.
const { createPlugin } = require('@playwright/test/lib/plugins/vitePlugin');
return createPlugin(
path.join(__dirname, 'registerSource.mjs'),
() => import('@vitejs/plugin-vue').then(plugin => plugin.default()));
});
}
const defineConfig = config => originalDefineConfig({ ...config, _plugins: [plugin] });
const test = baseTest.extend(fixtures);
module.exports = { test, expect, devices, defineConfig };

View File

@ -14,18 +14,18 @@
* limitations under the License.
*/
const { test: baseTest, expect, devices, _addRunnerPlugin, defineConfig } = require('@playwright/test');
const { test: baseTest, expect, devices, defineConfig: originalDefineConfig } = require('@playwright/test');
const { fixtures } = require('@playwright/test/lib/mount');
const path = require('path');
_addRunnerPlugin(() => {
const plugin = () => {
// Only fetch upon request to avoid resolution in workers.
const { createPlugin } = require('@playwright/test/lib/plugins/vitePlugin');
return createPlugin(
path.join(__dirname, 'registerSource.mjs'),
() => import('@vitejs/plugin-vue2').then(plugin => plugin.default()));
});
};
const defineConfig = config => originalDefineConfig({ ...config, _plugins: [plugin] });
const test = baseTest.extend(fixtures);
module.exports = { test, expect, devices, defineConfig };

View File

@ -151,11 +151,11 @@ async function runTests(args: string[], opts: { [key: string]: any }) {
return;
const configLoader = new ConfigLoader(overrides);
const runner = new Runner(configLoader.fullConfig());
if (resolvedConfigFile)
await configLoader.loadConfigFile(resolvedConfigFile);
else
await configLoader.loadEmptyConfig(configFileOrDirectory);
const runner = new Runner(configLoader.fullConfig());
const testFileFilters: TestFileFilter[] = args.map(arg => {
const match = /^(.*?):(\d+):?(\d+)?$/.exec(arg);

View File

@ -121,6 +121,7 @@ export class ConfigLoader {
this._fullConfig.shard = takeFirst(config.shard, baseFullConfig.shard);
this._fullConfig._ignoreSnapshots = takeFirst(config.ignoreSnapshots, baseFullConfig._ignoreSnapshots);
this._fullConfig.updateSnapshots = takeFirst(config.updateSnapshots, baseFullConfig.updateSnapshots);
this._fullConfig._pluginRegistrations = (config as any)._plugins || [];
const workers = takeFirst(config.workers, '50%');
if (typeof workers === 'string') {
@ -435,6 +436,7 @@ export const baseFullConfig: FullConfigInternal = {
_storeDir: '',
_maxConcurrentTestGroups: 0,
_ignoreSnapshots: false,
_pluginRegistrations: [],
};
function resolveReporters(reporters: Config['reporter'], rootDir: string): ReporterDescription[]|undefined {

View File

@ -16,7 +16,6 @@
import path from 'path';
import type { TestError } from '../../reporter';
import type { FullConfigInternal } from './types';
import type { LoadError } from './fixtures';
import { setCurrentlyLoadingFileSuite } from './globals';
import { PoolBuilder } from './poolBuilder';
@ -31,16 +30,16 @@ export const defaultTimeout = 30000;
const cachedFileSuites = new Map<string, Suite>();
export class TestLoader {
private _fullConfig: FullConfigInternal;
private _rootDir: string;
constructor(fullConfig: FullConfigInternal) {
this._fullConfig = fullConfig;
constructor(rootDir: string) {
this._rootDir = rootDir;
}
async loadTestFile(file: string, environment: 'loader' | 'worker', loadErrors: TestError[]): Promise<Suite> {
if (cachedFileSuites.has(file))
return cachedFileSuites.get(file)!;
const suite = new Suite(path.relative(this._fullConfig.rootDir, file) || path.basename(file), 'file');
const suite = new Suite(path.relative(this._rootDir, file) || path.basename(file), 'file');
suite._requireFile = file;
suite.location = { file, line: 0, column: 0 };
@ -80,8 +79,8 @@ export class TestLoader {
}
}
export async function loadTestFilesInProcess(config: FullConfigInternal, testFiles: string[], loadErrors: LoadError[]): Promise<Suite> {
const testLoader = new TestLoader(config);
export async function loadTestFilesInProcess(rootDir: string, testFiles: string[], loadErrors: LoadError[]): Promise<Suite> {
const testLoader = new TestLoader(rootDir);
const rootSuite = new Suite('', 'root');
for (const file of testFiles) {
const fileSuite = await testLoader.loadTestFile(file, 'loader', loadErrors);

View File

@ -16,6 +16,7 @@
import type { Fixtures, TestInfoError, Project } from '../../types/test';
import type { Location } from '../../types/testReporter';
import type { TestRunnerPluginRegistration } from '../plugins';
import type { ConfigCLIOverrides } from './ipc';
import type { FullConfig as FullConfigPublic, FullProject as FullProjectPublic } from './types';
export * from '../../types/test';
@ -57,6 +58,8 @@ export interface FullConfigInternal extends FullConfigPublic {
// Overrides the public field.
projects: FullProjectInternal[];
_pluginRegistrations: TestRunnerPluginRegistration[];
}
/**

View File

@ -24,7 +24,6 @@ import type { TestInfoImpl } from './common/testInfo';
import { rootTestType } from './common/testType';
import { type ContextReuseMode } from './common/types';
export { expect } from './matchers/expect';
export { addRunnerPlugin as _addRunnerPlugin } from './plugins';
export const _baseTest: TestType<{}, {}> = rootTestType.test;
addStackIgnoreFilter((frame: StackFrame) => frame.file.startsWith(path.dirname(require.resolve('../package.json'))));

View File

@ -39,7 +39,7 @@ export class LoaderMain extends ProcessRunner {
async loadTestFiles(params: { files: string[] }) {
const loadErrors: LoadError[] = [];
const config = await this._config();
const rootSuite = await loadTestFilesInProcess(config, params.files, loadErrors);
const rootSuite = await loadTestFilesInProcess(config.rootDir, params.files, loadErrors);
return { rootSuite: rootSuite._deepSerialize(), loadErrors };
}
}

View File

@ -15,7 +15,6 @@
*/
import type { Suite, Reporter } from '../../types/testReporter';
import type { Runner } from '../runner/runner';
import type { FullConfig } from '../common/types';
export interface TestRunnerPlugin {
@ -25,22 +24,7 @@ export interface TestRunnerPlugin {
teardown?(): Promise<void>;
}
export type TestRunnerPluginRegistration = TestRunnerPlugin | (() => TestRunnerPlugin | Promise<TestRunnerPlugin>);
export { webServer } from './webServerPlugin';
export { gitCommitInfo } from './gitCommitInfoPlugin';
let runnerInstanceToAddPluginsTo: Runner | undefined;
const deferredPlugins: TestRunnerPlugin[] = [];
export const setRunnerToAddPluginsTo = (runner: Runner) => {
runnerInstanceToAddPluginsTo = runner;
for (const plugin of deferredPlugins)
runnerInstanceToAddPluginsTo.addPlugin(plugin);
};
export const addRunnerPlugin = (plugin: TestRunnerPlugin | (() => TestRunnerPlugin)) => {
plugin = typeof plugin === 'function' ? plugin() : plugin;
if (runnerInstanceToAddPluginsTo)
runnerInstanceToAddPluginsTo.addPlugin(plugin);
else
deferredPlugins.push(plugin);
};

View File

@ -26,7 +26,7 @@ import type { FullConfigInternal } from '../common/types';
import { errorWithFile } from '../util';
import type { Matcher, TestFileFilter } from '../util';
import { createFileMatcher } from '../util';
import { collectFilesForProjects, collectProjects } from './projectUtils';
import { collectFilesForProjects, filterProjects } from './projectUtils';
import { requireOrImport } from '../common/transform';
import { serializeConfig } from '../common/ipc';
@ -39,7 +39,7 @@ type LoadOptions = {
};
export async function loadAllTests(config: FullConfigInternal, reporter: Multiplexer, options: LoadOptions, errors: TestError[]): Promise<Suite> {
const projects = collectProjects(config, options.projectFilter);
const projects = filterProjects(config.projects, options.projectFilter);
const filesByProject = await collectFilesForProjects(projects, options.testFileFilters);
const allTestFiles = new Set<string>();
for (const files of filesByProject.values())
@ -80,7 +80,7 @@ async function loadTests(config: FullConfigInternal, reporter: Multiplexer, test
}
const loadErrors: LoadError[] = [];
try {
return await loadTestFilesInProcess(config, [...testFiles], loadErrors);
return await loadTestFilesInProcess(config.rootDir, [...testFiles], loadErrors);
} finally {
errors.push(...loadErrors);
}

View File

@ -18,16 +18,16 @@ import fs from 'fs';
import path from 'path';
import { minimatch } from 'playwright-core/lib/utilsBundle';
import { promisify } from 'util';
import type { FullConfigInternal, FullProjectInternal } from '../common/types';
import type { FullProjectInternal } from '../common/types';
import type { TestFileFilter } from '../util';
import { createFileMatcher, createFileMatcherFromFilters } from '../util';
const readFileAsync = promisify(fs.readFile);
const readDirAsync = promisify(fs.readdir);
export function collectProjects(config: FullConfigInternal, projectNames?: string[]): FullProjectInternal[] {
export function filterProjects(projects: FullProjectInternal[], projectNames?: string[]): FullProjectInternal[] {
if (!projectNames)
return [...config.projects];
return [...projects];
const projectsToFind = new Set<string>();
const unknownProjects = new Map<string, string>();
projectNames.forEach(n => {
@ -35,19 +35,19 @@ export function collectProjects(config: FullConfigInternal, projectNames?: strin
projectsToFind.add(name);
unknownProjects.set(name, n);
});
const projects = config.projects.filter(project => {
const result = projects.filter(project => {
const name = project.name.toLocaleLowerCase();
unknownProjects.delete(name);
return projectsToFind.has(name);
});
if (unknownProjects.size) {
const names = config.projects.map(p => p.name).filter(name => !!name);
const names = projects.map(p => p.name).filter(name => !!name);
if (!names.length)
throw new Error(`No named projects are specified in the configuration file`);
const unknownProjectNames = Array.from(unknownProjects.values()).map(n => `"${n}"`).join(', ');
throw new Error(`Project(s) ${unknownProjectNames} not found. Available named projects: ${names.map(name => `"${name}"`).join(', ')}`);
}
return projects;
return result;
}
export async function collectFilesForProjects(projects: FullProjectInternal[], commandLineFileFilters: TestFileFilter[]): Promise<Map<FullProjectInternal, string[]>> {

View File

@ -17,13 +17,11 @@
import { monotonicTime } from 'playwright-core/lib/utils';
import type { FullResult } from '../../types/testReporter';
import type { TestRunnerPlugin } from '../plugins';
import { setRunnerToAddPluginsTo } from '../plugins';
import { dockerPlugin } from '../plugins/dockerPlugin';
import { webServerPluginsForConfig } from '../plugins/webServerPlugin';
import { collectFilesForProjects, collectProjects } from './projectUtils';
import { collectFilesForProjects, filterProjects } from './projectUtils';
import { createReporter } from './reporters';
import { createTaskRunner } from './tasks';
import { createTaskRunner, createTaskRunnerForList } from './tasks';
import type { TaskRunnerState } from './tasks';
import type { FullConfigInternal } from '../common/types';
import type { Matcher, TestFileFilter } from '../util';
@ -38,19 +36,13 @@ export type RunOptions = {
export class Runner {
private _config: FullConfigInternal;
private _plugins: TestRunnerPlugin[] = [];
constructor(config: FullConfigInternal) {
this._config = config;
setRunnerToAddPluginsTo(this);
}
addPlugin(plugin: TestRunnerPlugin) {
this._plugins.push(plugin);
}
async listTestFiles(projectNames: string[] | undefined): Promise<any> {
const projects = collectProjects(this._config, projectNames);
const projects = filterProjects(this._config.projects, projectNames);
const filesByProject = await collectFilesForProjects(projects, []);
const report: any = {
projects: []
@ -69,17 +61,19 @@ export class Runner {
const deadline = config.globalTimeout ? monotonicTime() + config.globalTimeout : 0;
// Legacy webServer support.
this._plugins.push(...webServerPluginsForConfig(config));
config._pluginRegistrations.push(...webServerPluginsForConfig(config));
// Docker support.
this._plugins.push(dockerPlugin);
config._pluginRegistrations.push(dockerPlugin);
const reporter = await createReporter(config, options.listOnly);
const taskRunner = createTaskRunner(config, reporter, this._plugins, options);
const taskRunner = options.listOnly ? createTaskRunnerForList(config, reporter)
: createTaskRunner(config, reporter);
const context: TaskRunnerState = {
config,
options,
reporter,
plugins: [],
};
reporter.onConfigure(config);

View File

@ -19,7 +19,7 @@ import path from 'path';
import { promisify } from 'util';
import { colors, rimraf } from 'playwright-core/lib/utilsBundle';
import { Dispatcher } from './dispatcher';
import type { TestRunnerPlugin } from '../plugins';
import type { TestRunnerPlugin, TestRunnerPluginRegistration } from '../plugins';
import type { Multiplexer } from '../reporters/multiplexer';
import type { TestGroup } from '../runner/testGroups';
import { createTestGroups, filterForShard } from '../runner/testGroups';
@ -45,43 +45,56 @@ export type TaskRunnerState = {
options: TaskRunnerOptions;
reporter: Multiplexer;
config: FullConfigInternal;
plugins: TestRunnerPlugin[];
rootSuite?: Suite;
testGroups?: TestGroup[];
dispatcher?: Dispatcher;
};
export function createTaskRunner(config: FullConfigInternal, reporter: Multiplexer, plugins: TestRunnerPlugin[], options: TaskRunnerOptions): TaskRunner<TaskRunnerState> {
export function createTaskRunner(config: FullConfigInternal, reporter: Multiplexer): TaskRunner<TaskRunnerState> {
const taskRunner = new TaskRunner<TaskRunnerState>(reporter, config.globalTimeout);
for (const plugin of plugins)
for (const plugin of config._pluginRegistrations)
taskRunner.addTask('plugin setup', createPluginSetupTask(plugin));
if (config.globalSetup || config.globalTeardown)
taskRunner.addTask('global setup', createGlobalSetupTask());
taskRunner.addTask('load tests', createLoadTask());
if (!options.listOnly) {
taskRunner.addTask('prepare to run', createRemoveOutputDirsTask());
taskRunner.addTask('plugin begin', async ({ rootSuite }) => {
for (const plugin of plugins)
await plugin.begin?.(rootSuite!);
});
}
taskRunner.addTask('prepare to run', createRemoveOutputDirsTask());
taskRunner.addTask('plugin begin', async ({ rootSuite, plugins }) => {
for (const plugin of plugins)
await plugin.begin?.(rootSuite!);
});
taskRunner.addTask('report begin', async ({ reporter, rootSuite }) => {
reporter.onBegin?.(config, rootSuite!);
return () => reporter.onEnd();
});
if (!options.listOnly) {
taskRunner.addTask('setup workers', createSetupWorkersTask());
taskRunner.addTask('test suite', async ({ dispatcher }) => dispatcher!.run());
}
taskRunner.addTask('setup workers', createSetupWorkersTask());
taskRunner.addTask('test suite', async ({ dispatcher }) => dispatcher!.run());
return taskRunner;
}
export function createPluginSetupTask(plugin: TestRunnerPlugin): Task<TaskRunnerState> {
return async ({ config, reporter }) => {
export function createTaskRunnerForList(config: FullConfigInternal, reporter: Multiplexer): TaskRunner<TaskRunnerState> {
const taskRunner = new TaskRunner<TaskRunnerState>(reporter, config.globalTimeout);
taskRunner.addTask('load tests', createLoadTask());
taskRunner.addTask('report begin', async ({ reporter, rootSuite }) => {
reporter.onBegin?.(config, rootSuite!);
return () => reporter.onEnd();
});
return taskRunner;
}
export function createPluginSetupTask(pluginRegistration: TestRunnerPluginRegistration): Task<TaskRunnerState> {
return async ({ config, reporter, plugins }) => {
let plugin: TestRunnerPlugin;
if (typeof pluginRegistration === 'function')
plugin = await pluginRegistration();
else
plugin = pluginRegistration;
plugins.push(plugin);
await plugin.setup?.(config, config._configDir, reporter);
return () => plugin.teardown?.();
};

View File

@ -195,7 +195,7 @@ export class WorkerMain extends ProcessRunner {
const configLoader = await ConfigLoader.deserialize(this._params.config);
this._config = configLoader.fullConfig();
this._testLoader = new TestLoader(this._config);
this._testLoader = new TestLoader(this._config.rootDir);
this._project = this._config.projects.find(p => p._id === this._params.projectId)!;
this._poolBuilder = PoolBuilder.createForWorker(this._project);
}

View File

@ -325,13 +325,14 @@ test('globalSetup auth should compile', async ({ runTSC }) => {
test('teardown order', async ({ runInlineTest }) => {
const result = await runInlineTest({
'playwright.config.ts': `
const _plugins = [];
for (let i = 1; i < 4; ++i) {
pwt._addRunnerPlugin(() => ({
_plugins.push(() => ({
setup: () => console.log('\\n%%setup ' + i),
teardown: () => console.log('\\n%%teardown ' + i),
}));
}
export default {};
export default { _plugins };
`,
'a.test.js': `
pwt.test('test', () => {});
@ -352,8 +353,9 @@ test('teardown order', async ({ runInlineTest }) => {
test('teardown after error', async ({ runInlineTest }) => {
const result = await runInlineTest({
'playwright.config.ts': `
const _plugins = [];
for (let i = 1; i < 4; ++i) {
pwt._addRunnerPlugin(() => ({
_plugins.push(() => ({
setup: () => console.log('\\n%%setup ' + i),
teardown: () => {
console.log('\\n%%teardown ' + i);
@ -361,7 +363,7 @@ test('teardown after error', async ({ runInlineTest }) => {
},
}));
}
export default {};
export default { _plugins };
`,
'a.test.js': `
pwt.test('test', () => {});

View File

@ -778,9 +778,8 @@ test.describe('gitCommitInfo plugin', () => {
'uncommitted.txt': `uncommitted file`,
'playwright.config.ts': `
import { gitCommitInfo } from '@playwright/test/lib/plugins';
const { test, _addRunnerPlugin } = pwt;
_addRunnerPlugin(gitCommitInfo());
export default {};
const { test } = pwt;
export default { _plugins: [gitCommitInfo()] };
`,
'example.spec.ts': `
const { test } = pwt;
@ -810,8 +809,8 @@ test.describe('gitCommitInfo plugin', () => {
'uncommitted.txt': `uncommitted file`,
'playwright.config.ts': `
import { gitCommitInfo } from '@playwright/test/lib/plugins';
const { test, _addRunnerPlugin } = pwt;
_addRunnerPlugin(gitCommitInfo({
const { test } = pwt;
const plugin = gitCommitInfo({
info: {
'revision.id': '1234567890',
'revision.subject': 'a better subject',
@ -819,8 +818,8 @@ test.describe('gitCommitInfo plugin', () => {
'revision.author': 'William',
'revision.email': 'shakespeare@example.local',
},
}));
export default {};
});
export default { _plugins: [plugin] };
`,
'example.spec.ts': `
import { gitCommitInfo } from '@playwright/test/lib/plugins';

View File

@ -363,10 +363,8 @@ test('sigint should stop plugins', async ({ runInlineTest }) => {
const result = await runInlineTest({
'playwright.config.ts': `
module.exports = {
};
require('@playwright/test')._addRunnerPlugin(() => ({
const _plugins = [];
_plugins.push(() => ({
setup: async () => {
console.log('Plugin1 setup');
console.log('%%SEND-SIGINT%%');
@ -377,7 +375,7 @@ test('sigint should stop plugins', async ({ runInlineTest }) => {
}
}));
require('@playwright/test')._addRunnerPlugin(() => ({
_plugins.push(() => ({
setup: async () => {
console.log('Plugin2 setup');
},
@ -385,6 +383,9 @@ test('sigint should stop plugins', async ({ runInlineTest }) => {
console.log('Plugin2 teardown');
}
}));
module.exports = {
_plugins
};
`,
'a.spec.js': `
const { test } = pwt;
@ -405,10 +406,8 @@ test('sigint should stop plugins 2', async ({ runInlineTest }) => {
const result = await runInlineTest({
'playwright.config.ts': `
module.exports = {
};
require('@playwright/test')._addRunnerPlugin(() => ({
const _plugins = [];
_plugins.push(() => ({
setup: async () => {
console.log('Plugin1 setup');
},
@ -417,7 +416,7 @@ test('sigint should stop plugins 2', async ({ runInlineTest }) => {
}
}));
require('@playwright/test')._addRunnerPlugin(() => ({
_plugins.push(() => ({
setup: async () => {
console.log('Plugin2 setup');
console.log('%%SEND-SIGINT%%');
@ -427,6 +426,7 @@ test('sigint should stop plugins 2', async ({ runInlineTest }) => {
console.log('Plugin2 teardown');
}
}));
module.exports = { _plugins };
`,
'a.spec.js': `
const { test } = pwt;

View File

@ -536,17 +536,22 @@ test.describe('baseURL with plugins', () => {
const port = workerIndex * 2 + 10500;
const result = await runInlineTest({
'test.spec.ts': `
import { webServer } from '@playwright/test/lib/plugins';
const { test, _addRunnerPlugin } = pwt;
_addRunnerPlugin(webServer({
command: 'node ${JSON.stringify(SIMPLE_SERVER_PATH)} ${port}',
url: 'http://localhost:${port}/port',
}));
test('connect to the server', async ({baseURL, page}) => {
expect(baseURL).toBeUndefined();
});
const { test } = pwt;
test('connect to the server', async ({baseURL, page}) => {
expect(baseURL).toBeUndefined();
});
`,
'playwright.config.ts': `
import { webServer } from '@playwright/test/lib/plugins';
module.exports = {
_plugins: [
webServer({
command: 'node ${JSON.stringify(SIMPLE_SERVER_PATH)} ${port}',
url: 'http://localhost:${port}/port',
})
]
};
`,
'playwright.config.ts': `module.exports = {};`,
}, undefined, { DEBUG: 'pw:webserver' });
expect(result.exitCode).toBe(0);
expect(result.passed).toBe(1);
@ -556,24 +561,26 @@ test.describe('baseURL with plugins', () => {
const port = workerIndex * 2 + 10500;
const result = await runInlineTest({
'test.spec.ts': `
import { webServer } from '@playwright/test/lib/plugins';
const { test, _addRunnerPlugin } = pwt;
_addRunnerPlugin(webServer({
command: 'node ${JSON.stringify(SIMPLE_SERVER_PATH)} ${port + 1}',
url: 'http://localhost:${port + 1}/port'
}));
test('connect to the server', async ({baseURL, page}) => {
expect(baseURL).toBe('http://localhost:${port}');
});
`,
const { test } = pwt;
test('connect to the server', async ({baseURL, page}) => {
expect(baseURL).toBe('http://localhost:${port}');
});
`,
'playwright.config.ts': `
module.exports = {
webServer: {
command: 'node ${JSON.stringify(SIMPLE_SERVER_PATH)} ${port}',
port: ${port},
}
};
`,
import { webServer } from '@playwright/test/lib/plugins';
module.exports = {
webServer: {
command: 'node ${JSON.stringify(SIMPLE_SERVER_PATH)} ${port}',
port: ${port},
},
_plugins: [
webServer({
command: 'node ${JSON.stringify(SIMPLE_SERVER_PATH)} ${port + 1}',
url: 'http://localhost:${port + 1}/port'
})
]
};
`,
}, undefined, { DEBUG: 'pw:webserver' });
expect(result.exitCode).toBe(0);
expect(result.passed).toBe(1);