Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
chore: revert isDevMode into isUnderTest (#3785)
Pavel Feldmanc83b2da54fda
diff --git a/index.js b/index.jsindex 61a3b0bd1d..814b04276e 100644--- a/index.js+++ b/index.js@@ -14,8 +14,8 @@* limitations under the License.*/-const { setDevMode } = require('./lib/utils/utils');-setDevMode(); // Note: we must call setDevMode before initializing.+const { setUnderTest } = require('./lib/utils/utils');+setUnderTest(); // Note: we must call setUnderTest before initializing.const { Playwright } = require('./lib/server/playwright');const { Electron } = require('./lib/server/electron/electron');diff --git a/src/client/browserContext.ts b/src/client/browserContext.tsindex c3a2791393..bddc1b8205 100644--- a/src/client/browserContext.ts+++ b/src/client/browserContext.ts@@ -26,7 +26,7 @@ import { Events } from './events';import { TimeoutSettings } from '../utils/timeoutSettings';import { Waiter } from './waiter';import { URLMatch, Headers, WaitForEventOptions } from './types';-import { isDevMode, headersObjectToArray } from '../utils/utils';+import { isUnderTest, headersObjectToArray } from '../utils/utils';export class BrowserContext extends ChannelOwner<channels.BrowserContextChannel, channels.BrowserContextInitializer> {_pages = new Set<Page>();@@ -158,7 +158,7 @@ export class BrowserContext extends ChannelOwner<channels.BrowserContextChannel,}async setHTTPCredentials(httpCredentials: { username: string, password: string } | null): Promise<void> {- if (!isDevMode())+ if (!isUnderTest())deprecate(`context.setHTTPCredentials`, `warning: method |context.setHTTPCredentials()| is deprecated. Instead of changing credentials, create another browser context with new credentials.`);return this._wrapApiCall('browserContext.setHTTPCredentials', async () => {await this._channel.setHTTPCredentials({ httpCredentials: httpCredentials || undefined });diff --git a/src/client/channelOwner.ts b/src/client/channelOwner.tsindex b607564bc5..be7d84a53f 100644--- a/src/client/channelOwner.ts+++ b/src/client/channelOwner.ts@@ -19,7 +19,7 @@ import * as channels from '../protocol/channels';import type { Connection } from './connection';import type { Logger } from './types';import { debugLogger } from '../utils/debugLogger';-import { isDevMode } from '../utils/utils';+import { isUnderTest } from '../utils/utils';export abstract class ChannelOwner<T extends channels.Channel = channels.Channel, Initializer = {}> extends EventEmitter {private _connection: Connection;@@ -100,7 +100,7 @@ export abstract class ChannelOwner<T extends channels.Channel = channels.Channelreturn result;} catch (e) {logApiCall(logger, `<= ${apiName} failed`);- const innerStack = (isDevMode() && e.stack) ? e.stack.substring(e.stack.indexOf(e.message) + e.message.length) : '';+ const innerStack = (isUnderTest() && e.stack) ? e.stack.substring(e.stack.indexOf(e.message) + e.message.length) : '';e.message = `${apiName}: ` + e.message;e.stack = e.message + innerStack + stack;throw e;diff --git a/src/inprocess.ts b/src/inprocess.tsindex 18d71d8a12..5c913850f4 100644--- a/src/inprocess.ts+++ b/src/inprocess.ts@@ -20,7 +20,6 @@ import type { Playwright as PlaywrightAPI } from './client/playwright';import { PlaywrightDispatcher } from './dispatchers/playwrightDispatcher';import { Connection } from './client/connection';import { BrowserServerLauncherImpl } from './browserServerImpl';-import { isDevMode } from './utils/utils';import { instrumentingAgents } from './server/instrumentation';import { DebugController } from './debug/debugController';@@ -45,7 +44,6 @@ export function setupInProcess(playwright: PlaywrightImpl): PlaywrightAPI {dispatcherConnection.onmessage = message => setImmediate(() => clientConnection.dispatch(message));clientConnection.onmessage = message => setImmediate(() => dispatcherConnection.dispatch(message));- if (isDevMode())- (playwrightAPI as any)._toImpl = (x: any) => dispatcherConnection._dispatchers.get(x._guid)!._object;+ (playwrightAPI as any)._toImpl = (x: any) => dispatcherConnection._dispatchers.get(x._guid)!._object;return playwrightAPI;}diff --git a/src/protocol/validatorPrimitives.ts b/src/protocol/validatorPrimitives.tsindex a5de550b96..ac996b078d 100644--- a/src/protocol/validatorPrimitives.ts+++ b/src/protocol/validatorPrimitives.ts@@ -14,7 +14,7 @@* limitations under the License.*/-import { isDevMode } from '../utils/utils';+import { isUnderTest } from '../utils/utils';export class ValidationError extends Error {}export type Validator = (arg: any, path: string) => any;@@ -81,7 +81,7 @@ export const tObject = (s: { [key: string]: Validator }): Validator => {if (!Object.is(value, undefined))result[key] = value;}- if (isDevMode()) {+ if (isUnderTest()) {for (const [key, value] of Object.entries(arg)) {if (key.startsWith('__testHook'))result[key] = value;diff --git a/src/server/processLauncher.ts b/src/server/processLauncher.tsindex 1de89f376f..b19281a7a0 100644--- a/src/server/processLauncher.ts+++ b/src/server/processLauncher.ts@@ -22,7 +22,7 @@ import * as stream from 'stream';import { helper } from './helper';import { Progress } from './progress';import * as types from './types';-import { isDevMode } from '../utils/utils';+import { isUnderTest } from '../utils/utils';export type Env = {[key: string]: string | number | boolean | undefined};@@ -120,7 +120,7 @@ export async function launchProcess(options: LaunchProcessOptions): Promise<Launlisteners.push(helper.addEventListener(process, 'SIGINT', () => {gracefullyClose().then(() => {// Give tests a chance to dispatch any async calls.- if (isDevMode())+ if (isUnderTest())setTimeout(() => process.exit(130), 0);elseprocess.exit(130);diff --git a/src/utils/utils.ts b/src/utils/utils.tsindex 56d11c69e0..bbdf8b6b67 100644--- a/src/utils/utils.ts+++ b/src/utils/utils.ts@@ -62,7 +62,7 @@ export function assert(value: any, message?: string): asserts value {}export function debugAssert(value: any, message?: string): asserts value {- if (isDevMode() && !value)+ if (isUnderTest() && !value)throw new Error(message);}@@ -87,12 +87,12 @@ export function isDebugMode(): boolean {return isInDebugMode;}-let _isDevMode = false;-export function setDevMode() {- _isDevMode = true;+let _isUnderTest = false;+export function setUnderTest() {+ _isUnderTest = true;}-export function isDevMode(): boolean {- return _isDevMode;+export function isUnderTest(): boolean {+ return _isUnderTest;}export function getFromENV(name: string) {diff --git a/test/playwright.fixtures.ts b/test/playwright.fixtures.tsindex 15b9f5690c..285bd51a3f 100644--- a/test/playwright.fixtures.ts+++ b/test/playwright.fixtures.ts@@ -115,7 +115,7 @@ registerWorkerFixture('defaultBrowserOptions', async ({browserName}, test) => {registerWorkerFixture('playwright', async ({browserName}, test) => {const {coverage, uninstall} = installCoverageHooks(browserName);if (options.WIRE) {- require('../lib/utils/utils').setDevMode();+ require('../lib/utils/utils').setUnderTest();const connection = new Connection();const spawnedProcess = childProcess.fork(path.join(__dirname, '..', 'lib', 'server.js'), [], {stdio: 'pipe',