Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions packages/db/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,28 @@
//
// DATABASE_URL=postgres://app:app@localhost:5432/app_test pnpm --filter @app/db test
//
// DB config also resolves from the repo-root .env (loaded below) — the migrate
// CLI and test-connection already do this, so the suite stays consistent with
// them instead of only working when DATABASE_URL is set inline in the shell.
//
// Tests import the BUILT packages (`@app/db`, `@app/types`) via their exports
// map, so `pretest` builds them first. That sidesteps NodeNext `.js`-import
// resolution issues that arise when transpiling the TS source on the fly.
// =============================================================================

import * as path from 'node:path';
import { fileURLToPath } from 'node:url';

import { config as dotenvConfig } from 'dotenv';
import { defineConfig } from 'vitest/config';

// Load the repo-root .env so DATABASE_URL / PG_* reach both globalSetup (the
// migrate CLI) and the test workers' createDb(). dotenv does NOT override vars
// already in the environment, so an inline `DATABASE_URL=… pnpm test` still wins.
// vitest.config.ts is at packages/db/, so the root .env is two dirs up.
const configDir = path.dirname(fileURLToPath(import.meta.url));
dotenvConfig({ path: path.resolve(configDir, '..', '..', '.env') });

export default defineConfig({
test: {
environment: 'node',
Expand Down
Loading