import type { FullConfig } from "@playwright/test"; import { baseURL } from "./playwright.config"; /** * Global setup — runs once before all tests. * Verifies the app is reachable before running E2E suite. */ export default async function globalSetup(_config: FullConfig) { const url = baseURL.replace("localhost", process.env.E2E_HOST || "192.168.50.61"); console.log(`[E2E Setup] Checking app at: ${url}`); let attempts = 0; while (attempts < 10) { try { const res = await fetch(url, { signal: AbortSignal.timeout(5000) }); if (res.ok || res.status === 401) { // 401 means the server is up (auth is working), 200 means homepage console.log(`[E2E Setup] App reachable (HTTP ${res.status})`); return; } } catch { // ignore and retry } attempts++; await new Promise((r) => setTimeout(r, 2000)); } throw new Error( `[E2E Setup] App not reachable at ${url} after ${attempts} attempts. ` + "Ensure the Docker container is running: `docker compose up -d`" ); }