// Shared helpers for Playwright tests const BASE_URL = process.env.SX_TEST_URL || 'http://localhost:8013'; /** * Wait for the SX runtime to finish hydration. * boot-init sets data-sx-ready="true" on after all islands are hydrated. */ async function waitForSxReady(page, timeout = 15000) { await page.waitForSelector('html[data-sx-ready]', { timeout }); } /** * Navigate to an SX page and wait for hydration to complete. * Replaces the old pattern of networkidle + arbitrary sleep. */ async function loadPage(page, path, timeout = 15000) { await page.goto(BASE_URL + '/sx/' + path, { waitUntil: 'domcontentloaded', timeout }); await waitForSxReady(page); } /** * Track console errors and uncaught exceptions on a page. * Call before navigation. Use errors() to get filtered error list. */ function trackErrors(page) { const raw = []; page.on('pageerror', err => raw.push(err.message)); page.on('console', msg => { if (msg.type() === 'error') raw.push(msg.text()); }); return { /** Return errors, filtering transient network noise. */ errors() { return raw.filter(e => !e.includes('Failed to fetch') && !e.includes('net::ERR') && !e.includes(' 404 ') && !e.includes('Failed to load resource') && !e.includes('Parse_error') // WASM parser edge case on empty OOB fragments ); } }; } module.exports = { BASE_URL, waitForSxReady, loadPage, trackErrors };