Skip to content

Commit

Permalink
fix: various test-related fixes (#6916)
Browse files Browse the repository at this point in the history
- Closing inspector window resumes the script.
- Replace FOLIO_WORKER_INDEX with TEST_WORKER_INDEX.
- Account for `@playwright/test` stack traces.
  • Loading branch information
dgozman authored Jun 5, 2021
1 parent a836466 commit 69b7346
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/server/supplements/recorderSupplement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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()]);
}
Expand Down
1 change: 1 addition & 0 deletions src/utils/stackTrace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[] } {
Expand Down
2 changes: 1 addition & 1 deletion tests/config/default.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/);
Expand Down
9 changes: 8 additions & 1 deletion tests/inspector/inspectorTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand All @@ -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');
Expand Down
12 changes: 12 additions & 0 deletions tests/inspector/pause.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
1 change: 1 addition & 0 deletions tests/launcher.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}) => {
Expand Down
8 changes: 4 additions & 4 deletions utils/generate_types/test/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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});
Expand Down Expand Up @@ -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});
Expand Down

0 comments on commit 69b7346

Please sign in to comment.