From f6110ec023b2a241f5ed9e54a9a4afb06feda2ff Mon Sep 17 00:00:00 2001 From: "Tommy D. Rossi" Date: Tue, 3 Feb 2026 19:56:46 +0100 Subject: [PATCH] =?UTF-8?q?speed=20up=20slow=20debugger=20tests=20(~74s=20?= =?UTF-8?q?=E2=86=92=20~38s)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two tests were taking 30s and 10s respectively due to avoidable waits: 1. 'should pause on all exceptions with setPauseOnExceptions' (30.6s → 0.5s) - Was awaiting page.evaluate() while debugger was paused - Playwright's evaluate has 30s timeout, so it sat there waiting - Fix: use Runtime.evaluate via CDP session (don't await until after resume) 2. 'should manage breakpoints with Debugger class' (10.6s → 0.4s) - Was connecting over CDP and scanning all pages with waitForLoadState - Each page waited up to 5s for domcontentloaded + content check - Fix: use getCDPSessionForPage directly on the page we just created --- playwriter/src/relay-session.test.ts | 32 ++++++---------------------- 1 file changed, 6 insertions(+), 26 deletions(-) diff --git a/playwriter/src/relay-session.test.ts b/playwriter/src/relay-session.test.ts index d48cfb0..8b2dddc 100644 --- a/playwriter/src/relay-session.test.ts +++ b/playwriter/src/relay-session.test.ts @@ -219,28 +219,8 @@ describe('CDP Session Tests', () => { }) await new Promise(r => setTimeout(r, 100)) - const browser = await chromium.connectOverCDP(getCdpUrl({ port: TEST_PORT })) - let cdpPage - for (const p of browser.contexts()[0].pages()) { - if (p.isClosed()) { - continue - } - await p.waitForLoadState('domcontentloaded', { timeout: 5000 }).catch(() => {}) - let html = '' - try { - html = await p.content() - } catch { - continue - } - if (html.includes('testFunc')) { - cdpPage = p - break - } - } - expect(cdpPage).toBeDefined() - const wsUrl = getCdpUrl({ port: TEST_PORT }) - const cdpSession = await getCDPSessionForPage({ page: cdpPage!, wsUrl }) + const cdpSession = await getCDPSessionForPage({ page, wsUrl }) const dbg = new Debugger({ cdp: cdpSession }) await dbg.enable() @@ -260,7 +240,6 @@ describe('CDP Session Tests', () => { expect(dbg.listBreakpoints()).toHaveLength(0) cdpSession.close() - await browser.close() await page.close() }, 60000) @@ -607,15 +586,15 @@ describe('CDP Session Tests', () => { cdpSession.on('Debugger.paused', () => resolve()) }) - await cdpPage!.evaluate(` - (function() { + const evalPromise = cdpSession.send('Runtime.evaluate', { + expression: `(function() { try { throw new Error('Caught test error'); } catch (e) { // caught but should still pause with state 'all' } - })() - `).catch(() => {}) + })()` + }) await Promise.race([ pausedPromise, @@ -628,6 +607,7 @@ describe('CDP Session Tests', () => { expect(location.sourceContext).toContain('throw') await dbg.resume() + await evalPromise await dbg.setPauseOnExceptions({ state: 'none' })