import 'dotenv/config'; import { E2E_AUTH_SECRET } from './constants'; /** * Prepares the environment the test process itself runs in. * * Loading .env is convenient for TEST_DATABASE_URL, but it also brings the * real AUTH_SECRET along — which would then differ from the one the server * under test was started with, and every signed-in test would fail looking * like an authorisation bug. Pinning it here keeps both sides in agreement. * * The suite truncates every table, so an unset TEST_DATABASE_URL is a hard * stop rather than a fallback to whatever DATABASE_URL happens to point at. */ export default function globalSetup(): void { if (!process.env.TEST_DATABASE_URL) { throw new Error( 'TEST_DATABASE_URL n’est pas défini. Les tests E2E vident la base : ils refusent de tourner sans base dédiée.', ); } process.env.DATABASE_URL = process.env.TEST_DATABASE_URL; process.env.AUTH_SECRET = E2E_AUTH_SECRET; }