chore: hide plugins for now (#13908)

This commit is contained in:
Pavel Feldman 2022-05-03 13:25:56 -08:00 committed by GitHub
parent 85b86e19b8
commit 29fd1d86df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
46 changed files with 184 additions and 632 deletions

View File

@ -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">>

View File

@ -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

View File

@ -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',
},

View File

@ -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',
},

View File

@ -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",

View File

@ -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) => {

View File

@ -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;

View File

@ -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);
};

View File

@ -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",

View File

@ -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) => {

View File

@ -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;

View File

@ -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);
};

View File

@ -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",

View File

@ -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) => {

View File

@ -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;

View File

@ -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);
};

View File

@ -3,4 +3,5 @@
matchers/
reporters/
third_party/
plugins/
plugins/webServerPlugin.ts

View File

@ -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__']) {

View File

@ -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 = {

View File

@ -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 {

View File

@ -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),

View File

@ -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);
};

View File

@ -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) => {
configDir = configDirectory;
const url = `http://localhost:${port}/playwright/index.html`;
if (!config.use)
config.use = {};
config.use!.baseURL = url;
},
setup: async (config: FullConfig, configDirectory: string, suite: Suite) => {
// TODO: declare and pick these from the config.
const viteConfig: InlineConfig = {};
const port = 3100;
configDir = configDirectory;
process.env.PLAYWRIGHT_TEST_BASE_URL = `http://localhost:${port}/playwright/index.html`;
setup: async suite => {
viteConfig.root = viteConfig.root || configDir;
viteConfig.plugins = viteConfig.plugins || [
frameworkPluginFactory()

View File

@ -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);
};

View File

@ -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);
}

View File

@ -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[];

View File

@ -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.

View File

@ -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',
},

View File

@ -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,

View File

@ -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',
},

View File

@ -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',
},

View File

@ -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',
},

View File

@ -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',
},

View File

@ -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',
},

View File

@ -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',
},

View File

@ -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',
},

View File

@ -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.

View File

@ -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,

View File

@ -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,

View File

@ -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: {

View File

@ -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);
});
},

View File

@ -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'],

View File

@ -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': `

View File

@ -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',
'',
]);
});

View File

@ -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': 'shakespeare@example.local',
},
}) ],
}
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': 'shakespeare@example.local',
},
}));
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;

View File

@ -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},