import { expect, test } from '@playwright/test'; import { ConsoleErrorCapture } from '../../shared/website/ConsoleErrorCapture'; const WEBSITE_BASE_URL = process.env.PLAYWRIGHT_BASE_URL || 'http://localhost:3000'; const CRITICAL_ROUTES = [ '/', '/dashboard', '/leagues', '/teams', '/drivers', ]; const ALLOWED_WARNINGS = [ 'hydration', 'text content does not match', 'warning:', 'download the react devtools', 'connection refused', 'failed to load resource', 'network error', 'cors', 'react does not recognize the `%s` prop on a dom element', ]; test.describe('Runtime Health', () => { for (const path of CRITICAL_ROUTES) { test(`route ${path} should have no unexpected console errors`, async ({ page }) => { const capture = new ConsoleErrorCapture(page); capture.setAllowlist(ALLOWED_WARNINGS); const response = await page.goto(`${WEBSITE_BASE_URL}${path}`); // Some routes might redirect to login if not authenticated, which is fine for health check // as long as the page itself doesn't crash. expect(response?.status()).toBeLessThan(500); // Wait a bit for client-side errors to surface await page.waitForTimeout(1000); if (capture.hasUnexpectedErrors()) { throw new Error(`Found unexpected console errors on ${path}:\n${capture.format()}`); } }); } });