diff --git a/index.js b/index.js index 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.ts index 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 { _pages = new Set(); @@ -158,7 +158,7 @@ export class BrowserContext extends ChannelOwner { - 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.ts index 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 extends EventEmitter { private _connection: Connection; @@ -100,7 +100,7 @@ export abstract class ChannelOwner 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.ts index 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.ts index 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 { gracefullyClose().then(() => { // Give tests a chance to dispatch any async calls. - if (isDevMode()) + if (isUnderTest()) setTimeout(() => process.exit(130), 0); else process.exit(130); diff --git a/src/utils/utils.ts b/src/utils/utils.ts index 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.ts index 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',