feat: 灵犀 Studio Web UI 定制版
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
import { vi } from 'vitest'
|
||||
|
||||
// Vite injects this at build time; unit tests need a stable fallback.
|
||||
;(globalThis as any).__APP_VERSION__ = 'test'
|
||||
// Client-only setup (window/localStorage only exist in jsdom)
|
||||
if (typeof window !== 'undefined') {
|
||||
// Mock window.matchMedia
|
||||
Object.defineProperty(window, 'matchMedia', {
|
||||
writable: true,
|
||||
value: vi.fn().mockImplementation((query: string) => ({
|
||||
matches: false,
|
||||
media: query,
|
||||
onchange: null,
|
||||
addListener: vi.fn(),
|
||||
removeListener: vi.fn(),
|
||||
addEventListener: vi.fn(),
|
||||
removeEventListener: vi.fn(),
|
||||
dispatchEvent: vi.fn(),
|
||||
})),
|
||||
})
|
||||
|
||||
// Mock localStorage
|
||||
const store: Record<string, string> = {}
|
||||
Object.defineProperty(window, 'localStorage', {
|
||||
value: {
|
||||
getItem: vi.fn((key: string) => store[key] ?? null),
|
||||
setItem: vi.fn((key: string, value: string) => { store[key] = value }),
|
||||
removeItem: vi.fn((key: string) => { delete store[key] }),
|
||||
clear: vi.fn(() => { for (const k of Object.keys(store)) delete store[k] }),
|
||||
get length() { return Object.keys(store).length },
|
||||
key: vi.fn((i: number) => Object.keys(store)[i] ?? null),
|
||||
},
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user