-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvitest.setup.ts
More file actions
50 lines (46 loc) · 1.49 KB
/
Copy pathvitest.setup.ts
File metadata and controls
50 lines (46 loc) · 1.49 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
import { beforeAll, afterAll, beforeEach } from "vitest";
// Set required environment variables for tests
beforeAll(() => {
process.env.DATABASE_URL =
process.env.DATABASE_URL || "postgresql://test:test@localhost:5432/cku_test";
process.env.REDIS_URL =
process.env.REDIS_URL || "redis://localhost:6379/1";
process.env.JWT_SECRET =
process.env.JWT_SECRET ||
"test_secret_key_that_is_long_enough_for_testing_purposes_1234567890";
process.env.NODE_ENV = process.env.NODE_ENV || "test";
process.env.CKU_ALLOWED_ORIGINS = "http://localhost:3000,http://localhost:7473";
});
// Mock localStorage for browser tests running in node environment
if (typeof (global as any).localStorage === 'undefined') {
const store: Record<string, string> = {};
(global as any).localStorage = {
getItem: (key: string) => store[key] || null,
setItem: (key: string, value: string) => {
store[key] = value.toString();
},
removeItem: (key: string) => {
delete store[key];
},
clear: () => {
Object.keys(store).forEach(key => delete store[key]);
},
key: (index: number) => {
const keys = Object.keys(store);
return keys[index] || null;
},
get length() {
return Object.keys(store).length;
},
};
}
// Optional: Set up global mocks if needed
beforeEach(() => {
// Clear any previous mocks between tests
if ((global as any).localStorage) {
(global as any).localStorage.clear();
}
});
afterAll(() => {
// Cleanup after all tests
});