mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
chore: revert isDevMode into isUnderTest (#3785)
This commit is contained in:
parent
fea3ceb36c
commit
c83b2da54f
4
index.js
4
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');
|
||||
|
@ -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 });
|
||||
|
@ -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.Channel
|
||||
return 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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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<Laun
|
||||
listeners.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);
|
||||
else
|
||||
process.exit(130);
|
||||
|
@ -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) {
|
||||
|
@ -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',
|
||||
|
Loading…
x
Reference in New Issue
Block a user