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.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const { setDevMode } = require('./lib/utils/utils');
|
const { setUnderTest } = require('./lib/utils/utils');
|
||||||
setDevMode(); // Note: we must call setDevMode before initializing.
|
setUnderTest(); // Note: we must call setUnderTest before initializing.
|
||||||
|
|
||||||
const { Playwright } = require('./lib/server/playwright');
|
const { Playwright } = require('./lib/server/playwright');
|
||||||
const { Electron } = require('./lib/server/electron/electron');
|
const { Electron } = require('./lib/server/electron/electron');
|
||||||
|
@ -26,7 +26,7 @@ import { Events } from './events';
|
|||||||
import { TimeoutSettings } from '../utils/timeoutSettings';
|
import { TimeoutSettings } from '../utils/timeoutSettings';
|
||||||
import { Waiter } from './waiter';
|
import { Waiter } from './waiter';
|
||||||
import { URLMatch, Headers, WaitForEventOptions } from './types';
|
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> {
|
export class BrowserContext extends ChannelOwner<channels.BrowserContextChannel, channels.BrowserContextInitializer> {
|
||||||
_pages = new Set<Page>();
|
_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> {
|
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.`);
|
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 () => {
|
return this._wrapApiCall('browserContext.setHTTPCredentials', async () => {
|
||||||
await this._channel.setHTTPCredentials({ httpCredentials: httpCredentials || undefined });
|
await this._channel.setHTTPCredentials({ httpCredentials: httpCredentials || undefined });
|
||||||
|
@ -19,7 +19,7 @@ import * as channels from '../protocol/channels';
|
|||||||
import type { Connection } from './connection';
|
import type { Connection } from './connection';
|
||||||
import type { Logger } from './types';
|
import type { Logger } from './types';
|
||||||
import { debugLogger } from '../utils/debugLogger';
|
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 {
|
export abstract class ChannelOwner<T extends channels.Channel = channels.Channel, Initializer = {}> extends EventEmitter {
|
||||||
private _connection: Connection;
|
private _connection: Connection;
|
||||||
@ -100,7 +100,7 @@ export abstract class ChannelOwner<T extends channels.Channel = channels.Channel
|
|||||||
return result;
|
return result;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logApiCall(logger, `<= ${apiName} failed`);
|
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.message = `${apiName}: ` + e.message;
|
||||||
e.stack = e.message + innerStack + stack;
|
e.stack = e.message + innerStack + stack;
|
||||||
throw e;
|
throw e;
|
||||||
|
@ -20,7 +20,6 @@ import type { Playwright as PlaywrightAPI } from './client/playwright';
|
|||||||
import { PlaywrightDispatcher } from './dispatchers/playwrightDispatcher';
|
import { PlaywrightDispatcher } from './dispatchers/playwrightDispatcher';
|
||||||
import { Connection } from './client/connection';
|
import { Connection } from './client/connection';
|
||||||
import { BrowserServerLauncherImpl } from './browserServerImpl';
|
import { BrowserServerLauncherImpl } from './browserServerImpl';
|
||||||
import { isDevMode } from './utils/utils';
|
|
||||||
import { instrumentingAgents } from './server/instrumentation';
|
import { instrumentingAgents } from './server/instrumentation';
|
||||||
import { DebugController } from './debug/debugController';
|
import { DebugController } from './debug/debugController';
|
||||||
|
|
||||||
@ -45,7 +44,6 @@ export function setupInProcess(playwright: PlaywrightImpl): PlaywrightAPI {
|
|||||||
dispatcherConnection.onmessage = message => setImmediate(() => clientConnection.dispatch(message));
|
dispatcherConnection.onmessage = message => setImmediate(() => clientConnection.dispatch(message));
|
||||||
clientConnection.onmessage = message => setImmediate(() => dispatcherConnection.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;
|
return playwrightAPI;
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { isDevMode } from '../utils/utils';
|
import { isUnderTest } from '../utils/utils';
|
||||||
|
|
||||||
export class ValidationError extends Error {}
|
export class ValidationError extends Error {}
|
||||||
export type Validator = (arg: any, path: string) => any;
|
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))
|
if (!Object.is(value, undefined))
|
||||||
result[key] = value;
|
result[key] = value;
|
||||||
}
|
}
|
||||||
if (isDevMode()) {
|
if (isUnderTest()) {
|
||||||
for (const [key, value] of Object.entries(arg)) {
|
for (const [key, value] of Object.entries(arg)) {
|
||||||
if (key.startsWith('__testHook'))
|
if (key.startsWith('__testHook'))
|
||||||
result[key] = value;
|
result[key] = value;
|
||||||
|
@ -22,7 +22,7 @@ import * as stream from 'stream';
|
|||||||
import { helper } from './helper';
|
import { helper } from './helper';
|
||||||
import { Progress } from './progress';
|
import { Progress } from './progress';
|
||||||
import * as types from './types';
|
import * as types from './types';
|
||||||
import { isDevMode } from '../utils/utils';
|
import { isUnderTest } from '../utils/utils';
|
||||||
|
|
||||||
export type Env = {[key: string]: string | number | boolean | undefined};
|
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', () => {
|
listeners.push(helper.addEventListener(process, 'SIGINT', () => {
|
||||||
gracefullyClose().then(() => {
|
gracefullyClose().then(() => {
|
||||||
// Give tests a chance to dispatch any async calls.
|
// Give tests a chance to dispatch any async calls.
|
||||||
if (isDevMode())
|
if (isUnderTest())
|
||||||
setTimeout(() => process.exit(130), 0);
|
setTimeout(() => process.exit(130), 0);
|
||||||
else
|
else
|
||||||
process.exit(130);
|
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 {
|
export function debugAssert(value: any, message?: string): asserts value {
|
||||||
if (isDevMode() && !value)
|
if (isUnderTest() && !value)
|
||||||
throw new Error(message);
|
throw new Error(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,12 +87,12 @@ export function isDebugMode(): boolean {
|
|||||||
return isInDebugMode;
|
return isInDebugMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
let _isDevMode = false;
|
let _isUnderTest = false;
|
||||||
export function setDevMode() {
|
export function setUnderTest() {
|
||||||
_isDevMode = true;
|
_isUnderTest = true;
|
||||||
}
|
}
|
||||||
export function isDevMode(): boolean {
|
export function isUnderTest(): boolean {
|
||||||
return _isDevMode;
|
return _isUnderTest;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getFromENV(name: string) {
|
export function getFromENV(name: string) {
|
||||||
|
@ -115,7 +115,7 @@ registerWorkerFixture('defaultBrowserOptions', async ({browserName}, test) => {
|
|||||||
registerWorkerFixture('playwright', async ({browserName}, test) => {
|
registerWorkerFixture('playwright', async ({browserName}, test) => {
|
||||||
const {coverage, uninstall} = installCoverageHooks(browserName);
|
const {coverage, uninstall} = installCoverageHooks(browserName);
|
||||||
if (options.WIRE) {
|
if (options.WIRE) {
|
||||||
require('../lib/utils/utils').setDevMode();
|
require('../lib/utils/utils').setUnderTest();
|
||||||
const connection = new Connection();
|
const connection = new Connection();
|
||||||
const spawnedProcess = childProcess.fork(path.join(__dirname, '..', 'lib', 'server.js'), [], {
|
const spawnedProcess = childProcess.fork(path.join(__dirname, '..', 'lib', 'server.js'), [], {
|
||||||
stdio: 'pipe',
|
stdio: 'pipe',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user