import { defineConfig } from 'vitest/config'; // Under CI the job-level env already sets DB_NAME=familysync and DB_HOST=mariadb // (the ephemeral service container). Do not override those — CI provisions and // migrates its own DB via the db:migrate step (T-ndv-04). // Locally, force workers to connect to the isolated test DB so the dev // `familysync` DB is never mutated by the test suite (T-ndv-02). const isCI = !!process.env.CI; export default defineConfig({ test: { environment: 'node', globals: true, globalSetup: ['./test/global-setup.ts'], setupFiles: ['./test/setup.ts'], // Disable parallel file execution so concurrent DB tests do not interfere // via the shared MariaDB. The global afterEach in test/setup.ts truncates // list tables; running test files in parallel causes FK violations when one // file's afterEach deletes rows that another file's test is still using. fileParallelism: false, env: { // OIDC discovery config — supplied so oidcConfigFallbackMiddleware // (src/auth/middleware.ts) always takes its env path and never reads // app_config on every /api/* request. Without these, the middleware hits // the DB, which 500s any test file that mocks `db` with a partial query // chain (e.g. events/login). CI's api job provides no OIDC env, so this // also makes the suite hermetic rather than depending on a local .env. // Dummy values are safe: tests exercising the real OIDC flow mock // @hono/oidc-auth directly. OIDC_ISSUER: 'https://auth.test.local', OIDC_CLIENT_ID: 'familysync-test', OIDC_AUTH_EXTERNAL_URL: 'https://familysync.test.local', // Local: force the isolated test DB so the dev `familysync` DB is never // mutated. Under CI the job-level env already sets DB_NAME=familysync and // DB_HOST=mariadb — do not override those. ...(isCI ? {} : { DB_NAME: 'familysync_test', DB_HOST: process.env.DB_HOST ?? '127.0.0.1', }), }, }, });