- 清理废弃的 CI/CD 工作流文件与 dogfood 输出 - 添加 vitest 测试环境配置(mocks、setup 文件) - 添加算法、服务、页面、工具类的单元测试 - 更新 vitest 配置、依赖与文档
39 lines
1.0 KiB
TypeScript
39 lines
1.0 KiB
TypeScript
import { vi } from 'vitest'
|
|
|
|
const uni = {
|
|
getStorageSync: vi.fn((key: string) => {
|
|
const store: Record<string, string> = (globalThis as any).__uniStorage__ ?? {}
|
|
return store[key] ?? ''
|
|
}),
|
|
setStorageSync: vi.fn((key: string, value: any) => {
|
|
if (!(globalThis as any).__uniStorage__) (globalThis as any).__uniStorage__ = {}
|
|
;(globalThis as any).__uniStorage__[key] = JSON.stringify(value)
|
|
}),
|
|
removeStorageSync: vi.fn((key: string) => {
|
|
if ((globalThis as any).__uniStorage__) delete (globalThis as any).__uniStorage__[key]
|
|
}),
|
|
clearStorageSync: vi.fn(() => {
|
|
;(globalThis as any).__uniStorage__ = {}
|
|
}),
|
|
showToast: vi.fn(),
|
|
showLoading: vi.fn(),
|
|
hideLoading: vi.fn(),
|
|
showModal: vi.fn(),
|
|
navigateTo: vi.fn(),
|
|
navigateBack: vi.fn(),
|
|
redirectTo: vi.fn(),
|
|
switchTab: vi.fn(),
|
|
reLaunch: vi.fn(),
|
|
getSystemInfoSync: vi.fn(() => ({
|
|
platform: 'devtools',
|
|
screenWidth: 375,
|
|
screenHeight: 812,
|
|
})),
|
|
}
|
|
|
|
vi.stubGlobal('uni', uni)
|
|
|
|
beforeEach(() => {
|
|
;(globalThis as any).__uniStorage__ = {}
|
|
})
|