mirror of
https://github.com/microsoft/playwright.git
synced 2025-01-05 10:15:12 +03:00
fix: use logger from config if specified (#8697)
This commit is contained in:
parent
5d278db17b
commit
e5e461c0de
@ -69,7 +69,7 @@ export class BrowserType extends ChannelOwner<channels.BrowserTypeChannel, chann
|
|||||||
}
|
}
|
||||||
|
|
||||||
async launch(options: LaunchOptions = {}): Promise<Browser> {
|
async launch(options: LaunchOptions = {}): Promise<Browser> {
|
||||||
const logger = options.logger;
|
const logger = options.logger || this._defaultLaunchOptions.logger;
|
||||||
return this._wrapApiCall(async (channel: channels.BrowserTypeChannel) => {
|
return this._wrapApiCall(async (channel: channels.BrowserTypeChannel) => {
|
||||||
assert(!(options as any).userDataDir, 'userDataDir option is not supported in `browserType.launch`. Use `browserType.launchPersistentContext` instead');
|
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.');
|
assert(!(options as any).port, 'Cannot specify a port without launching as a server.');
|
||||||
@ -94,6 +94,7 @@ export class BrowserType extends ChannelOwner<channels.BrowserTypeChannel, chann
|
|||||||
}
|
}
|
||||||
|
|
||||||
async launchPersistentContext(userDataDir: string, options: LaunchPersistentContextOptions = {}): Promise<BrowserContext> {
|
async launchPersistentContext(userDataDir: string, options: LaunchPersistentContextOptions = {}): Promise<BrowserContext> {
|
||||||
|
const logger = options.logger || this._defaultLaunchOptions.logger;
|
||||||
return this._wrapApiCall(async (channel: channels.BrowserTypeChannel) => {
|
return this._wrapApiCall(async (channel: channels.BrowserTypeChannel) => {
|
||||||
assert(!(options as any).port, 'Cannot specify a port without launching as a server.');
|
assert(!(options as any).port, 'Cannot specify a port without launching as a server.');
|
||||||
options = { ...this._defaultLaunchOptions, ...this._defaultContextOptions, ...options };
|
options = { ...this._defaultLaunchOptions, ...this._defaultContextOptions, ...options };
|
||||||
@ -109,11 +110,11 @@ export class BrowserType extends ChannelOwner<channels.BrowserTypeChannel, chann
|
|||||||
const result = await channel.launchPersistentContext(persistentParams);
|
const result = await channel.launchPersistentContext(persistentParams);
|
||||||
const context = BrowserContext.from(result.context);
|
const context = BrowserContext.from(result.context);
|
||||||
context._options = contextParams;
|
context._options = contextParams;
|
||||||
context._logger = options.logger;
|
context._logger = logger;
|
||||||
context._setBrowserType(this);
|
context._setBrowserType(this);
|
||||||
await this._onDidCreateContext?.(context);
|
await this._onDidCreateContext?.(context);
|
||||||
return context;
|
return context;
|
||||||
}, options.logger);
|
}, logger);
|
||||||
}
|
}
|
||||||
|
|
||||||
connect(options: api.ConnectOptions & { wsEndpoint?: string }): Promise<api.Browser>;
|
connect(options: api.ConnectOptions & { wsEndpoint?: string }): Promise<api.Browser>;
|
||||||
|
@ -220,6 +220,34 @@ test('should respect context options in various contexts', async ({ runInlineTes
|
|||||||
expect(result.passed).toBe(4);
|
expect(result.passed).toBe(4);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should call logger from launchOptions config', async ({ runInlineTest }, testInfo) => {
|
||||||
|
const result = await runInlineTest({
|
||||||
|
'a.test.ts': `
|
||||||
|
const { test } = pwt;
|
||||||
|
const log = [];
|
||||||
|
test.use({
|
||||||
|
launchOptions: {
|
||||||
|
logger: {
|
||||||
|
log: (name, severity, message) => log.push({name, severity, message}),
|
||||||
|
isEnabled: (name, severity) => severity !== 'verbose'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should support config logger', async ({browser}) => {
|
||||||
|
expect(browser.version()).toBeTruthy();
|
||||||
|
expect(log.length > 0).toBeTruthy();
|
||||||
|
expect(log.filter(item => item.severity === 'info').length > 0).toBeTruthy();
|
||||||
|
expect(log.filter(item => item.message.includes('browserType.launch started')).length > 0).toBeTruthy();
|
||||||
|
expect(log.filter(item => item.message.includes('browserType.launch succeeded')).length > 0).toBeTruthy();
|
||||||
|
});
|
||||||
|
`,
|
||||||
|
}, { workers: 1 });
|
||||||
|
|
||||||
|
expect(result.exitCode).toBe(0);
|
||||||
|
expect(result.passed).toBe(1);
|
||||||
|
});
|
||||||
|
|
||||||
test('should report error and pending operations on timeout', async ({ runInlineTest }, testInfo) => {
|
test('should report error and pending operations on timeout', async ({ runInlineTest }, testInfo) => {
|
||||||
const result = await runInlineTest({
|
const result = await runInlineTest({
|
||||||
'a.test.ts': `
|
'a.test.ts': `
|
||||||
|
Loading…
Reference in New Issue
Block a user