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.
This commit is contained in:
Dmitry Gozman 2021-06-04 18:43:54 -07:00 committed by GitHub
parent a83646684a
commit 69b734629c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 29 additions and 7 deletions

View File

@ -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()]);
}

View File

@ -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[] } {

View File

@ -63,7 +63,7 @@ const config: folio.Config<CommonOptions & PlaywrightOptions> = {
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/);

View File

@ -24,12 +24,13 @@ export { expect } from 'folio';
type CLITestArgs = {
recorderPageGetter: () => Promise<Page>;
closeRecorder: () => Promise<void>;
openRecorder: () => Promise<Recorder>;
runCLI: (args: string[]) => CLIMock;
};
export const test = contextTest.extend<CLITestArgs>({
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<CLITestArgs>({
});
},
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');

View File

@ -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');

View File

@ -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}) => {

View File

@ -681,8 +681,8 @@ playwright.chromium.launch().then(async browser => {
for (const frameLike of frameLikes) {
{
const handle = await frameLike.waitForSelector('body');
const bodyAssertion: AssertType<playwright.ElementHandle<HTMLBodyElement>, typeof handle> = true;
const canBeNull: AssertCanBeNull<typeof handle> = false
const bodyAssertion: AssertType<playwright.ElementHandle<HTMLBodyElement>, typeof handle> = true;
const canBeNull: AssertCanBeNull<typeof handle> = 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<playwright.ElementHandle<HTMLElement|SVGElement>, typeof handle> = true;
const canBeNull: AssertCanBeNull<typeof handle> = false;
}
const canBeNull: AssertCanBeNull<typeof handle> = false;
}
{
const state = Math.random() > .5 ? 'attached' : 'visible';
const handle = await frameLike.waitForSelector('something-strange', {state});