Add Playwright E2E test suite (25 tests across 4 specs)
- playwright.config.ts: headless CI setup with JSON/HTML reporters - e2e/global-setup.ts: app reachability check before tests - e2e/auth.spec.ts: 6 auth tests (sign-in, session, protected routes) - e2e/compare.spec.ts: 8 API tests (validation, SSE flow, DB persistence) - e2e/comparisons.spec.ts: 6 CRUD tests (list, detail, 404, view counts) - e2e/user.spec.ts: 5 user tests (stats, pagination, session binding) - e2e/helpers.ts: shared SSE parsing, auth, URL resolution utilities - e2e/README.md: setup and run instructions - AGENTS.md: updated with LLM provider notes and testing docs - .gitignore: added playwright report/result directories - package.json: added @playwright/test and test:e2e scripts
This commit is contained in:
32
e2e/global-setup.ts
Normal file
32
e2e/global-setup.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
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`"
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user