fix(fixtures): account for default options being undefined (#11916)

This commit is contained in:
Dmitry Gozman 2022-02-07 17:11:36 -08:00 committed by GitHub
parent 1e00218ead
commit 7912c515a3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 6 deletions

View file

@ -47,8 +47,8 @@ export class BrowserType extends ChannelOwner<channels.BrowserTypeChannel> imple
_playwright!: Playwright;
// Instrumentation.
_defaultContextOptions: BrowserContextOptions = {};
_defaultLaunchOptions: LaunchOptions = {};
_defaultContextOptions?: BrowserContextOptions;
_defaultLaunchOptions?: LaunchOptions;
_onDidCreateContext?: (context: BrowserContext) => Promise<void>;
_onWillCloseContext?: (context: BrowserContext) => Promise<void>;
@ -67,7 +67,7 @@ export class BrowserType extends ChannelOwner<channels.BrowserTypeChannel> imple
}
async launch(options: LaunchOptions = {}): Promise<Browser> {
const logger = options.logger || this._defaultLaunchOptions.logger;
const logger = options.logger || this._defaultLaunchOptions?.logger;
assert(!(options as any).userDataDir, 'userDataDir option is not supported in `browserType.launch`. Use `browserType.launchPersistentContext` instead');
assert(!(options as any).port, 'Cannot specify a port without launching as a server.');
options = { ...this._defaultLaunchOptions, ...options };
@ -92,7 +92,7 @@ export class BrowserType extends ChannelOwner<channels.BrowserTypeChannel> imple
}
async launchPersistentContext(userDataDir: string, options: LaunchPersistentContextOptions = {}): Promise<BrowserContext> {
const logger = options.logger || this._defaultLaunchOptions.logger;
const logger = options.logger || this._defaultLaunchOptions?.logger;
assert(!(options as any).port, 'Cannot specify a port without launching as a server.');
options = { ...this._defaultLaunchOptions, ...this._defaultContextOptions, ...options };
const contextParams = await prepareBrowserContextParams(options);

View file

@ -457,11 +457,12 @@ export const test = _baseTest.extend<TestFixtures, WorkerFixtures>({
function formatPendingCalls(calls: ParsedStackTrace[]) {
calls = calls.filter(call => !!call.apiName);
if (!calls.length)
return '';
return 'Pending operations:\n' + calls.map(call => {
const frame = call.frames && call.frames[0] ? formatStackFrame(call.frames[0]) : '<unknown>';
return ` - ${call.apiName} at ${frame}\n`;
const frame = call.frames && call.frames[0] ? ' at ' + formatStackFrame(call.frames[0]) : '';
return ` - ${call.apiName}${frame}\n`;
}).join('') + '\n';
}