Skip to content

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

chore: hide plugins for now (#13908)

Pavel Feldman29fd1d86df7d
diff --git a/docs/src/test-api/class-testconfig.md b/docs/src/test-api/class-testconfig.md
index c78ea12a32..17ec5acd99 100644
--- a/docs/src/test-api/class-testconfig.md
+++ b/docs/src/test-api/class-testconfig.md
@@ -319,9 +319,6 @@ The directory for each test can be accessed by [`property: TestInfo.snapshotDir`
This path will serve as the base directory for each test file snapshot directory. Setting `snapshotDir` to `'snapshots'`, the [`property: TestInfo.snapshotDir`] would resolve to `snapshots/a.spec.js-snapshots`.
-## property: TestConfig.plugins
-- type: ?<[Array]<[TestPlugin]>>
-
## property: TestConfig.preserveOutput
- type: ?<[PreserveOutput]<"always"|"never"|"failures-only">>
diff --git a/docs/src/test-api/class-testplugin.md b/docs/src/test-api/class-testplugin.md
deleted file mode 100644
index dd464af016..0000000000
--- a/docs/src/test-api/class-testplugin.md
+++ /dev/null
@@ -1,19 +0,0 @@
-# class: TestPlugin
-* langs: js
-
-## property: TestPlugin.name
-- type: <[string]>
-
-## optional async method: TestPlugin.configure
-### param: TestPlugin.configure.config
-- `config` <[TestConfig]>
-
-### param: TestPlugin.configure.configDir
-- `configDir` <[string]>
-
-## optional async method: TestPlugin.setup
-
-### param: TestPlugin.setup.suite
-- `suite` <[Suite]>
-
-## optional async method: TestPlugin.teardown
diff --git a/examples/components-vue/playwright.config.ts b/examples/components-vue/playwright.config.ts
index 1081014837..c608e9398d 100644
--- a/examples/components-vue/playwright.config.ts
+++ b/examples/components-vue/playwright.config.ts
@@ -1,18 +1,10 @@
import { PlaywrightTestConfig, devices } from '@playwright/test';
-import viteCT from '@playwright/experimental-ct-vue/vitePlugin';
const config: PlaywrightTestConfig = {
testDir: 'src',
forbidOnly: !!process.env.CI,
retries: process.env.CI ? 2 : 0,
- reporter: process.env.CI ? [
- ['html', { open: 'never' }],
- ] : [
- ['html', { open: 'on-failure' }]
- ],
- plugins: [
- viteCT()
- ],
+ reporter: 'html',
use: {
trace: 'on-first-retry',
},
diff --git a/packages/html-reporter/playwright.config.ts b/packages/html-reporter/playwright.config.ts
index b3f7fefd67..b4b0eed1ec 100644
--- a/packages/html-reporter/playwright.config.ts
+++ b/packages/html-reporter/playwright.config.ts
@@ -17,7 +17,6 @@
import type { PlaywrightTestConfig } from '@playwright/test';
import path from 'path';
import { devices } from '@playwright/test';
-import viteCT from '@playwright/experimental-ct-react/vitePlugin';
const config: PlaywrightTestConfig = {
testDir: 'src',
@@ -28,9 +27,6 @@ const config: PlaywrightTestConfig = {
] : [
['html', { open: 'on-failure' }]
],
- plugins: [
- viteCT({ port: 3101 })
- ],
use: {
trace: 'on-first-retry',
},
diff --git a/packages/playwright-ct-react/package.json b/packages/playwright-ct-react/package.json
index 51dd2bcfc7..0d4190d770 100644
--- a/packages/playwright-ct-react/package.json
+++ b/packages/playwright-ct-react/package.json
@@ -14,8 +14,7 @@
"license": "Apache-2.0",
"exports": {
"./register": "./register.mjs",
- "./test": "./test.js",
- "./vitePlugin": "./vitePlugin.js"
+ "./test": "./test.js"
},
"dependencies": {
"@vitejs/plugin-react": "^1.0.7",
diff --git a/packages/playwright-ct-react/test.js b/packages/playwright-ct-react/test.js
index 101182cfb5..a3e48480cb 100644
--- a/packages/playwright-ct-react/test.js
+++ b/packages/playwright-ct-react/test.js
@@ -14,8 +14,13 @@
* limitations under the License.
*/
-const { test: baseTest, expect } = require('@playwright/test');
+const { test: baseTest, expect, _addRunnerPlugin } = require('@playwright/test');
const { mount } = require('@playwright/test/lib/mount');
+const { createPlugin } = require('@playwright/test/lib/plugins/vitePlugin');
+
+_addRunnerPlugin(createPlugin(
+ '@playwright/experimental-ct-react/register',
+ () => require('@vitejs/plugin-react')()));
const test = baseTest.extend({
_workerPage: [async ({ browser }, use) => {
diff --git a/packages/playwright-ct-react/vitePlugin.d.ts b/packages/playwright-ct-react/vitePlugin.d.ts
deleted file mode 100644
index 759cf63aee..0000000000
--- a/packages/playwright-ct-react/vitePlugin.d.ts
+++ /dev/null
@@ -1,23 +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 { TestPlugin } from '@playwright/test';
-import type { InlineConfig } from 'vite';
-
-export default function(options?: {
- config?: InlineConfig,
- port?: number,
-}): TestPlugin;
diff --git a/packages/playwright-ct-react/vitePlugin.js b/packages/playwright-ct-react/vitePlugin.js
deleted file mode 100644
index 97281c5a6f..0000000000
--- a/packages/playwright-ct-react/vitePlugin.js
+++ /dev/null
@@ -1,24 +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.
- */
-
-const { createPlugin } = require('@playwright/test/lib/plugins/vitePlugin');
-
-module.exports = (options = {}) => {
- return createPlugin(
- '@playwright/experimental-ct-react/register',
- () => require('@vitejs/plugin-react')(),
- options);
-};
diff --git a/packages/playwright-ct-svelte/package.json b/packages/playwright-ct-svelte/package.json
index 55a9485302..1cabfa1887 100644
--- a/packages/playwright-ct-svelte/package.json
+++ b/packages/playwright-ct-svelte/package.json
@@ -14,8 +14,7 @@
"license": "Apache-2.0",
"exports": {
"./register": "./register.mjs",
- "./test": "./test.js",
- "./vitePlugin": "./vitePlugin.js"
+ "./test": "./test.js"
},
"dependencies": {
"@sveltejs/vite-plugin-svelte": "^1.0.0-next.30",
diff --git a/packages/playwright-ct-svelte/test.js b/packages/playwright-ct-svelte/test.js
index 101182cfb5..a6a334ca38 100644
--- a/packages/playwright-ct-svelte/test.js
+++ b/packages/playwright-ct-svelte/test.js
@@ -14,8 +14,13 @@
* limitations under the License.
*/
-const { test: baseTest, expect } = require('@playwright/test');
+const { test: baseTest, expect, _addRunnerPlugin } = require('@playwright/test');
const { mount } = require('@playwright/test/lib/mount');
+const { createPlugin } = require('@playwright/test/lib/plugins/vitePlugin');
+
+_addRunnerPlugin(createPlugin(
+ '@playwright/experimental-ct-svelte/register',
+ () => require('@sveltejs/vite-plugin-svelte').svelte()));
const test = baseTest.extend({
_workerPage: [async ({ browser }, use) => {
diff --git a/packages/playwright-ct-svelte/vitePlugin.d.ts b/packages/playwright-ct-svelte/vitePlugin.d.ts
deleted file mode 100644
index 759cf63aee..0000000000
--- a/packages/playwright-ct-svelte/vitePlugin.d.ts
+++ /dev/null
@@ -1,23 +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 { TestPlugin } from '@playwright/test';
-import type { InlineConfig } from 'vite';
-
-export default function(options?: {
- config?: InlineConfig,
- port?: number,
-}): TestPlugin;
diff --git a/packages/playwright-ct-svelte/vitePlugin.js b/packages/playwright-ct-svelte/vitePlugin.js
deleted file mode 100644
index fad9a03baa..0000000000
--- a/packages/playwright-ct-svelte/vitePlugin.js
+++ /dev/null
@@ -1,24 +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.
- */
-
-const { createPlugin } = require('@playwright/test/lib/plugins/vitePlugin');
-
-module.exports = (options = {}) => {
- return createPlugin(
- '@playwright/experimental-ct-svelte/register',
- () => require('@sveltejs/vite-plugin-svelte').svelte(),
- options);
-};
diff --git a/packages/playwright-ct-vue/package.json b/packages/playwright-ct-vue/package.json
index d5b9202732..639192b5ae 100644
--- a/packages/playwright-ct-vue/package.json
+++ b/packages/playwright-ct-vue/package.json
@@ -14,8 +14,7 @@
"license": "Apache-2.0",
"exports": {
"./register": "./register.mjs",
- "./test": "./test.js",
- "./vitePlugin": "./vitePlugin.js"
+ "./test": "./test.js"
},
"dependencies": {
"@vitejs/plugin-vue": "^2.3.1",
diff --git a/packages/playwright-ct-vue/test.js b/packages/playwright-ct-vue/test.js
index 101182cfb5..b47e6fa5b0 100644
--- a/packages/playwright-ct-vue/test.js
+++ b/packages/playwright-ct-vue/test.js
@@ -14,8 +14,13 @@
* limitations under the License.
*/
-const { test: baseTest, expect } = require('@playwright/test');
+const { test: baseTest, expect, _addRunnerPlugin } = require('@playwright/test');
const { mount } = require('@playwright/test/lib/mount');
+const { createPlugin } = require('@playwright/test/lib/plugins/vitePlugin');
+
+_addRunnerPlugin(createPlugin(
+ '@playwright/experimental-ct-vue/register',
+ () => require('@vitejs/plugin-vue')()));
const test = baseTest.extend({
_workerPage: [async ({ browser }, use) => {
diff --git a/packages/playwright-ct-vue/vitePlugin.d.ts b/packages/playwright-ct-vue/vitePlugin.d.ts
deleted file mode 100644
index 759cf63aee..0000000000
--- a/packages/playwright-ct-vue/vitePlugin.d.ts
+++ /dev/null
@@ -1,23 +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 { TestPlugin } from '@playwright/test';
-import type { InlineConfig } from 'vite';
-
-export default function(options?: {
- config?: InlineConfig,
- port?: number,
-}): TestPlugin;
diff --git a/packages/playwright-ct-vue/vitePlugin.js b/packages/playwright-ct-vue/vitePlugin.js
deleted file mode 100644
index b06e1b3a80..0000000000
--- a/packages/playwright-ct-vue/vitePlugin.js
+++ /dev/null
@@ -1,24 +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.
- */
-
-const { createPlugin } = require('@playwright/test/lib/plugins/vitePlugin');
-
-module.exports = (options = {}) => {
- return createPlugin(
- '@playwright/experimental-ct-vue/register',
- () => require('@vitejs/plugin-vue')(),
- options);
-};
diff --git a/packages/playwright-test/src/DEPS.list b/packages/playwright-test/src/DEPS.list
index a27fa8b5fd..9c2d617d3e 100644
--- a/packages/playwright-test/src/DEPS.list
+++ b/packages/playwright-test/src/DEPS.list
@@ -3,4 +3,5 @@
matchers/
reporters/
third_party/
+plugins/
plugins/webServerPlugin.ts
diff --git a/packages/playwright-test/src/index.ts b/packages/playwright-test/src/index.ts
index 4431a4cb6e..e27db4a594 100644
--- a/packages/playwright-test/src/index.ts
+++ b/packages/playwright-test/src/index.ts
@@ -23,6 +23,7 @@ import { createGuid, debugMode } from 'playwright-core/lib/utils';
import { removeFolders } from 'playwright-core/lib/utils/fileUtils';
export { expect } from './expect';
export const _baseTest: TestType<{}, {}> = rootTestType.test;
+export { addRunnerPlugin as _addRunnerPlugin } from './plugins';
import * as outOfProcess from 'playwright-core/lib/outofprocess';
if ((process as any)['__pw_initiator__']) {
diff --git a/packages/playwright-test/src/ipc.ts b/packages/playwright-test/src/ipc.ts
index 0012af44e1..de10417e8d 100644
--- a/packages/playwright-test/src/ipc.ts
+++ b/packages/playwright-test/src/ipc.ts
@@ -16,13 +16,12 @@
import type { TestError } from '../types/testReporter';
import type { ConfigCLIOverrides } from './runner';
-import type { FullConfigInternal, TestStatus } from './types';
+import type { TestStatus } from './types';
export type SerializedLoaderData = {
- config: FullConfigInternal;
configFile: string | undefined;
configDir: string;
- overridesForLegacyConfigMode?: ConfigCLIOverrides;
+ configCLIOverrides: ConfigCLIOverrides;
};
export type WorkerInitParams = {
diff --git a/packages/playwright-test/src/loader.ts b/packages/playwright-test/src/loader.ts
index 9a48bbb9cc..b6bcbd5586 100644
--- a/packages/playwright-test/src/loader.ts
+++ b/packages/playwright-test/src/loader.ts
@@ -29,7 +29,6 @@ import type { Reporter } from '../types/testReporter';
import { builtInReporters } from './runner';
import { isRegExp, calculateSha1 } from 'playwright-core/lib/utils';
import { serializeError } from './util';
-import { webServerPluginForConfig } from './plugins/webServerPlugin';
import { hostPlatform } from 'playwright-core/lib/utils/hostPlatform';
import { FixturePool, isFixtureOption } from './fixtures';
import type { TestTypeImpl } from './testType';
@@ -53,20 +52,12 @@ export class Loader {
}
static async deserialize(data: SerializedLoaderData): Promise<Loader> {
- if (process.env.PLAYWRIGHT_LEGACY_CONFIG_MODE) {
- const loader = new Loader(data.overridesForLegacyConfigMode);
- if (data.configFile)
- await loader.loadConfigFile(data.configFile);
- else
- await loader.loadEmptyConfig(data.configDir);
- return loader;
- } else {
- const loader = new Loader();
- loader._configFile = data.configFile;
- loader._configDir = data.configDir;
- loader._fullConfig = data.config;
- return loader;
- }
+ const loader = new Loader(data.configCLIOverrides);
+ if (data.configFile)
+ await loader.loadConfigFile(data.configFile);
+ else
+ await loader.loadEmptyConfig(data.configDir);
+ return loader;
}
async loadConfigFile(file: string): Promise<FullConfigInternal> {
@@ -86,11 +77,6 @@ export class Loader {
}
private async _processConfigObject(config: Config, configDir: string) {
- if (config.webServer) {
- config.plugins = config.plugins || [];
- config.plugins.push(webServerPluginForConfig(config));
- }
-
// 1. Validate data provided in the config file.
validateConfig(this._configFile || '<default config>', config);
@@ -118,11 +104,7 @@ export class Loader {
for (const project of config.projects || [])
this._applyCLIOverridesToProject(project);
- // 3. Run configure plugins phase.
- for (const plugin of config.plugins || [])
- await plugin.configure?.(config, configDir);
-
- // 4. Resolve config.
+ // 3. Resolve config.
this._configDir = configDir;
const packageJsonPath = getPackageJsonPath(configDir);
const packageJsonDir = packageJsonPath ? path.dirname(packageJsonPath) : undefined;
@@ -142,8 +124,6 @@ export class Loader {
(config as any).screenshotsDir = path.resolve(configDir, (config as any).screenshotsDir);
if (config.snapshotDir !== undefined)
config.snapshotDir = path.resolve(configDir, config.snapshotDir);
- if (config.webServer)
- config.webServer.cwd = config.webServer.cwd ? path.resolve(configDir, config.webServer.cwd) : configDir;
this._fullConfig._configDir = configDir;
this._fullConfig.rootDir = config.testDir || this._configDir;
@@ -164,7 +144,6 @@ export class Loader {
this._fullConfig.updateSnapshots = takeFirst(config.updateSnapshots, baseFullConfig.updateSnapshots);
this._fullConfig.workers = takeFirst(config.workers, baseFullConfig.workers);
this._fullConfig.webServer = takeFirst(config.webServer, baseFullConfig.webServer);
- this._fullConfig._plugins = takeFirst(config.plugins, baseFullConfig._plugins);
this._fullConfig.metadata = takeFirst(config.metadata, baseFullConfig.metadata);
this._fullConfig.projects = (config.projects || [config]).map(p => this._resolveProject(config, p, throwawayArtifactsPath));
}
@@ -246,10 +225,8 @@ export class Loader {
const result: SerializedLoaderData = {
configFile: this._configFile,
configDir: this._configDir,
- config: this._fullConfig,
+ configCLIOverrides: this._configCLIOverrides,
};
- if (process.env.PLAYWRIGHT_LEGACY_CONFIG_MODE)
- result.overridesForLegacyConfigMode = this._configCLIOverrides;
return result;
}
@@ -647,7 +624,6 @@ export const baseFullConfig: FullConfigInternal = {
_globalOutputDir: path.resolve(process.cwd()),
_configDir: '',
_testGroupsCount: 0,
- _plugins: [],
};
function resolveReporters(reporters: Config['reporter'], rootDir: string): ReporterDescription[]|undefined {
diff --git a/packages/playwright-test/src/plugins/gitCommitInfoPlugin.ts b/packages/playwright-test/src/plugins/gitCommitInfoPlugin.ts
index b0ae3ddaf4..2c0aacf09f 100644
--- a/packages/playwright-test/src/plugins/gitCommitInfoPlugin.ts
+++ b/packages/playwright-test/src/plugins/gitCommitInfoPlugin.ts
@@ -13,17 +13,19 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-import type { Config, TestPlugin } from '../types';
+
import { createGuid } from 'playwright-core/lib/utils';
import { spawnAsync } from 'playwright-core/lib/utils/spawnAsync';
+import type { TestRunnerPlugin } from './';
+import type { FullConfig } from '../../types/testReporter';
const GIT_OPERATIONS_TIMEOUT_MS = 1500;
-export const gitCommitInfo = (options?: GitCommitInfoPluginOptions): TestPlugin => {
+export const gitCommitInfo = (options?: GitCommitInfoPluginOptions): TestRunnerPlugin => {
return {
name: 'playwright:git-commit-info',
- configure: async (config: Config, configDir: string) => {
+ setup: async (config: FullConfig, configDir: string) => {
const info = {
...linksFromEnv(),
...options?.info ? options.info : await gitStatusFromCLI(options?.directory || configDir),
diff --git a/packages/playwright-test/src/plugins/index.ts b/packages/playwright-test/src/plugins/index.ts
index 999abdc782..6dab9bf383 100644
--- a/packages/playwright-test/src/plugins/index.ts
+++ b/packages/playwright-test/src/plugins/index.ts
@@ -13,5 +13,28 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
+import type { Suite } from '../../types/testReporter';
+import type { Runner } from '../runner';
+import type { FullConfig } from '../types';
+
+export interface TestRunnerPlugin {
+ name: string;
+ setup?(config: FullConfig, configDir: string, rootSuite: Suite): Promise<void>;
+ teardown?(): Promise<void>;
+}
+
export { webServer } from './webServerPlugin';
export { gitCommitInfo } from './gitCommitInfoPlugin';
+
+let runnerInstanceToAddPluginsTo: Runner | undefined;
+
+export const setRunnerToAddPluginsTo = (runner: Runner) => {
+ runnerInstanceToAddPluginsTo = runner;
+};
+
+export const addRunnerPlugin = (plugin: TestRunnerPlugin) => {
+ // Only present in runner, absent in worker.
+ if (runnerInstanceToAddPluginsTo)
+ runnerInstanceToAddPluginsTo.addPlugin(plugin);
+};
diff --git a/packages/playwright-test/src/plugins/vitePlugin.ts b/packages/playwright-test/src/plugins/vitePlugin.ts
index 325210cc29..d37c791007 100644
--- a/packages/playwright-test/src/plugins/vitePlugin.ts
+++ b/packages/playwright-test/src/plugins/vitePlugin.ts
@@ -14,38 +14,34 @@
* limitations under the License.
*/
-import type { PlaywrightTestConfig, TestPlugin } from '@playwright/test';
import fs from 'fs';
+import type { Suite } from '../../types/testReporter';
import path from 'path';
import type { InlineConfig, Plugin, ViteDevServer } from 'vite';
+import type { TestRunnerPlugin } from '.';
import { parse, traverse, types as t } from '../babelBundle';
import type { ComponentInfo } from '../tsxTransform';
import { collectComponentUsages, componentInfo } from '../tsxTransform';
+import type { FullConfig } from '../types';
let viteDevServer: ViteDevServer;
export function createPlugin(
registerFunction: string,
- frameworkPluginFactory: () => Plugin,
- options: {
- port?: number,
- config?: InlineConfig
- } = {}): TestPlugin {
- const viteConfig = options.config || {};
- const port = options.port || 3100;
+ frameworkPluginFactory: () => Plugin): TestRunnerPlugin {
let configDir: string;
return {
name: 'playwright-vite-plugin',
- configure: async (config: PlaywrightTestConfig, configDirectory: string) => {
+ setup: async (config: FullConfig, configDirectory: string, suite: Suite) => {
+ // TODO: declare and pick these from the config.
+ const viteConfig: InlineConfig = {};
+ const port = 3100;
+
configDir = configDirectory;
- const url = `http://localhost:${port}/playwright/index.html`;
- if (!config.use)
- config.use = {};
- config.use!.baseURL = url;
- },
- setup: async suite => {
+ process.env.PLAYWRIGHT_TEST_BASE_URL = `http://localhost:${port}/playwright/index.html`;
+
viteConfig.root = viteConfig.root || configDir;
viteConfig.plugins = viteConfig.plugins || [
frameworkPluginFactory()
diff --git a/packages/playwright-test/src/plugins/webServerPlugin.ts b/packages/playwright-test/src/plugins/webServerPlugin.ts
index 9e9dfa8f73..a7372d2573 100644
--- a/packages/playwright-test/src/plugins/webServerPlugin.ts
+++ b/packages/playwright-test/src/plugins/webServerPlugin.ts
@@ -22,8 +22,8 @@ import { debug } from 'playwright-core/lib/utilsBundle';
import { raceAgainstTimeout } from 'playwright-core/lib/utils/timeoutRunner';
import { launchProcess } from 'playwright-core/lib/utils/processLauncher';
-import type { PlaywrightTestConfig, TestPlugin } from '../types';
-import type { Reporter } from '../../types/testReporter';
+import type { FullConfig, Reporter } from '../../types/testReporter';
+import type { TestRunnerPlugin } from '.';
export type WebServerPluginOptions = {
@@ -42,7 +42,7 @@ const DEFAULT_ENVIRONMENT_VARIABLES = {
const debugWebServer = debug('pw:webserver');
-export class WebServerPlugin implements TestPlugin {
+export class WebServerPlugin implements TestRunnerPlugin {
private _isAvailable: () => Promise<boolean>;
private _killProcess?: () => Promise<void>;
private _processExitedPromise!: Promise<any>;
@@ -57,11 +57,8 @@ export class WebServerPlugin implements TestPlugin {
}
- public async configure(config: PlaywrightTestConfig, configDir: string) {
+ public async setup(config: FullConfig, configDir: string) {
this._options.cwd = this._options.cwd ? path.resolve(configDir, this._options.cwd) : configDir;
- }
-
- public async setup() {
try {
await this._startProcess();
await this._waitForProcess();
@@ -200,23 +197,23 @@ function getIsAvailableFunction(url: string, checkPortOnly: boolean, ignoreHTTPS
return () => isPortUsed(+port);
}
-export const webServer = (options: WebServerPluginOptions): TestPlugin => {
+export const webServer = (options: WebServerPluginOptions): TestRunnerPlugin => {
// eslint-disable-next-line no-console
return new WebServerPlugin(options, false, { onStdOut: d => console.log(d.toString()), onStdErr: d => console.error(d.toString()) });
};
-export const webServerPluginForConfig = (config: PlaywrightTestConfig): TestPlugin => {
+export const webServerPluginForConfig = (config: FullConfig, reporter: Reporter): TestRunnerPlugin => {
const webServer = config.webServer!;
if (webServer.port !== undefined && webServer.url !== undefined)
throw new Error(`Exactly one of 'port' or 'url' is required in config.webServer.`);
- if (webServer.port !== undefined && !config.use?.baseURL) {
- config.use = (config.use || {});
- config.use.baseURL = `http://localhost:${webServer.port}`;
- }
-
const url = webServer.url || `http://localhost:${webServer.port}`;
+
+ // We only set base url when only the port is given. That's a legacy mode we have regrets about.
+ if (!webServer.url)
+ process.env.PLAYWRIGHT_TEST_BASE_URL = url;
+
// TODO: replace with reporter once plugins are removed.
// eslint-disable-next-line no-console
- return new WebServerPlugin({ ...webServer, url }, webServer.port !== undefined, { onStdOut: d => console.log(d.toString()), onStdErr: d => console.error(d.toString()) });
+ return new WebServerPlugin({ ...webServer, url }, webServer.port !== undefined, reporter);
};
diff --git a/packages/playwright-test/src/runner.ts b/packages/playwright-test/src/runner.ts
index e2895cb329..e86a177b64 100644
--- a/packages/playwright-test/src/runner.ts
+++ b/packages/playwright-test/src/runner.ts
@@ -41,6 +41,9 @@ import type { Config, FullProjectInternal } from './types';
import type { FullConfigInternal } from './types';
import { raceAgainstTimeout } from 'playwright-core/lib/utils/timeoutRunner';
import { SigIntWatcher } from './sigIntWatcher';
+import type { TestRunnerPlugin } from './plugins';
+import { setRunnerToAddPluginsTo } from './plugins';
+import { webServerPluginForConfig } from './plugins/webServerPlugin';
const removeFolderAsync = promisify(rimraf);
const readDirAsync = promisify(fs.readdir);
@@ -76,9 +79,15 @@ export type ConfigCLIOverrides = {
export class Runner {
private _loader: Loader;
private _reporter!: Reporter;
+ private _plugins: TestRunnerPlugin[] = [];
constructor(configCLIOverrides?: ConfigCLIOverrides) {
this._loader = new Loader(configCLIOverrides);
+ setRunnerToAddPluginsTo(this);
+ }
+
+ addPlugin(plugin: TestRunnerPlugin) {
+ this._plugins.push(plugin);
}
async loadConfigFromResolvedFile(resolvedConfigFile: string): Promise<FullConfigInternal> {
@@ -448,10 +457,14 @@ export class Runner {
};
await this._runAndReportError(async () => {
+ // Legacy webServer support.
+ if (config.webServer)
+ this._plugins.push(webServerPluginForConfig(config, this._reporter));
+
// First run the plugins, if plugin is a web server we want it to run before the
// config's global setup.
- for (const plugin of config._plugins) {
- await plugin.setup?.(rootSuite);
+ for (const plugin of this._plugins) {
+ await plugin.setup?.(config, config._configDir, rootSuite);
if (plugin.teardown)
pluginTeardowns.unshift(plugin.teardown);
}
diff --git a/packages/playwright-test/src/types.ts b/packages/playwright-test/src/types.ts
index c5583805b9..f7a618d78f 100644
--- a/packages/playwright-test/src/types.ts
+++ b/packages/playwright-test/src/types.ts
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-import type { Fixtures, TestError, Project, TestPlugin } from '../types/test';
+import type { Fixtures, TestError, Project } from '../types/test';
import type { Location } from '../types/testReporter';
import type { FullConfig as FullConfigPublic, FullProject as FullProjectPublic } from './types';
export * from '../types/test';
@@ -41,14 +41,9 @@ export interface TestStepInternal {
* increasing the surface area of the public API type called FullConfig.
*/
export interface FullConfigInternal extends FullConfigPublic {
- /**
- * Location for GlobalInfo scoped data. This my differ from the projec-level outputDir
- * since GlobalInfo (and this config), only respect top-level configurations.
- */
_globalOutputDir: string;
_configDir: string;
_testGroupsCount: number;
- _plugins: TestPlugin[];
// Overrides the public field.
projects: FullProjectInternal[];
diff --git a/packages/playwright-test/types/test.d.ts b/packages/playwright-test/types/test.d.ts
index 3e57650f74..cbda622a44 100644
--- a/packages/playwright-test/types/test.d.ts
+++ b/packages/playwright-test/types/test.d.ts
@@ -688,8 +688,6 @@ interface TestConfig {
*/
snapshotDir?: string;
- plugins?: Array<TestPlugin>;
-
/**
* Whether to preserve test output in the
* [testConfig.outputDir](https://playwright.dev/docs/api/class-testconfig#test-config-output-dir). Defaults to `'always'`.
@@ -3527,23 +3525,6 @@ export interface TestError {
value?: string;
}
-export interface TestPlugin {
- name: string;
-
- /**
- * @param config
- * @param configDir
- */
- configure?(config: TestConfig, configDir: string): Promise<void>;
-
- /**
- * @param suite
- */
- setup?(suite: Suite): Promise<void>;
-
- teardown?(): Promise<void>;
-}
-
/**
* Playwright Test supports running multiple test projects at the same time. This is useful for running tests in multiple
* configurations. For example, consider running tests against multiple browsers.
diff --git a/packages/web/playwright.config.ts b/packages/web/playwright.config.ts
index 4efdf4e8b9..79961e4998 100644
--- a/packages/web/playwright.config.ts
+++ b/packages/web/playwright.config.ts
@@ -16,7 +16,6 @@
import type { PlaywrightTestConfig } from '@playwright/test';
import { devices } from '@playwright/test';
-import viteCT from '@playwright/experimental-ct-react/vitePlugin';
const config: PlaywrightTestConfig = {
testDir: 'src',
@@ -27,9 +26,6 @@ const config: PlaywrightTestConfig = {
] : [
['html', { open: 'on-failure' }]
],
- plugins: [
- viteCT({ port: 3101 })
- ],
use: {
trace: 'on-first-retry',
},
diff --git a/tests/android/playwright.config.ts b/tests/android/playwright.config.ts
index 42f55df5c3..15029ad768 100644
--- a/tests/android/playwright.config.ts
+++ b/tests/android/playwright.config.ts
@@ -20,16 +20,12 @@ loadEnv({ path: path.join(__dirname, '..', '..', '.env') });
import type { Config, PlaywrightTestOptions, PlaywrightWorkerOptions } from '@playwright/test';
import * as path from 'path';
import type { ServerWorkerOptions } from '../config/serverFixtures';
-import { gitCommitInfo } from '@playwright/test/lib/plugins';
process.env.PWPAGE_IMPL = 'android';
const outputDir = path.join(__dirname, '..', '..', 'test-results');
const testDir = path.join(__dirname, '..');
const config: Config<ServerWorkerOptions & PlaywrightWorkerOptions & PlaywrightTestOptions> = {
- plugins: [
- gitCommitInfo(),
- ],
testDir,
outputDir,
timeout: 120000,
diff --git a/tests/components/ct-react-vite/playwright.config.ts b/tests/components/ct-react-vite/playwright.config.ts
index 7bb9b2e316..4cf7b00732 100644
--- a/tests/components/ct-react-vite/playwright.config.ts
+++ b/tests/components/ct-react-vite/playwright.config.ts
@@ -15,20 +15,12 @@
*/
import { PlaywrightTestConfig, devices } from '@playwright/test';
-import viteCT from '@playwright/experimental-ct-react/vitePlugin';
const config: PlaywrightTestConfig = {
testDir: 'src',
forbidOnly: !!process.env.CI,
retries: process.env.CI ? 2 : 0,
- reporter: process.env.CI ? [
- ['html', { open: 'never' }],
- ] : [
- ['html', { open: 'on-failure' }]
- ],
- plugins: [
- viteCT(),
- ],
+ reporter: 'html',
use: {
trace: 'on-first-retry',
},
diff --git a/tests/components/ct-react/playwright.config.ts b/tests/components/ct-react/playwright.config.ts
index 7bb9b2e316..4cf7b00732 100644
--- a/tests/components/ct-react/playwright.config.ts
+++ b/tests/components/ct-react/playwright.config.ts
@@ -15,20 +15,12 @@
*/
import { PlaywrightTestConfig, devices } from '@playwright/test';
-import viteCT from '@playwright/experimental-ct-react/vitePlugin';
const config: PlaywrightTestConfig = {
testDir: 'src',
forbidOnly: !!process.env.CI,
retries: process.env.CI ? 2 : 0,
- reporter: process.env.CI ? [
- ['html', { open: 'never' }],
- ] : [
- ['html', { open: 'on-failure' }]
- ],
- plugins: [
- viteCT(),
- ],
+ reporter: 'html',
use: {
trace: 'on-first-retry',
},
diff --git a/tests/components/ct-svelte-kit/playwright.config.ts b/tests/components/ct-svelte-kit/playwright.config.ts
index 58798ed39d..fcb57e200d 100644
--- a/tests/components/ct-svelte-kit/playwright.config.ts
+++ b/tests/components/ct-svelte-kit/playwright.config.ts
@@ -16,20 +16,12 @@
import type { PlaywrightTestConfig } from '@playwright/test';
import { devices } from '@playwright/test';
-import viteCT from '@playwright/experimental-ct-svelte/vitePlugin';
const config: PlaywrightTestConfig = {
testDir: 'src',
forbidOnly: !!process.env.CI,
retries: process.env.CI ? 2 : 0,
- reporter: process.env.CI ? [
- ['html', { open: 'never' }],
- ] : [
- ['html', { open: 'on-failure' }]
- ],
- plugins: [
- viteCT(),
- ],
+ reporter: 'html',
use: {
trace: 'on-first-retry',
},
diff --git a/tests/components/ct-svelte-vite/playwright.config.ts b/tests/components/ct-svelte-vite/playwright.config.ts
index 58798ed39d..fcb57e200d 100644
--- a/tests/components/ct-svelte-vite/playwright.config.ts
+++ b/tests/components/ct-svelte-vite/playwright.config.ts
@@ -16,20 +16,12 @@
import type { PlaywrightTestConfig } from '@playwright/test';
import { devices } from '@playwright/test';
-import viteCT from '@playwright/experimental-ct-svelte/vitePlugin';
const config: PlaywrightTestConfig = {
testDir: 'src',
forbidOnly: !!process.env.CI,
retries: process.env.CI ? 2 : 0,
- reporter: process.env.CI ? [
- ['html', { open: 'never' }],
- ] : [
- ['html', { open: 'on-failure' }]
- ],
- plugins: [
- viteCT(),
- ],
+ reporter: 'html',
use: {
trace: 'on-first-retry',
},
diff --git a/tests/components/ct-svelte/playwright.config.ts b/tests/components/ct-svelte/playwright.config.ts
index 58798ed39d..fcb57e200d 100644
--- a/tests/components/ct-svelte/playwright.config.ts
+++ b/tests/components/ct-svelte/playwright.config.ts
@@ -16,20 +16,12 @@
import type { PlaywrightTestConfig } from '@playwright/test';
import { devices } from '@playwright/test';
-import viteCT from '@playwright/experimental-ct-svelte/vitePlugin';
const config: PlaywrightTestConfig = {
testDir: 'src',
forbidOnly: !!process.env.CI,
retries: process.env.CI ? 2 : 0,
- reporter: process.env.CI ? [
- ['html', { open: 'never' }],
- ] : [
- ['html', { open: 'on-failure' }]
- ],
- plugins: [
- viteCT(),
- ],
+ reporter: 'html',
use: {
trace: 'on-first-retry',
},
diff --git a/tests/components/ct-vue-cli/playwright.config.ts b/tests/components/ct-vue-cli/playwright.config.ts
index 7c86ee5d6f..4cf7b00732 100644
--- a/tests/components/ct-vue-cli/playwright.config.ts
+++ b/tests/components/ct-vue-cli/playwright.config.ts
@@ -15,20 +15,12 @@
*/
import { PlaywrightTestConfig, devices } from '@playwright/test';
-import viteCT from '@playwright/experimental-ct-vue/vitePlugin';
const config: PlaywrightTestConfig = {
testDir: 'src',
forbidOnly: !!process.env.CI,
retries: process.env.CI ? 2 : 0,
- reporter: process.env.CI ? [
- ['html', { open: 'never' }],
- ] : [
- ['html', { open: 'on-failure' }]
- ],
- plugins: [
- viteCT(),
- ],
+ reporter: 'html',
use: {
trace: 'on-first-retry',
},
diff --git a/tests/components/ct-vue-vite/playwright.config.ts b/tests/components/ct-vue-vite/playwright.config.ts
index 7c86ee5d6f..4cf7b00732 100644
--- a/tests/components/ct-vue-vite/playwright.config.ts
+++ b/tests/components/ct-vue-vite/playwright.config.ts
@@ -15,20 +15,12 @@
*/
import { PlaywrightTestConfig, devices } from '@playwright/test';
-import viteCT from '@playwright/experimental-ct-vue/vitePlugin';
const config: PlaywrightTestConfig = {
testDir: 'src',
forbidOnly: !!process.env.CI,
retries: process.env.CI ? 2 : 0,
- reporter: process.env.CI ? [
- ['html', { open: 'never' }],
- ] : [
- ['html', { open: 'on-failure' }]
- ],
- plugins: [
- viteCT(),
- ],
+ reporter: 'html',
use: {
trace: 'on-first-retry',
},
diff --git a/tests/config/experimental.d.ts b/tests/config/experimental.d.ts
index bc1920b4c3..74735b74a5 100644
--- a/tests/config/experimental.d.ts
+++ b/tests/config/experimental.d.ts
@@ -17395,8 +17395,6 @@ interface TestConfig {
*/
snapshotDir?: string;
- plugins?: Array<TestPlugin>;
-
/**
* Whether to preserve test output in the
* [testConfig.outputDir](https://playwright.dev/docs/api/class-testconfig#test-config-output-dir). Defaults to `'always'`.
@@ -20458,23 +20456,6 @@ export interface TestError {
value?: string;
}
-export interface TestPlugin {
- name: string;
-
- /**
- * @param config
- * @param configDir
- */
- configure?(config: TestConfig, configDir: string): Promise<void>;
-
- /**
- * @param suite
- */
- setup?(suite: Suite): Promise<void>;
-
- teardown?(): Promise<void>;
-}
-
/**
* Playwright Test supports running multiple test projects at the same time. This is useful for running tests in multiple
* configurations. For example, consider running tests against multiple browsers.
diff --git a/tests/electron/playwright.config.ts b/tests/electron/playwright.config.ts
index bd717461fd..645aa28ee4 100644
--- a/tests/electron/playwright.config.ts
+++ b/tests/electron/playwright.config.ts
@@ -20,16 +20,12 @@ loadEnv({ path: path.join(__dirname, '..', '..', '.env') });
import type { Config, PlaywrightTestOptions, PlaywrightWorkerOptions } from '@playwright/test';
import * as path from 'path';
import type { CoverageWorkerOptions } from '../config/coverageFixtures';
-import { gitCommitInfo } from '@playwright/test/lib/plugins';
process.env.PWPAGE_IMPL = 'electron';
const outputDir = path.join(__dirname, '..', '..', 'test-results');
const testDir = path.join(__dirname, '..');
const config: Config<CoverageWorkerOptions & PlaywrightWorkerOptions & PlaywrightTestOptions> = {
- plugins: [
- gitCommitInfo(),
- ],
testDir,
outputDir,
timeout: 30000,
diff --git a/tests/installation/playwright.config.ts b/tests/installation/playwright.config.ts
index bc406adf94..62f0a8348c 100644
--- a/tests/installation/playwright.config.ts
+++ b/tests/installation/playwright.config.ts
@@ -19,12 +19,7 @@ import type { PlaywrightTestConfig } from '@playwright/test';
import { config as loadEnv } from 'dotenv';
loadEnv({ path: path.join(__dirname, '..', '..', '.env') });
-import { gitCommitInfo } from '@playwright/test/lib/plugins';
-
const config: PlaywrightTestConfig = {
- plugins: [
- gitCommitInfo(),
- ],
globalSetup: path.join(__dirname, 'globalSetup'),
testIgnore: '**\/fixture-scripts/**',
timeout: 5 * 60 * 1000,
diff --git a/tests/library/playwright.config.ts b/tests/library/playwright.config.ts
index 9ad08996fa..679a84738e 100644
--- a/tests/library/playwright.config.ts
+++ b/tests/library/playwright.config.ts
@@ -21,7 +21,6 @@ import type { Config, PlaywrightTestOptions, PlaywrightWorkerOptions } from '@pl
import * as path from 'path';
import type { TestModeWorkerOptions } from '../config/testModeFixtures';
import type { CoverageWorkerOptions } from '../config/coverageFixtures';
-import { gitCommitInfo } from '@playwright/test/lib/plugins';
type BrowserName = 'chromium' | 'firefox' | 'webkit';
@@ -45,9 +44,6 @@ const trace = !!process.env.PWTEST_TRACE;
const outputDir = path.join(__dirname, '..', '..', 'test-results');
const testDir = path.join(__dirname, '..');
const config: Config<CoverageWorkerOptions & PlaywrightWorkerOptions & PlaywrightTestOptions & TestModeWorkerOptions> = {
- plugins: [
- gitCommitInfo(),
- ],
testDir,
outputDir,
expect: {
diff --git a/tests/playwright-test/playwright-test-fixtures.ts b/tests/playwright-test/playwright-test-fixtures.ts
index a3be3540cf..0277e9845e 100644
--- a/tests/playwright-test/playwright-test-fixtures.ts
+++ b/tests/playwright-test/playwright-test-fixtures.ts
@@ -215,7 +215,6 @@ type RunOptions = {
cwd?: string,
};
type Fixtures = {
- legacyConfigLoader: boolean;
writeFiles: (files: Files) => Promise<string>;
runInlineTest: (files: Files, params?: Params, env?: Env, options?: RunOptions, beforeRunPlaywrightTest?: ({ baseDir }: { baseDir: string }) => Promise<void>) => Promise<RunResult>;
runTSC: (files: Files) => Promise<TSCResult>;
@@ -225,19 +224,15 @@ export const test = base
.extend<CommonFixtures>(commonFixtures)
.extend<ServerFixtures, ServerWorkerOptions>(serverFixtures)
.extend<Fixtures>({
- legacyConfigLoader: [false, { option: true }],
-
writeFiles: async ({}, use, testInfo) => {
await use(files => writeFiles(testInfo, files));
},
- runInlineTest: async ({ childProcess, legacyConfigLoader }, use, testInfo: TestInfo) => {
+ runInlineTest: async ({ childProcess }, use, testInfo: TestInfo) => {
await use(async (files: Files, params: Params = {}, env: Env = {}, options: RunOptions = {}, beforeRunPlaywrightTest?: ({ baseDir: string }) => Promise<void>) => {
const baseDir = await writeFiles(testInfo, files);
if (beforeRunPlaywrightTest)
await beforeRunPlaywrightTest({ baseDir });
- if (legacyConfigLoader)
- env = { ...env, PLAYWRIGHT_LEGACY_CONFIG_MODE: '1' };
return await runPlaywrightTest(childProcess, baseDir, params, env, options);
});
},
diff --git a/tests/playwright-test/playwright.config.ts b/tests/playwright-test/playwright.config.ts
index 8ef397e238..d9880ed624 100644
--- a/tests/playwright-test/playwright.config.ts
+++ b/tests/playwright-test/playwright.config.ts
@@ -32,10 +32,6 @@ const config: Config = {
{
name: 'playwright-test'
},
- {
- name: 'playwright-test-legacy-config',
- use: { legacyConfigLoader: true },
- } as any,
],
reporter: process.env.CI ? [
['dot'],
diff --git a/tests/playwright-test/playwright.connect.spec.ts b/tests/playwright-test/playwright.connect.spec.ts
index cdf9481c50..143a2db790 100644
--- a/tests/playwright-test/playwright.connect.spec.ts
+++ b/tests/playwright-test/playwright.connect.spec.ts
@@ -16,8 +16,7 @@
import { test, expect } from './playwright-test-fixtures';
-test('should work with connectOptions (legacy)', async ({ runInlineTest, legacyConfigLoader }) => {
- test.skip(!legacyConfigLoader, 'Not supported in the new mode');
+test('should work with connectOptions', async ({ runInlineTest }) => {
const result = await runInlineTest({
'playwright.config.js': `
module.exports = {
@@ -50,42 +49,6 @@ test('should work with connectOptions (legacy)', async ({ runInlineTest, legacyC
expect(result.passed).toBe(1);
});
-test('should work with connectOptions', async ({ runInlineTest }) => {
- const result = await runInlineTest({
- 'playwright.config.js': `
- module.exports = { plugins: [require('./plugin')] };
- `,
- 'plugin.js': `
- let server;
- module.exports = {
- configure: async (config) => {
- server = await pwt.chromium.launchServer();
- config.use = {
- connectOptions: {
- wsEndpoint: server.wsEndpoint()
- }
- };
- },
-
- teardown: async () => {
- await server.close();
- }
- };
- `,
- 'a.test.ts': `
- const { test } = pwt;
- test.use({ locale: 'fr-CH' });
- test('pass', async ({ page }) => {
- await page.setContent('<div>PASS</div>');
- await expect(page.locator('div')).toHaveText('PASS');
- expect(await page.evaluate(() => navigator.language)).toBe('fr-CH');
- });
- `,
- });
- expect(result.exitCode).toBe(0);
- expect(result.passed).toBe(1);
-});
-
test('should throw with bad connectOptions', async ({ runInlineTest }) => {
const result = await runInlineTest({
'playwright.config.js': `
diff --git a/tests/playwright-test/plugins.spec.ts b/tests/playwright-test/plugins.spec.ts
deleted file mode 100644
index 1ccee77738..0000000000
--- a/tests/playwright-test/plugins.spec.ts
+++ /dev/null
@@ -1,97 +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 { test, expect } from './playwright-test-fixtures';
-
-test('event order', async ({ runInlineTest, legacyConfigLoader }, testInfo) => {
- test.skip(legacyConfigLoader);
- const log = testInfo.outputPath('logs.txt');
- const result = await runInlineTest({
- 'log.ts': `
- import { appendFileSync } from 'fs';
- const log = (...args) => appendFileSync('${log.replace(/\\/g, '\\\\')}', args.join(' ') + '\\n');
- export default log;
- `,
- 'test.spec.ts': `
- import log from './log';
- const { test } = pwt;
- test('it works', async ({baseURL}) => {
- log('baseURL', baseURL);
- });
- `,
- 'playwright.config.ts': `
- import { myPlugin } from './plugin.ts';
- module.exports = {
- plugins: [
- myPlugin('a'),
- myPlugin('b'),
- ],
- globalSetup: 'globalSetup.ts',
- globalTeardown: 'globalTeardown.ts',
- };
- `,
- 'globalSetup.ts': `
- import log from './log';
- const setup = async () => {
- await new Promise(r => setTimeout(r, 100));
- log('globalSetup');
- }
- export default setup;
- `,
- 'globalTeardown.ts': `
- import log from './log';
- const teardown = async () => {
- await new Promise(r => setTimeout(r, 100));
- log('globalTeardown');
- }
- export default teardown;
- `,
- 'plugin.ts': `
- import log from './log';
- export const myPlugin = (name: string) => ({
- configure: async (config) => {
- await new Promise(r => setTimeout(r, 100));
- log(name, 'configure');
- config.use = (config.use || {});
- config.use.baseURL = (config.use.baseURL || '') + name + ' | ';
- },
- setup: async () => {
- await new Promise(r => setTimeout(r, 100));
- log(name, 'setup');
- },
- teardown: async () => {
- await new Promise(r => setTimeout(r, 100));
- log(name, 'teardown');
- },
- });
- `,
- });
- expect(result.exitCode).toBe(0);
- expect(result.passed).toBe(1);
- const logLines = await fs.promises.readFile(log, 'utf8');
- expect(logLines.split('\n')).toEqual([
- 'a configure',
- 'b configure',
- 'a setup',
- 'b setup',
- 'globalSetup',
- 'baseURL a | b | ',
- 'globalTeardown',
- 'b teardown',
- 'a teardown',
- '',
- ]);
-});
diff --git a/tests/playwright-test/reporter-html.spec.ts b/tests/playwright-test/reporter-html.spec.ts
index 3de4c993ea..b865cf38c7 100644
--- a/tests/playwright-test/reporter-html.spec.ts
+++ b/tests/playwright-test/reporter-html.spec.ts
@@ -723,18 +723,11 @@ test.describe('gitCommitInfo plugin', () => {
const result = await runInlineTest({
'uncommitted.txt': `uncommitted file`,
- 'playwright.config.ts': `
- import path from 'path';
- import { gitCommitInfo } from '@playwright/test/lib/plugins';
-
- const config = {
- plugins: [ gitCommitInfo() ],
- }
-
- export default config;
- `,
+ 'playwright.config.ts': `export default {};`,
'example.spec.ts': `
- const { test } = pwt;
+ import { gitCommitInfo } from '@playwright/test/lib/plugins';
+ const { test, _addRunnerPlugin } = pwt;
+ _addRunnerPlugin(gitCommitInfo());
test('sample', async ({}) => { expect(2).toBe(2); });
`,
}, { reporter: 'dot,html' }, { PW_TEST_HTML_REPORT_OPEN: 'never', GITHUB_REPOSITORY: 'microsoft/playwright-example-for-test', GITHUB_RUN_ID: 'example-run-id', GITHUB_SERVER_URL: 'https://playwright.dev', GITHUB_SHA: 'example-sha' }, undefined, beforeRunPlaywrightTest);
@@ -760,25 +753,20 @@ test.describe('gitCommitInfo plugin', () => {
const result = await runInlineTest({
'uncommitted.txt': `uncommitted file`,
'playwright.config.ts': `
- import path from 'path';
- import { gitCommitInfo } from '@playwright/test/lib/plugins';
-
- const config = {
- plugins: [ gitCommitInfo({
- info: {
- 'revision.id': '1234567890',
- 'revision.subject': 'a better subject',
- 'revision.timestamp': new Date(),
- 'revision.author': 'William',
- 'revision.email': '[email protected]',
- },
- }) ],
- }
-
- export default config;
+ export default {};
`,
'example.spec.ts': `
- const { test } = pwt;
+ import { gitCommitInfo } from '@playwright/test/lib/plugins';
+ const { test, _addRunnerPlugin } = pwt;
+ _addRunnerPlugin(gitCommitInfo({
+ info: {
+ 'revision.id': '1234567890',
+ 'revision.subject': 'a better subject',
+ 'revision.timestamp': new Date(),
+ 'revision.author': 'William',
+ 'revision.email': '[email protected]',
+ },
+ }));
test('sample', async ({}) => { expect(2).toBe(2); });
`,
}, { reporter: 'dot,html' }, { PW_TEST_HTML_REPORT_OPEN: 'never', GITHUB_REPOSITORY: 'microsoft/playwright-example-for-test', GITHUB_RUN_ID: 'example-run-id', GITHUB_SERVER_URL: 'https://playwright.dev', GITHUB_SHA: 'example-sha' }, undefined);
@@ -803,13 +791,7 @@ test.describe('gitCommitInfo plugin', () => {
const result = await runInlineTest({
'uncommitted.txt': `uncommitted file`,
'playwright.config.ts': `
- import path from 'path';
-
- const config = {
- plugins: [],
- }
-
- export default config;
+ export default {};
`,
'example.spec.ts': `
const { test } = pwt;
@@ -829,15 +811,11 @@ test.describe('gitCommitInfo plugin', () => {
const result = await runInlineTest({
'uncommitted.txt': `uncommitted file`,
'playwright.config.ts': `
- import path from 'path';
-
- const config = {
+ export default {
metadata: {
'revision.timestamp': 'hi',
},
- }
-
- export default config;
+ };
`,
'example.spec.ts': `
const { test } = pwt;
diff --git a/tests/playwright-test/web-server.spec.ts b/tests/playwright-test/web-server.spec.ts
index 6b0791d205..96f2f97beb 100644
--- a/tests/playwright-test/web-server.spec.ts
+++ b/tests/playwright-test/web-server.spec.ts
@@ -415,14 +415,14 @@ test(`should suport self signed certificate`, async ({ runInlineTest, httpsServe
test('pass', async ({}) => { });
`,
'playwright.config.js': `
- module.exports = {
- webServer: {
- url: '${httpsServer.EMPTY_PAGE}',
- ignoreHTTPSErrors: true,
- reuseExistingServer: true,
- },
- };
- `,
+ module.exports = {
+ webServer: {
+ url: '${httpsServer.EMPTY_PAGE}',
+ ignoreHTTPSErrors: true,
+ reuseExistingServer: true,
+ },
+ };
+ `,
});
expect(result.exitCode).toBe(0);
});
@@ -431,7 +431,17 @@ test('should create multiple servers', async ({ runInlineTest }, { workerIndex }
const port = workerIndex + 10500;
const result = await runInlineTest({
'test.spec.ts': `
- const { test } = pwt;
+ 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',
+ }));
+ _addRunnerPlugin(webServer({
+ command: 'node ${JSON.stringify(SIMPLE_SERVER_PATH)} ${port + 1}',
+ url: 'http://localhost:${port + 1}/port',
+ }));
+
test('connect to the server', async ({page}) => {
await page.goto('http://localhost:${port}/port');
await page.locator('text=${port}');
@@ -441,48 +451,37 @@ test('should create multiple servers', async ({ runInlineTest }, { workerIndex }
});
`,
'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',
- }),
- webServer({
- command: 'node ${JSON.stringify(SIMPLE_SERVER_PATH)} ${port + 1}',
- url: 'http://localhost:${port + 1}/port',
- }),
- ],
- globalSetup: 'globalSetup.ts',
- globalTeardown: 'globalTeardown.ts',
- };
+ globalSetup: 'globalSetup.ts',
+ globalTeardown: 'globalTeardown.ts',
+ };
`,
'globalSetup.ts': `
- module.exports = async () => {
- const http = require("http");
+ module.exports = async () => {
+ const http = require("http");
+ const response = await new Promise(resolve => {
+ const request = http.request("http://localhost:${port}/hello", resolve);
+ request.end();
+ })
+ console.log('globalSetup-status-'+response.statusCode)
+ return async () => {
const response = await new Promise(resolve => {
const request = http.request("http://localhost:${port}/hello", resolve);
request.end();
})
- console.log('globalSetup-status-'+response.statusCode)
- return async () => {
- const response = await new Promise(resolve => {
- const request = http.request("http://localhost:${port}/hello", resolve);
- request.end();
- })
- console.log('globalSetup-teardown-status-'+response.statusCode)
- };
+ console.log('globalSetup-teardown-status-'+response.statusCode)
};
+ };
`,
'globalTeardown.ts': `
- module.exports = async () => {
- const http = require("http");
- const response = await new Promise(resolve => {
- const request = http.request("http://localhost:${port}/hello", resolve);
- request.end();
- })
- console.log('globalTeardown-status-'+response.statusCode)
- };
+ module.exports = async () => {
+ const http = require("http");
+ const response = await new Promise(resolve => {
+ const request = http.request("http://localhost:${port}/hello", resolve);
+ request.end();
+ })
+ console.log('globalTeardown-status-'+response.statusCode)
+ };
`,
}, undefined, { DEBUG: 'pw:webserver' });
expect(result.exitCode).toBe(0);
@@ -504,22 +503,17 @@ test.describe('baseURL with plugins', () => {
const port = workerIndex + 10500;
const result = await runInlineTest({
'test.spec.ts': `
- const { test } = pwt;
+ 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();
});
- `,
- '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);
@@ -529,20 +523,18 @@ test.describe('baseURL with plugins', () => {
const port = workerIndex + 10500;
const result = await runInlineTest({
'test.spec.ts': `
- const { test } = pwt;
+ 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}');
});
`,
'playwright.config.ts': `
- import { webServer } from '@playwright/test/lib/plugins';
module.exports = {
- plugins: [
- webServer({
- command: 'node ${JSON.stringify(SIMPLE_SERVER_PATH)} ${port + 1}',
- url: 'http://localhost:${port + 1}/port'
- }),
- ],
webServer: {
command: 'node ${JSON.stringify(SIMPLE_SERVER_PATH)} ${port}',
port: ${port},