From 69b734629cb3afb883bdd7c774c8c3fd98d1494e Mon Sep 17 00:00:00 2001 From: Dmitry Gozman Date: Fri, 4 Jun 2021 18:43:54 -0700 Subject: [PATCH] fix: various test-related fixes (#6916) - Closing inspector window resumes the script. - Replace FOLIO_WORKER_INDEX with TEST_WORKER_INDEX. - Account for `@playwright/test` stack traces. --- src/server/supplements/recorderSupplement.ts | 3 ++- src/utils/stackTrace.ts | 1 + tests/config/default.config.ts | 2 +- tests/inspector/inspectorTest.ts | 9 ++++++++- tests/inspector/pause.spec.ts | 12 ++++++++++++ tests/launcher.spec.ts | 1 + utils/generate_types/test/test.ts | 8 ++++---- 7 files changed, 29 insertions(+), 7 deletions(-) diff --git a/src/server/supplements/recorderSupplement.ts b/src/server/supplements/recorderSupplement.ts index ccd040a37c..345d0db221 100644 --- a/src/server/supplements/recorderSupplement.ts +++ b/src/server/supplements/recorderSupplement.ts @@ -131,6 +131,7 @@ export class RecorderSupplement implements InstrumentationListener { const recorderApp = await RecorderApp.open(this._context); this._recorderApp = recorderApp; recorderApp.once('close', () => { + this._debugger.resume(false); this._recorderApp = null; }); recorderApp.on('event', (data: EventData) => { @@ -231,7 +232,7 @@ export class RecorderSupplement implements InstrumentationListener { if (!this._currentCallsMetadata.has(metadata)) this.onBeforeCall(sdkObject, metadata); } - this._recorderApp!.setPaused(this._debugger.isPaused()); + this._recorderApp?.setPaused(this._debugger.isPaused()); this._updateUserSources(); this.updateCallLog([...this._currentCallsMetadata.keys()]); } diff --git a/src/utils/stackTrace.ts b/src/utils/stackTrace.ts index 242ca05835..374e7a667b 100644 --- a/src/utils/stackTrace.ts +++ b/src/utils/stackTrace.ts @@ -41,6 +41,7 @@ const PW_LIB_DIRS = [ 'playwright-chromium', 'playwright-firefox', 'playwright-webkit', + path.join('@playwright', 'test'), ].map(packageName => path.sep + path.join(packageName, 'lib')); export function captureStackTrace(): { stack: string, frames: StackFrame[] } { diff --git a/tests/config/default.config.ts b/tests/config/default.config.ts index 6b0d21b05b..c2d51d1419 100644 --- a/tests/config/default.config.ts +++ b/tests/config/default.config.ts @@ -63,7 +63,7 @@ const config: folio.Config = { const browserNames = ['chromium', 'webkit', 'firefox'] as BrowserName[]; for (const browserName of browserNames) { const executablePath = getExecutablePath(browserName); - if (executablePath && !process.env.FOLIO_WORKER_INDEX) + if (executablePath && !process.env.TEST_WORKER_INDEX) console.error(`Using executable at ${executablePath}`); const testIgnore: RegExp[] = browserNames.filter(b => b !== browserName).map(b => new RegExp(b)); testIgnore.push(/android/, /electron/); diff --git a/tests/inspector/inspectorTest.ts b/tests/inspector/inspectorTest.ts index 90968f0185..c9f0192622 100644 --- a/tests/inspector/inspectorTest.ts +++ b/tests/inspector/inspectorTest.ts @@ -24,12 +24,13 @@ export { expect } from 'folio'; type CLITestArgs = { recorderPageGetter: () => Promise; + closeRecorder: () => Promise; openRecorder: () => Promise; runCLI: (args: string[]) => CLIMock; }; export const test = contextTest.extend({ - recorderPageGetter: async ({ page, context, toImpl, browserName, channel, headless, mode, executablePath }, run, testInfo) => { + recorderPageGetter: async ({ context, toImpl, mode }, run, testInfo) => { process.env.PWTEST_RECORDER_PORT = String(10907 + testInfo.workerIndex); testInfo.skip(mode === 'service'); await run(async () => { @@ -42,6 +43,12 @@ export const test = contextTest.extend({ }); }, + closeRecorder: async ({ context, toImpl }, run) => { + await run(async () => { + await toImpl(context).recorderAppForTest.close(); + }); + }, + runCLI: async ({ browserName, channel, headless, mode, executablePath }, run, testInfo) => { process.env.PWTEST_RECORDER_PORT = String(10907 + testInfo.workerIndex); testInfo.skip(mode === 'service'); diff --git a/tests/inspector/pause.spec.ts b/tests/inspector/pause.spec.ts index 09e9191c49..4fda959411 100644 --- a/tests/inspector/pause.spec.ts +++ b/tests/inspector/pause.spec.ts @@ -17,6 +17,18 @@ import { Page } from '../../index'; import { test as it, expect } from './inspectorTest'; + +it('should resume when closing inspector', async ({page, recorderPageGetter, closeRecorder, mode}) => { + it.skip(mode !== 'default'); + + const scriptPromise = (async () => { + await page.pause(); + })(); + await recorderPageGetter(); + await closeRecorder(); + await scriptPromise; +}); + it.describe('pause', () => { it.skip(({ mode }) => mode !== 'default'); diff --git a/tests/launcher.spec.ts b/tests/launcher.spec.ts index fc267815e7..a33c666bfc 100644 --- a/tests/launcher.spec.ts +++ b/tests/launcher.spec.ts @@ -26,6 +26,7 @@ it('should require top-level DeviceDescriptors', async ({playwright}) => { const Devices = require('../lib/server/deviceDescriptors.js'); expect(Devices['iPhone 6']).toBeTruthy(); expect(Devices['iPhone 6']).toEqual(playwright.devices['iPhone 6']); + expect(playwright.devices['iPhone 6'].defaultBrowserType).toBe('webkit'); }); it('should kill browser process on timeout after close', async ({browserType, browserOptions, mode}) => { diff --git a/utils/generate_types/test/test.ts b/utils/generate_types/test/test.ts index 964456d923..fb08ac3782 100644 --- a/utils/generate_types/test/test.ts +++ b/utils/generate_types/test/test.ts @@ -681,8 +681,8 @@ playwright.chromium.launch().then(async browser => { for (const frameLike of frameLikes) { { const handle = await frameLike.waitForSelector('body'); - const bodyAssertion: AssertType, typeof handle> = true; - const canBeNull: AssertCanBeNull = false + const bodyAssertion: AssertType, typeof handle> = true; + const canBeNull: AssertCanBeNull = false } { const handle = await frameLike.waitForSelector('body', {timeout: 0}); @@ -714,8 +714,8 @@ playwright.chromium.launch().then(async browser => { { const handle = await frameLike.waitForSelector('something-strange', {timeout: 0}); const elementAssertion: AssertType, typeof handle> = true; - const canBeNull: AssertCanBeNull = false; - } + const canBeNull: AssertCanBeNull = false; + } { const state = Math.random() > .5 ? 'attached' : 'visible'; const handle = await frameLike.waitForSelector('something-strange', {state});