| 123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- // 测试环境全局设置
- import { jest } from '@jest/globals';
- // 全局测试超时设置
- jest.setTimeout(10000);
- // 全局测试前置处理
- beforeAll(() => {
- // 设置测试环境变量
- process.env.NODE_ENV = 'test';
- // 抑制控制台输出(测试中)
- jest.spyOn(console, 'log').mockImplementation(() => {});
- jest.spyOn(console, 'error').mockImplementation(() => {});
- jest.spyOn(console, 'warn').mockImplementation(() => {});
- jest.spyOn(console, 'info').mockImplementation(() => {});
- });
- // 全局测试后置清理
- afterAll(() => {
- // 恢复控制台输出
- jest.restoreAllMocks();
- });
- // 每个测试后的清理
- afterEach(() => {
- jest.clearAllMocks();
- });
- // 全局测试工具函数
- globalThis.createTestContext = () => ({
- timestamp: new Date().toISOString(),
- requestId: `test_${Math.random().toString(36).substr(2, 9)}`
- });
- // 类型声明
- declare global {
- // eslint-disable-next-line no-var
- var createTestContext: () => {
- timestamp: string;
- requestId: string;
- };
- }
- export {};
|