/** * 全局测试设置文件 * 在所有测试运行前执行的初始化代码 */ import { afterAll, afterEach, beforeAll, beforeEach } from 'vitest'; // 全局变量存储原始环境变量 let originalEnv = {}; beforeAll(() => { // 保存原始环境变量 originalEnv = { ...process.env }; // 设置测试环境标识 process.env.NODE_ENV = 'test'; // 禁用网络请求(可选) process.env.DISABLE_NETWORK = 'true'; }); afterAll(() => { // 恢复原始环境变量 process.env = originalEnv; }); beforeEach(() => { // 每个测试前的清理工作 // 清理可能的环境变量污染 }); afterEach(() => { // 每个测试后的清理工作 // 重置模块状态等 }); // 全局错误处理 process.on('unhandledRejection', (reason, promise) => { console.error('Unhandled Rejection at:', promise, 'reason:', reason); }); process.on('uncaughtException', error => { console.error('Uncaught Exception:', error); });