Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cherry-pick(#21318): chore: have pretty error if CT config has no defineConfig #21321

Merged
merged 1 commit into from
Mar 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/playwright-test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
*/

const pwt = require('./lib/index');
const { defineConfig } = require('./lib/common/configLoader');
const playwright = require('playwright-core');
const defineConfig = config => config;
const combinedExports = {
...playwright,
...pwt,
Expand Down
8 changes: 8 additions & 0 deletions packages/playwright-test/src/common/configLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ import { errorWithFile, getPackageJsonPath, mergeObjects } from '../util';

export const defaultTimeout = 30000;

const kDefineConfigWasUsed = Symbol('defineConfigWasUsed');
export const defineConfig = (config: any) => {
config[kDefineConfigWasUsed] = true;
return config;
};

export class ConfigLoader {
private _fullConfig: FullConfigInternal;

Expand Down Expand Up @@ -122,6 +128,7 @@ export class ConfigLoader {
this._fullConfig._internal.ignoreSnapshots = takeFirst(config.ignoreSnapshots, baseFullConfig._internal.ignoreSnapshots);
this._fullConfig.updateSnapshots = takeFirst(config.updateSnapshots, baseFullConfig.updateSnapshots);
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%');
if (typeof workers === 'string') {
Expand Down Expand Up @@ -454,6 +461,7 @@ export const baseFullConfig: FullConfigInternal = {
cliGrep: undefined,
cliGrepInvert: undefined,
listOnly: false,
defineConfigWasUsed: false,
}
};

Expand Down
1 change: 1 addition & 0 deletions packages/playwright-test/src/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type ConfigInternal = {
cliProjectFilter?: string[];
testIdMatcher?: Matcher;
passWithNoTests?: boolean;
defineConfigWasUsed: boolean;
};

/**
Expand Down
6 changes: 4 additions & 2 deletions packages/playwright-test/src/mount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* 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';

let boundCallbacksForMount: Function[] = [];
Expand All @@ -37,7 +37,9 @@ export const fixtures: Fixtures<

_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.exposeFunction('__ct_dispatch', (ordinal: number, args: any[]) => {
boundCallbacksForMount[ordinal](...args);
Expand Down