Files
ss-tools/frontend/e2e/fixtures/global-setup.js
busya 6988e63967 chore: commit remaining pre-existing changes
- Agent configs (.opencode/agents/)
- Backend: alembic, routes, app, utils, scripts
- Frontend: package.json, vite, components, e2e infra
- Specs: 028-llm-datasource-supeset updates
- Docker e2e config and Playwright setup
2026-05-17 19:23:07 +03:00

66 lines
2.2 KiB
JavaScript

// #region GlobalSetup [C:2] [TYPE Script] [SEMANTICS e2e, setup, healthcheck]
// @BRIEF Pre-flight check before any E2E tests run.
// @PRE Backend and frontend must be reachable.
// @POST Exits with 1 if either service is down, else sets ENV vars.
import { chromium } from '@playwright/test';
const BACKEND_URL = process.env.BACKEND_URL || 'http://127.0.0.1:8101';
const FRONTEND_URL = process.env.FRONTEND_URL || 'http://127.0.0.1:8102';
async function globalSetup() {
console.log(`[E2E] Pre-flight check — Backend: ${BACKEND_URL}, Frontend: ${FRONTEND_URL}`);
// 1. Check backend health
try {
const healthRes = await fetch(`${BACKEND_URL}/api/health/summary`);
if (!healthRes.ok) {
throw new Error(`Backend health check failed: ${healthRes.status}`);
}
console.log('[E2E] Backend is healthy ✅');
} catch (err) {
console.error(`[E2E] Backend unreachable: ${err.message}`);
console.error('[E2E] Make sure the stack is running: docker compose up -d');
process.exit(1);
}
// 2. Check frontend responds
try {
const frontRes = await fetch(FRONTEND_URL);
if (!frontRes.ok && frontRes.status !== 302) {
console.warn(`[E2E] Frontend responded with ${frontRes.status}, continuing anyway`);
} else {
console.log('[E2E] Frontend is reachable ✅');
}
} catch (err) {
console.error(`[E2E] Frontend unreachable: ${err.message}`);
process.exit(1);
}
// 3. Verify auth works (can get token)
try {
const loginRes = await fetch(`${BACKEND_URL}/api/auth/login`, {
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: `username=${encodeURIComponent(process.env.E2E_USERNAME || 'admin')}&password=${encodeURIComponent(process.env.E2E_PASSWORD || 'admin123')}`,
});
if (!loginRes.ok) {
throw new Error(`Login failed: ${loginRes.status}`);
}
const loginData = await loginRes.json();
if (!loginData.access_token) {
throw new Error('No access_token in login response');
}
process.env.E2E_TOKEN = loginData.access_token;
console.log('[E2E] Auth token obtained ✅');
} catch (err) {
console.error(`[E2E] Auth check failed: ${err.message}`);
process.exit(1);
}
console.log('[E2E] Pre-flight complete — all systems go 🚀');
}
export default globalSetup;
// #endregion GlobalSetup