45 lines
1.3 KiB
TypeScript
45 lines
1.3 KiB
TypeScript
import { execSync } from 'child_process';
|
|
|
|
// E2E 测试设置
|
|
// 在真实数据库上运行测试前的准备工作
|
|
|
|
beforeAll(async () => {
|
|
// 检查 DATABASE_URL 环境变量
|
|
if (!process.env.DATABASE_URL) {
|
|
console.warn(
|
|
'WARNING: DATABASE_URL not set. E2E tests require a real PostgreSQL database.',
|
|
);
|
|
console.warn('Set DATABASE_URL to a test database before running E2E tests.');
|
|
}
|
|
|
|
// 检查 REDIS_URL 环境变量
|
|
if (!process.env.REDIS_URL && !process.env.REDIS_HOST) {
|
|
console.warn(
|
|
'WARNING: REDIS_URL/REDIS_HOST not set. Some E2E tests may fail.',
|
|
);
|
|
}
|
|
|
|
// 尝试运行 Prisma 迁移(仅在 CI 环境或明确需要时)
|
|
if (process.env.RUN_MIGRATIONS === 'true') {
|
|
try {
|
|
console.log('Running Prisma migrations...');
|
|
execSync('npx prisma migrate deploy', {
|
|
cwd: process.cwd(),
|
|
stdio: 'inherit',
|
|
});
|
|
console.log('Migrations completed.');
|
|
} catch (error) {
|
|
console.error('Failed to run migrations:', error);
|
|
throw error;
|
|
}
|
|
}
|
|
});
|
|
|
|
afterAll(async () => {
|
|
// 清理测试数据(可选)
|
|
// 在真实测试中,可能需要清理测试创建的数据
|
|
});
|
|
|
|
// 增加超时时间,因为 E2E 测试可能需要更长时间
|
|
jest.setTimeout(60000);
|