Skip to content

Commit 6ec77dc

Browse files
authored
fix(inspector): fix the wait for event error rendering (#5517)
1 parent eb3efb3 commit 6ec77dc

File tree

3 files changed

+52
-10
lines changed

3 files changed

+52
-10
lines changed

src/server/supplements/inspectorController.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ export class InspectorController implements InstrumentationListener {
7575
case 'after':
7676
const originalMetadata = this._waitOperations.get(info.waitId)!;
7777
originalMetadata.endTime = metadata.endTime;
78+
originalMetadata.error = info.error;
7879
this._waitOperations.delete(info.waitId);
7980
metadata = originalMetadata;
8081
break;

src/server/supplements/recorderSupplement.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,8 +447,10 @@ export class RecorderSupplement {
447447
selector: metadata.params?.selector,
448448
};
449449
let duration = metadata.endTime ? metadata.endTime - metadata.startTime : undefined;
450-
if (duration && metadata.pauseStartTime && metadata.pauseEndTime)
450+
if (typeof duration === 'number' && metadata.pauseStartTime && metadata.pauseEndTime) {
451451
duration -= (metadata.pauseEndTime - metadata.pauseStartTime);
452+
duration = Math.max(duration, 0);
453+
}
452454
logs.push({
453455
id: metadata.id,
454456
messages: metadata.log,

test/pause.spec.ts

Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,23 @@ describe('pause', (suite, { mode }) => {
163163
await scriptPromise;
164164
});
165165

166+
it('should highlight waitForEvent', async ({page, recorderPageGetter}) => {
167+
await page.setContent('<button onclick="console.log(1)">Submit</button>');
168+
const scriptPromise = (async () => {
169+
await page.pause();
170+
await Promise.all([
171+
page.waitForEvent('console'),
172+
page.click('button'),
173+
]);
174+
})();
175+
const recorderPage = await recorderPageGetter();
176+
await recorderPage.click('[title="Step over"]');
177+
await recorderPage.waitForSelector('.source-line-paused:has-text("page.click")');
178+
await recorderPage.waitForSelector('.source-line-running:has-text("page.waitForEvent")');
179+
await recorderPage.click('[title="Resume"]');
180+
await scriptPromise;
181+
});
182+
166183
it('should populate log with waitForEvent', async ({page, recorderPageGetter}) => {
167184
await page.setContent('<button onclick="console.log(1)">Submit</button>');
168185
const scriptPromise = (async () => {
@@ -178,7 +195,7 @@ describe('pause', (suite, { mode }) => {
178195
await recorderPage.waitForSelector('.source-line-paused:has-text("page.pause(); // 2")');
179196
expect(await sanitizeLog(recorderPage)).toEqual([
180197
'page.pause- XXms',
181-
'page.waitForEvent(console)- XXms',
198+
'page.waitForEvent(console)',
182199
'page.click(button)- XXms',
183200
'page.pause',
184201
]);
@@ -200,12 +217,36 @@ describe('pause', (suite, { mode }) => {
200217
'page.isChecked(button)- XXms',
201218
'checking \"checked\" state of \"button\"',
202219
'selector resolved to <button onclick=\"console.log(1)\">Submit</button>',
203-
'Not a checkbox or radio button',
220+
'error: Not a checkbox or radio button',
204221
]);
205222
const error = await scriptPromise;
206223
expect(error.message).toContain('Not a checkbox or radio button');
207224
});
208225

226+
it('should populate log with error in waitForEvent', async ({page, recorderPageGetter}) => {
227+
await page.setContent('<button>Submit</button>');
228+
const scriptPromise = (async () => {
229+
await page.pause();
230+
await Promise.all([
231+
page.waitForEvent('console', { timeout: 1 }),
232+
page.click('button'),
233+
]);
234+
})().catch(() => {});
235+
const recorderPage = await recorderPageGetter();
236+
await recorderPage.click('[title="Step over"]');
237+
await recorderPage.waitForSelector('.source-line-paused:has-text("page.click")');
238+
await recorderPage.waitForSelector('.source-line-error:has-text("page.waitForEvent")');
239+
await recorderPage.click('[title="Resume"]');
240+
expect(await sanitizeLog(recorderPage)).toEqual([
241+
'page.pause- XXms',
242+
'page.waitForEvent(console)',
243+
'waiting for event \"console\"',
244+
'error: Timeout while waiting for event \"console\"',
245+
'page.click(button)- XXms',
246+
]);
247+
await scriptPromise;
248+
});
249+
209250
it('should pause on page close', async ({ page, recorderPageGetter }) => {
210251
const scriptPromise = (async () => {
211252
await page.pause();
@@ -234,13 +275,11 @@ describe('pause', (suite, { mode }) => {
234275
async function sanitizeLog(recorderPage: Page): Promise<string[]> {
235276
const results = [];
236277
for (const entry of await recorderPage.$$('.call-log-call')) {
237-
const header = await (await (await entry.$('.call-log-call-header')).textContent()).replace(/ \d+(\.\d+)?(ms|s)/, '- XXms');
238-
results.push(header);
239-
results.push(...await entry.$$eval('.call-log-message', ee => ee.map(e => e.textContent)));
240-
const errorElement = await entry.$('.call-log-error');
241-
const error = errorElement ? await errorElement.textContent() : undefined;
242-
if (error)
243-
results.push(error);
278+
const header = (await (await entry.$('.call-log-call-header')).textContent()).replace(/ [\d.]+(ms|s)/, '- XXms');
279+
results.push(header.replace(/page\.waitForEvent\(console\).*/, 'page.waitForEvent(console)'));
280+
results.push(...await entry.$$eval('.call-log-message', ee => ee.map(e => {
281+
return (e.classList.contains('error') ? 'error: ' : '') + e.textContent;
282+
})));
244283
}
245284
return results;
246285
}

0 commit comments

Comments
 (0)