46 lines
1.5 KiB
TypeScript
46 lines
1.5 KiB
TypeScript
import '@testing-library/jest-dom'
|
|
|
|
/**
|
|
* Vitest Setup File
|
|
*
|
|
* This file runs before each test file in the Vitest environment.
|
|
* It validates that tests are running against the development database
|
|
* to prevent accidental data corruption.
|
|
*/
|
|
|
|
// Check if DATABASE_URL is set and points to dev database
|
|
const databaseUrl = process.env.DATABASE_URL;
|
|
|
|
if (databaseUrl) {
|
|
const isDevDatabase = databaseUrl.includes('euchre_camp_dev');
|
|
const isProductionDatabase =
|
|
databaseUrl.includes('euchre_camp') &&
|
|
!databaseUrl.includes('_dev') &&
|
|
!databaseUrl.includes('_dev_');
|
|
|
|
if (isProductionDatabase) {
|
|
console.error('');
|
|
console.error('='.repeat(80));
|
|
console.error('CRITICAL ERROR: Tests are attempting to run against PRODUCTION database!');
|
|
console.error('='.repeat(80));
|
|
console.error('');
|
|
console.error('Current DATABASE_URL:', databaseUrl);
|
|
console.error('');
|
|
console.error('Tests MUST run against the development database (euchre_camp_dev)');
|
|
console.error('');
|
|
console.error('To fix this:');
|
|
console.error(' 1. Run: npm run test:run');
|
|
console.error(' 2. Or set: DATABASE_URL="postgresql://euchre_camp:password@dhg.lol:5432/euchre_camp_dev"');
|
|
console.error('');
|
|
console.error('Aborting test execution to prevent data corruption.');
|
|
console.error('');
|
|
process.exit(1);
|
|
}
|
|
|
|
if (isDevDatabase) {
|
|
console.log('✓ Tests running against development database (euchre_camp_dev)');
|
|
}
|
|
} else {
|
|
console.warn('⚠ No DATABASE_URL set - tests may fail or use unexpected database');
|
|
}
|