fix: resolve test environment loading race condition in CI
- Move getTestConfig() calls from module level to test execution time - Add CI-specific debug logging to diagnose environment loading issues - Add verification step in CI workflow to check .env.test availability - Ensure environment variables are loaded before tests access config The issue was that config was being accessed at module import time, which could happen before the global setup runs in some CI environments.
This commit is contained in:
@@ -11,10 +11,26 @@ import { existsSync } from 'fs';
|
||||
|
||||
// Load test environment variables
|
||||
export function loadTestEnvironment(): void {
|
||||
// CI Debug logging
|
||||
const isCI = process.env.CI === 'true';
|
||||
|
||||
// Load base test environment
|
||||
const testEnvPath = path.resolve(process.cwd(), '.env.test');
|
||||
|
||||
if (isCI) {
|
||||
console.log('[CI-DEBUG] Looking for .env.test at:', testEnvPath);
|
||||
console.log('[CI-DEBUG] File exists?', existsSync(testEnvPath));
|
||||
}
|
||||
|
||||
if (existsSync(testEnvPath)) {
|
||||
dotenv.config({ path: testEnvPath });
|
||||
const result = dotenv.config({ path: testEnvPath });
|
||||
if (isCI && result.error) {
|
||||
console.error('[CI-DEBUG] Failed to load .env.test:', result.error);
|
||||
} else if (isCI && result.parsed) {
|
||||
console.log('[CI-DEBUG] Successfully loaded', Object.keys(result.parsed).length, 'env vars from .env.test');
|
||||
}
|
||||
} else if (isCI) {
|
||||
console.warn('[CI-DEBUG] .env.test file not found, will use defaults only');
|
||||
}
|
||||
|
||||
// Load local test overrides (for sensitive values)
|
||||
|
||||
Reference in New Issue
Block a user