-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathvitest.setup.ts
More file actions
77 lines (71 loc) · 2.53 KB
/
vitest.setup.ts
File metadata and controls
77 lines (71 loc) · 2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import { vi } from 'vitest';
import 'vitest-canvas-mock';
// Polyfill for structuredClone in test environment
if (typeof globalThis.structuredClone !== 'function') {
globalThis.structuredClone = <T>(obj: T): T => {
return JSON.parse(JSON.stringify(obj));
};
}
// Mock performance API (needed before modules are imported)
globalThis.performance = {
now: () => Date.now(),
timing: {},
navigation: {},
timeOrigin: Date.now(),
mark: () => undefined,
measure: () => undefined,
clearMarks: () => undefined,
clearMeasures: () => undefined,
getEntries: () => [],
getEntriesByName: () => [],
getEntriesByType: () => [],
} as unknown as Performance;
// Mock fetch API (jsdom does not provide it)
if (typeof globalThis.fetch === 'undefined') {
globalThis.fetch = () => Promise.reject(new Error('fetch not mocked'));
}
// Mock Supabase client
vi.mock('./src/user-account/supabase-client', () => ({
SUPABASE_URL: 'https://test.supabase.co',
SUPABASE_ANON_KEY: 'test-key',
isSupabaseApprovedDomain: true,
getSupabaseClient: vi.fn(() => ({
auth: {
getSession: vi.fn().mockResolvedValue({ data: { session: null }, error: null }),
onAuthStateChange: vi.fn(() => ({
data: { subscription: { unsubscribe: vi.fn() } },
})),
},
})),
}));
// Mock Auth module
vi.mock('./src/user-account/auth', () => ({
Auth: {
initializeAuth: vi.fn().mockResolvedValue(null),
signUp: vi.fn().mockResolvedValue({ data: null, error: null }),
signIn: vi.fn().mockResolvedValue({ data: null, error: null }),
signInWithOAuthProvider: vi.fn(),
updatePassword: vi.fn().mockResolvedValue({ error: null }),
updateProfile: vi.fn().mockResolvedValue(null),
signOut: vi.fn().mockResolvedValue(undefined),
getCurrentUser: vi.fn().mockResolvedValue(null),
getUserProfile: vi.fn().mockResolvedValue(null),
isLoggedIn: vi.fn().mockResolvedValue(false),
setSession: vi.fn().mockResolvedValue(undefined),
onAuthStateChange: vi.fn(),
getAccessToken: vi.fn().mockResolvedValue(null),
getSession: vi.fn().mockResolvedValue(null),
refreshSession: vi.fn().mockResolvedValue(null),
isTokenExpired: vi.fn().mockResolvedValue(false),
getValidAccessToken: vi.fn().mockResolvedValue(null),
},
}));
// Mock UserDataService
vi.mock('./src/user-account/user-data-service', () => ({
initUserDataService: vi.fn(),
getUserDataService: vi.fn(() => ({
getProgressData: vi.fn().mockResolvedValue(null),
saveProgressData: vi.fn().mockResolvedValue(undefined),
isInitialized: true,
})),
}));