Skip to content

Commit 69b7346

Browse files
authored
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.
1 parent a836466 commit 69b7346

File tree

7 files changed

+29
-7
lines changed

7 files changed

+29
-7
lines changed

src/server/supplements/recorderSupplement.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ export class RecorderSupplement implements InstrumentationListener {
131131
const recorderApp = await RecorderApp.open(this._context);
132132
this._recorderApp = recorderApp;
133133
recorderApp.once('close', () => {
134+
this._debugger.resume(false);
134135
this._recorderApp = null;
135136
});
136137
recorderApp.on('event', (data: EventData) => {
@@ -231,7 +232,7 @@ export class RecorderSupplement implements InstrumentationListener {
231232
if (!this._currentCallsMetadata.has(metadata))
232233
this.onBeforeCall(sdkObject, metadata);
233234
}
234-
this._recorderApp!.setPaused(this._debugger.isPaused());
235+
this._recorderApp?.setPaused(this._debugger.isPaused());
235236
this._updateUserSources();
236237
this.updateCallLog([...this._currentCallsMetadata.keys()]);
237238
}

src/utils/stackTrace.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ const PW_LIB_DIRS = [
4141
'playwright-chromium',
4242
'playwright-firefox',
4343
'playwright-webkit',
44+
path.join('@playwright', 'test'),
4445
].map(packageName => path.sep + path.join(packageName, 'lib'));
4546

4647
export function captureStackTrace(): { stack: string, frames: StackFrame[] } {

tests/config/default.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ const config: folio.Config<CommonOptions & PlaywrightOptions> = {
6363
const browserNames = ['chromium', 'webkit', 'firefox'] as BrowserName[];
6464
for (const browserName of browserNames) {
6565
const executablePath = getExecutablePath(browserName);
66-
if (executablePath && !process.env.FOLIO_WORKER_INDEX)
66+
if (executablePath && !process.env.TEST_WORKER_INDEX)
6767
console.error(`Using executable at ${executablePath}`);
6868
const testIgnore: RegExp[] = browserNames.filter(b => b !== browserName).map(b => new RegExp(b));
6969
testIgnore.push(/android/, /electron/);

tests/inspector/inspectorTest.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,13 @@ export { expect } from 'folio';
2424

2525
type CLITestArgs = {
2626
recorderPageGetter: () => Promise<Page>;
27+
closeRecorder: () => Promise<void>;
2728
openRecorder: () => Promise<Recorder>;
2829
runCLI: (args: string[]) => CLIMock;
2930
};
3031

3132
export const test = contextTest.extend<CLITestArgs>({
32-
recorderPageGetter: async ({ page, context, toImpl, browserName, channel, headless, mode, executablePath }, run, testInfo) => {
33+
recorderPageGetter: async ({ context, toImpl, mode }, run, testInfo) => {
3334
process.env.PWTEST_RECORDER_PORT = String(10907 + testInfo.workerIndex);
3435
testInfo.skip(mode === 'service');
3536
await run(async () => {
@@ -42,6 +43,12 @@ export const test = contextTest.extend<CLITestArgs>({
4243
});
4344
},
4445

46+
closeRecorder: async ({ context, toImpl }, run) => {
47+
await run(async () => {
48+
await toImpl(context).recorderAppForTest.close();
49+
});
50+
},
51+
4552
runCLI: async ({ browserName, channel, headless, mode, executablePath }, run, testInfo) => {
4653
process.env.PWTEST_RECORDER_PORT = String(10907 + testInfo.workerIndex);
4754
testInfo.skip(mode === 'service');

tests/inspector/pause.spec.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,18 @@
1717
import { Page } from '../../index';
1818
import { test as it, expect } from './inspectorTest';
1919

20+
21+
it('should resume when closing inspector', async ({page, recorderPageGetter, closeRecorder, mode}) => {
22+
it.skip(mode !== 'default');
23+
24+
const scriptPromise = (async () => {
25+
await page.pause();
26+
})();
27+
await recorderPageGetter();
28+
await closeRecorder();
29+
await scriptPromise;
30+
});
31+
2032
it.describe('pause', () => {
2133
it.skip(({ mode }) => mode !== 'default');
2234

tests/launcher.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ it('should require top-level DeviceDescriptors', async ({playwright}) => {
2626
const Devices = require('../lib/server/deviceDescriptors.js');
2727
expect(Devices['iPhone 6']).toBeTruthy();
2828
expect(Devices['iPhone 6']).toEqual(playwright.devices['iPhone 6']);
29+
expect(playwright.devices['iPhone 6'].defaultBrowserType).toBe('webkit');
2930
});
3031

3132
it('should kill browser process on timeout after close', async ({browserType, browserOptions, mode}) => {

utils/generate_types/test/test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -681,8 +681,8 @@ playwright.chromium.launch().then(async browser => {
681681
for (const frameLike of frameLikes) {
682682
{
683683
const handle = await frameLike.waitForSelector('body');
684-
const bodyAssertion: AssertType<playwright.ElementHandle<HTMLBodyElement>, typeof handle> = true;
685-
const canBeNull: AssertCanBeNull<typeof handle> = false
684+
const bodyAssertion: AssertType<playwright.ElementHandle<HTMLBodyElement>, typeof handle> = true;
685+
const canBeNull: AssertCanBeNull<typeof handle> = false
686686
}
687687
{
688688
const handle = await frameLike.waitForSelector('body', {timeout: 0});
@@ -714,8 +714,8 @@ playwright.chromium.launch().then(async browser => {
714714
{
715715
const handle = await frameLike.waitForSelector('something-strange', {timeout: 0});
716716
const elementAssertion: AssertType<playwright.ElementHandle<HTMLElement|SVGElement>, typeof handle> = true;
717-
const canBeNull: AssertCanBeNull<typeof handle> = false;
718-
}
717+
const canBeNull: AssertCanBeNull<typeof handle> = false;
718+
}
719719
{
720720
const state = Math.random() > .5 ? 'attached' : 'visible';
721721
const handle = await frameLike.waitForSelector('something-strange', {state});

0 commit comments

Comments
 (0)