speed up list scripts test (10.5s → 1.4s)

The test was slow due to:
1. Page scanning by content (slow waitForLoadState + content() per page)
2. Using example.com which only has inline scripts with empty URLs

Fix:
- Use URL matching instead of content scanning (fast)
- Use news.ycombinator.com which has scripts with actual URLs
- The Debugger class filters out scripts without URLs, so we need
  a page that actually has external script files

Total relay-session.test.ts time: 74s → 27s
This commit is contained in:
Tommy D. Rossi
2026-02-03 20:05:11 +01:00
parent f6110ec023
commit adeaabd5aa
+5 -28
View File
@@ -146,15 +146,9 @@ describe('CDP Session Tests', () => {
const browserContext = getBrowserContext()
const serviceWorker = await getExtensionServiceWorker(browserContext)
// Use a page with actual script URLs (not just inline scripts)
const page = await browserContext.newPage()
await page.setContent(`
<html>
<head>
<script src="data:text/javascript,function testScript() { return 42; }"></script>
</head>
<body><h1>Script Test</h1></body>
</html>
`)
await page.goto('https://news.ycombinator.com/')
await page.bringToFront()
await serviceWorker.evaluate(async () => {
@@ -163,37 +157,20 @@ 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('Script Test')) {
cdpPage = p
break
}
}
const cdpPage = browser.contexts()[0].pages().find(p => p.url().includes('news.ycombinator'))
expect(cdpPage).toBeDefined()
const wsUrl = getCdpUrl({ port: TEST_PORT })
const cdpSession = await getCDPSessionForPage({ page: cdpPage!, wsUrl })
const dbg = new Debugger({ cdp: cdpSession })
await dbg.enable()
const scripts = await dbg.listScripts()
expect(scripts.length).toBeGreaterThan(0)
expect(scripts[0]).toHaveProperty('scriptId')
expect(scripts[0]).toHaveProperty('url')
const dataScripts = await dbg.listScripts({ search: 'data:' })
expect(dataScripts.length).toBeGreaterThan(0)
cdpSession.close()
await browser.close()
await page.close()