Initial commit: add .gitignore and README
This commit is contained in:
34
tests/load-env.ts
Normal file
34
tests/load-env.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
/**
|
||||
* Load test environment variables
|
||||
* This file is loaded before tests run
|
||||
*/
|
||||
import { config } from 'dotenv';
|
||||
import { resolve } from 'path';
|
||||
|
||||
// Try to load .env.test first, fall back to .env
|
||||
const envPath = resolve(process.cwd(), '.env.test');
|
||||
config({ path: envPath });
|
||||
|
||||
// Also load regular .env for fallback values
|
||||
config();
|
||||
|
||||
// Ensure NODE_ENV is set to test
|
||||
process.env.NODE_ENV = 'test';
|
||||
|
||||
// Set default TEST_DATABASE_URL if not set
|
||||
if (!process.env.TEST_DATABASE_URL) {
|
||||
process.env.TEST_DATABASE_URL =
|
||||
process.env.DATABASE_URL?.replace(/\/[^/]+$/, '/dbis_core_test') ||
|
||||
'postgresql://postgres:postgres@localhost:5434/dbis_core_test';
|
||||
}
|
||||
|
||||
// Use TEST_DATABASE_URL as DATABASE_URL for tests (so source code uses test DB)
|
||||
if (process.env.TEST_DATABASE_URL && !process.env.DATABASE_URL) {
|
||||
process.env.DATABASE_URL = process.env.TEST_DATABASE_URL;
|
||||
}
|
||||
|
||||
// Set default JWT_SECRET for tests if not set
|
||||
if (!process.env.JWT_SECRET) {
|
||||
process.env.JWT_SECRET = 'test-secret-key-for-testing-only';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user