Some checks reported errors
continuous-integration/drone/push Build was killed
- 搭建 api、auth、utils 等逻辑模块 - 通过 tsc、eslint、vitest 测试验证 BREAKING CHANGE: 新镜像分支
54 lines
1.1 KiB
TypeScript
54 lines
1.1 KiB
TypeScript
/**
|
|
* 测试设置文件
|
|
* 配置全局测试环境和共享设置
|
|
*/
|
|
|
|
import { vi } from 'vitest';
|
|
|
|
// 模拟浏览器API
|
|
Object.defineProperty(window, 'localStorage', {
|
|
value: {
|
|
getItem: vi.fn(),
|
|
setItem: vi.fn(),
|
|
removeItem: vi.fn(),
|
|
clear: vi.fn()
|
|
},
|
|
writable: true
|
|
});
|
|
|
|
Object.defineProperty(window, 'sessionStorage', {
|
|
value: {
|
|
getItem: vi.fn(),
|
|
setItem: vi.fn(),
|
|
removeItem: vi.fn(),
|
|
clear: vi.fn()
|
|
},
|
|
writable: true
|
|
});
|
|
|
|
// 模拟IntersectionObserver
|
|
globalThis.IntersectionObserver = vi.fn().mockImplementation(() => ({
|
|
observe: vi.fn(),
|
|
unobserve: vi.fn(),
|
|
disconnect: vi.fn()
|
|
}));
|
|
|
|
// 模拟ResizeObserver
|
|
globalThis.ResizeObserver = vi.fn().mockImplementation(() => ({
|
|
observe: vi.fn(),
|
|
unobserve: vi.fn(),
|
|
disconnect: vi.fn()
|
|
}));
|
|
|
|
// 模拟requestAnimationFrame
|
|
globalThis.requestAnimationFrame = vi.fn((cb: FrameRequestCallback) => setTimeout(cb, 0));
|
|
|
|
// 模拟cancelAnimationFrame
|
|
globalThis.cancelAnimationFrame = vi.fn((id: number) => clearTimeout(id));
|
|
|
|
// 模拟fetch
|
|
globalThis.fetch = vi.fn();
|
|
|
|
// 设置环境变量
|
|
process.env.NODE_ENV = 'test';
|