From e5e461c0de8856ccef3db4e51ca70bca91d9d2ec Mon Sep 17 00:00:00 2001 From: Yury Semikhatsky Date: Fri, 3 Sep 2021 14:21:25 -0700 Subject: [PATCH] fix: use logger from config if specified (#8697) --- src/client/browserType.ts | 7 +++--- tests/playwright-test/playwright.spec.ts | 28 ++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/src/client/browserType.ts b/src/client/browserType.ts index 084a831114..b16ba9d822 100644 --- a/src/client/browserType.ts +++ b/src/client/browserType.ts @@ -69,7 +69,7 @@ export class BrowserType extends ChannelOwner { - const logger = options.logger; + const logger = options.logger || this._defaultLaunchOptions.logger; 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).port, 'Cannot specify a port without launching as a server.'); @@ -94,6 +94,7 @@ export class BrowserType extends ChannelOwner { + const logger = options.logger || this._defaultLaunchOptions.logger; return this._wrapApiCall(async (channel: channels.BrowserTypeChannel) => { assert(!(options as any).port, 'Cannot specify a port without launching as a server.'); options = { ...this._defaultLaunchOptions, ...this._defaultContextOptions, ...options }; @@ -109,11 +110,11 @@ export class BrowserType extends ChannelOwner; diff --git a/tests/playwright-test/playwright.spec.ts b/tests/playwright-test/playwright.spec.ts index 1cff43167d..d4cec95972 100644 --- a/tests/playwright-test/playwright.spec.ts +++ b/tests/playwright-test/playwright.spec.ts @@ -220,6 +220,34 @@ test('should respect context options in various contexts', async ({ runInlineTes 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) => { const result = await runInlineTest({ 'a.test.ts': `