import { execFileSync } from "node:child_process"; /** * Applies migrations and loads the dev/demo seed data against whatever * DATABASE_HOST/PORT/NAME/USER/PASSWORD point at before the suite runs. * Deliberately does not create or tear down the database itself — same * division of responsibility as `npm run test:integration`, where the * caller is responsible for pointing these at a disposable database. */ export default function globalSetup() { if (!process.env.DATABASE_HOST || !process.env.DATABASE_NAME || !process.env.DATABASE_USER) { throw new Error( "Database connection is not configured. Point DATABASE_HOST, DATABASE_NAME, DATABASE_USER, and " + "DATABASE_PASSWORD at a disposable MySQL database before running the e2e suite, e.g.\n" + ' DATABASE_HOST=localhost DATABASE_NAME=nextchair_e2e DATABASE_USER=user DATABASE_PASSWORD=pass npm run test:e2e', ); } const env = { ...process.env, // A Super Administrator is provisioned separately from prisma/seed.ts // (see scripts/ensure-super-admin.ts's own doc comment — it deliberately // stays out of the dev/demo seed) — the merged-nav E2E scenarios need // one to sign in as, so this fixes deterministic test-only credentials // when the caller hasn't already set their own (same fallback pattern // as AUTH_SECRET in playwright.config.ts). SUPER_ADMIN_EMAIL: process.env.SUPER_ADMIN_EMAIL || "superadmin@blakeheritage.co.uk", SUPER_ADMIN_PASSWORD: process.env.SUPER_ADMIN_PASSWORD || "password123", SUPER_ADMIN_FIRST_NAME: process.env.SUPER_ADMIN_FIRST_NAME || "Super", SUPER_ADMIN_LAST_NAME: process.env.SUPER_ADMIN_LAST_NAME || "Admin", }; execFileSync("npx", ["prisma", "migrate", "deploy"], { stdio: "inherit", env }); execFileSync("npx", ["tsx", "prisma/seed.ts"], { stdio: "inherit", env }); execFileSync("npx", ["tsx", "scripts/ensure-super-admin.ts"], { stdio: "inherit", env }); }