feat: 初始化 Gitea Action 发送钉钉机器人消息项目
This commit is contained in:
44
tests/setup/global-setup.js
Normal file
44
tests/setup/global-setup.js
Normal file
@@ -0,0 +1,44 @@
|
||||
/**
|
||||
* 全局测试设置文件
|
||||
* 在所有测试运行前执行的初始化代码
|
||||
*/
|
||||
|
||||
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);
|
||||
});
|
||||
Reference in New Issue
Block a user