This commit is contained in:
parent
128b2ff1d5
commit
d7ad0a0180
|
|
@ -15,8 +15,8 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const pwt = require('./lib/index');
|
const pwt = require('./lib/index');
|
||||||
|
const { defineConfig } = require('./lib/common/configLoader');
|
||||||
const playwright = require('playwright-core');
|
const playwright = require('playwright-core');
|
||||||
const defineConfig = config => config;
|
|
||||||
const combinedExports = {
|
const combinedExports = {
|
||||||
...playwright,
|
...playwright,
|
||||||
...pwt,
|
...pwt,
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,12 @@ import { errorWithFile, getPackageJsonPath, mergeObjects } from '../util';
|
||||||
|
|
||||||
export const defaultTimeout = 30000;
|
export const defaultTimeout = 30000;
|
||||||
|
|
||||||
|
const kDefineConfigWasUsed = Symbol('defineConfigWasUsed');
|
||||||
|
export const defineConfig = (config: any) => {
|
||||||
|
config[kDefineConfigWasUsed] = true;
|
||||||
|
return config;
|
||||||
|
};
|
||||||
|
|
||||||
export class ConfigLoader {
|
export class ConfigLoader {
|
||||||
private _fullConfig: FullConfigInternal;
|
private _fullConfig: FullConfigInternal;
|
||||||
|
|
||||||
|
|
@ -122,6 +128,7 @@ export class ConfigLoader {
|
||||||
this._fullConfig._internal.ignoreSnapshots = takeFirst(config.ignoreSnapshots, baseFullConfig._internal.ignoreSnapshots);
|
this._fullConfig._internal.ignoreSnapshots = takeFirst(config.ignoreSnapshots, baseFullConfig._internal.ignoreSnapshots);
|
||||||
this._fullConfig.updateSnapshots = takeFirst(config.updateSnapshots, baseFullConfig.updateSnapshots);
|
this._fullConfig.updateSnapshots = takeFirst(config.updateSnapshots, baseFullConfig.updateSnapshots);
|
||||||
this._fullConfig._internal.plugins = ((config as any)._plugins || []).map((p: any) => ({ factory: p }));
|
this._fullConfig._internal.plugins = ((config as any)._plugins || []).map((p: any) => ({ factory: p }));
|
||||||
|
this._fullConfig._internal.defineConfigWasUsed = !!(config as any)[kDefineConfigWasUsed];
|
||||||
|
|
||||||
const workers = takeFirst(config.workers, '50%');
|
const workers = takeFirst(config.workers, '50%');
|
||||||
if (typeof workers === 'string') {
|
if (typeof workers === 'string') {
|
||||||
|
|
@ -454,6 +461,7 @@ export const baseFullConfig: FullConfigInternal = {
|
||||||
cliGrep: undefined,
|
cliGrep: undefined,
|
||||||
cliGrepInvert: undefined,
|
cliGrepInvert: undefined,
|
||||||
listOnly: false,
|
listOnly: false,
|
||||||
|
defineConfigWasUsed: false,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,7 @@ type ConfigInternal = {
|
||||||
cliProjectFilter?: string[];
|
cliProjectFilter?: string[];
|
||||||
testIdMatcher?: Matcher;
|
testIdMatcher?: Matcher;
|
||||||
passWithNoTests?: boolean;
|
passWithNoTests?: boolean;
|
||||||
|
defineConfigWasUsed: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import type { Fixtures, Locator, Page, BrowserContextOptions, PlaywrightTestArgs, PlaywrightTestOptions, PlaywrightWorkerArgs, PlaywrightWorkerOptions, BrowserContext, ContextReuseMode } from './common/types';
|
import type { Fixtures, Locator, Page, BrowserContextOptions, PlaywrightTestArgs, PlaywrightTestOptions, PlaywrightWorkerArgs, PlaywrightWorkerOptions, BrowserContext, ContextReuseMode, FullConfigInternal } from './common/types';
|
||||||
import type { Component, JsxComponent, MountOptions } from '../types/component';
|
import type { Component, JsxComponent, MountOptions } from '../types/component';
|
||||||
|
|
||||||
let boundCallbacksForMount: Function[] = [];
|
let boundCallbacksForMount: Function[] = [];
|
||||||
|
|
@ -37,7 +37,9 @@ export const fixtures: Fixtures<
|
||||||
|
|
||||||
_ctWorker: [{ context: undefined, hash: '' }, { scope: 'worker' }],
|
_ctWorker: [{ context: undefined, hash: '' }, { scope: 'worker' }],
|
||||||
|
|
||||||
page: async ({ page }, use) => {
|
page: async ({ page }, use, info) => {
|
||||||
|
if (!(info.config as FullConfigInternal)._internal.defineConfigWasUsed)
|
||||||
|
throw new Error('Component testing requires the use of the defineConfig() in your playwright-ct.config.{ts,js}: https://aka.ms/playwright/ct-define-config');
|
||||||
await (page as any)._wrapApiCall(async () => {
|
await (page as any)._wrapApiCall(async () => {
|
||||||
await page.exposeFunction('__ct_dispatch', (ordinal: number, args: any[]) => {
|
await page.exposeFunction('__ct_dispatch', (ordinal: number, args: any[]) => {
|
||||||
boundCallbacksForMount[ordinal](...args);
|
boundCallbacksForMount[ordinal](...args);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue