Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
Fixes integration test failures caused by missing DATABASE_URL environment variable. Changes: - Add dotenv as dev dependency to load .env.test in vitest setup - Add .env.test to .gitignore to prevent committing test credentials - Create .env.test.example with warning comments for documentation - Add conditional test skipping when DATABASE_URL is not available - Add DATABASE_URL format validation in vitest setup - Add error handling to test cleanup to prevent silent failures - Remove filesystem path disclosure from error messages The fix allows integration tests to: - Load DATABASE_URL from .env.test locally for developers with database setup - Skip gracefully if DATABASE_URL is not available (no database running) - Connect to postgres service in CI where DATABASE_URL is explicitly provided Tests affected: auth-rls.integration.spec.ts and other integration tests requiring real database connections. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
32 lines
1.1 KiB
TypeScript
32 lines
1.1 KiB
TypeScript
import "reflect-metadata";
|
|
import * as dotenv from "dotenv";
|
|
import * as path from "path";
|
|
import * as fs from "fs";
|
|
|
|
// Load environment variables from .env.test if it exists
|
|
// This allows local integration tests to run with a local database
|
|
// CI environments explicitly provide DATABASE_URL in the test step
|
|
const envTestPath = path.resolve(__dirname, ".env.test");
|
|
if (fs.existsSync(envTestPath)) {
|
|
const result = dotenv.config({ path: envTestPath });
|
|
if (result.error) {
|
|
throw new Error(
|
|
`Failed to load test environment configuration: ${result.error.message}\n` +
|
|
`Ensure .env.test exists in the api directory and is properly formatted.`
|
|
);
|
|
}
|
|
|
|
// Validate DATABASE_URL format if provided
|
|
if (process.env.DATABASE_URL && !process.env.DATABASE_URL.startsWith("postgresql://")) {
|
|
throw new Error(
|
|
"Invalid DATABASE_URL format in .env.test. " +
|
|
"Expected format: postgresql://user:password@host:port/database"
|
|
);
|
|
}
|
|
|
|
// Log only in debug mode
|
|
if (process.env.DEBUG) {
|
|
console.debug("Test environment variables loaded from .env.test");
|
|
}
|
|
}
|