2026-02-27 17:05:05 +00:00
|
|
|
/**
|
|
|
|
|
* Vitest globalSetup: push schema once before all db tests.
|
|
|
|
|
* Runs in the main vitest process, outside test workers.
|
|
|
|
|
*/
|
|
|
|
|
import { execSync } from 'node:child_process';
|
|
|
|
|
|
|
|
|
|
const TEST_DATABASE_URL = process.env['DATABASE_URL'] ??
|
|
|
|
|
'postgresql://mcpctl:mcpctl_test@localhost:5433/mcpctl_test';
|
|
|
|
|
|
|
|
|
|
export function setup(): void {
|
2026-03-07 00:39:25 +00:00
|
|
|
try {
|
|
|
|
|
execSync('npx prisma db push --force-reset --skip-generate', {
|
|
|
|
|
cwd: new URL('..', import.meta.url).pathname,
|
|
|
|
|
env: {
|
|
|
|
|
...process.env,
|
|
|
|
|
DATABASE_URL: TEST_DATABASE_URL,
|
|
|
|
|
PRISMA_USER_CONSENT_FOR_DANGEROUS_AI_ACTION: 'yes',
|
|
|
|
|
},
|
|
|
|
|
stdio: 'pipe',
|
|
|
|
|
});
|
|
|
|
|
} catch {
|
|
|
|
|
// Test DB not available — db-specific tests will fail individually,
|
|
|
|
|
// but non-db tests can still run.
|
|
|
|
|
console.warn('[global-setup] Test database not available, skipping schema push');
|
|
|
|
|
}
|
2026-02-27 17:05:05 +00:00
|
|
|
}
|