// Loaded here, not in globalSetup: this file is evaluated first, and the // webServer environment below is read from it. Without this, TEST_DATABASE_URL // is still undefined when the server is started and every page fails on a // missing DATABASE_URL. import 'dotenv/config'; import { defineConfig, devices } from '@playwright/test'; import { E2E_AUTH_SECRET, E2E_BASE_URL, E2E_PORT } from './e2e/constants'; /** * End-to-end tests. * * They run against a real server and a real database — the E2E database, which * the global setup empties. That is the whole point: these are the only tests * that exercise the middleware, the server actions and the rendering together, * the way a person in the shop does. * * Port 3020 so a development server on 3010 can stay running. */ const PORT = E2E_PORT; const BASE_URL = E2E_BASE_URL; export default defineConfig({ testDir: './e2e', fullyParallel: false, workers: 1, forbidOnly: !!process.env.CI, retries: process.env.CI ? 1 : 0, reporter: process.env.CI ? [['github'], ['list']] : 'list', globalSetup: './e2e/global-setup.ts', use: { baseURL: BASE_URL, trace: 'retain-on-failure', screenshot: 'only-on-failure', locale: 'fr-CH', timezoneId: 'Europe/Zurich', }, projects: [ { name: 'chromium', use: { ...devices['Desktop Chrome'] } }, { // The shop uses a phone behind the counter, so the narrow viewport is // the primary case, not an afterthought. // // Run on Chromium rather than WebKit: WebKit needs system packages that // only root can install, and a suite nobody can run locally is a suite // nobody runs. This still covers the layout, the touch targets and the // mobile keyboard types. To exercise the real Safari engine — worth // doing before trusting an iPhone-only bug report — install the // dependencies once (`sudo npx playwright install-deps webkit`) and drop // the browserName override. name: 'mobile', use: { ...devices['iPhone 15'], browserName: 'chromium' }, }, ], webServer: { // A production build rather than the dev server: it is what actually ships, // and Next refuses to start a second dev server in the same directory, so // this also lets the suite run while someone is developing. command: 'sh scripts/e2e-server.sh', url: `${BASE_URL}/api/health`, reuseExistingServer: !process.env.CI, timeout: 120_000, env: { PORT: String(PORT), NODE_ENV: 'production', // Never the development database: the setup empties this one. DATABASE_URL: process.env.TEST_DATABASE_URL ?? '', AUTH_URL: BASE_URL, AUTH_SECRET: E2E_AUTH_SECRET, AUTHENTIK_ADMIN_GROUP: 'horaires-admins', // Placeholders, never contacted: the suite mints its own session cookie. // They exist so the provider builds and the sign-in page renders its // normal button — CI has no .env to inherit these from. AUTH_AUTHENTIK_ID: 'e2e-client-id', AUTH_AUTHENTIK_SECRET: 'e2e-client-secret', AUTH_AUTHENTIK_ISSUER: 'https://auth.example.test/application/o/e2e/', // The translation service is stubbed per-test; never called for real. TRANSLATION_API_URL: '', TRANSLATION_API_KEY: '', }, }, });