forked from codinit-dev/codinit-dev
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.ts
More file actions
92 lines (79 loc) · 2.29 KB
/
Copy pathsetup.ts
File metadata and controls
92 lines (79 loc) · 2.29 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import { expect, afterEach, beforeAll, vi } from 'vitest';
import { cleanup } from '@testing-library/react';
import * as matchers from '@testing-library/jest-dom/matchers';
// Extend expect with jest-dom matchers
expect.extend(matchers);
// Clean up after each test
afterEach(() => {
cleanup();
});
// Mock environment variables
beforeAll(() => {
// Set up test environment variables
process.env.NODE_ENV = 'test';
process.env.VITE_APP_ENV = 'test';
// Mock console methods to reduce noise in tests
const originalConsoleError = console.error;
const originalConsoleWarn = console.warn;
console.error = (...args: any[]) => {
// Only show errors that aren't from React testing library
if (!args[0]?.includes?.('Warning: ReactDOMTestUtils')) {
originalConsoleError(...args);
}
};
console.warn = (...args: any[]) => {
// Only show warnings that aren't from React testing library
if (!args[0]?.includes?.('Warning: ReactDOMTestUtils')) {
originalConsoleWarn(...args);
}
};
});
// Mock fetch globally
(globalThis as any).fetch = vi.fn();
// Mock ResizeObserver
(globalThis as any).ResizeObserver = vi.fn().mockImplementation(() => ({
observe: vi.fn(),
unobserve: vi.fn(),
disconnect: vi.fn(),
}));
// Mock IntersectionObserver
(globalThis as any).IntersectionObserver = vi.fn().mockImplementation(() => ({
observe: vi.fn(),
unobserve: vi.fn(),
disconnect: vi.fn(),
}));
// Mock matchMedia
Object.defineProperty(window, 'matchMedia', {
writable: true,
value: vi.fn().mockImplementation((query: string) => ({
matches: false,
media: query,
onchange: null,
addListener: vi.fn(), // deprecated
removeListener: vi.fn(), // deprecated
addEventListener: vi.fn(),
removeEventListener: vi.fn(),
dispatchEvent: vi.fn(),
})),
});
// Mock localStorage
const localStorageMock = {
getItem: vi.fn(),
setItem: vi.fn(),
removeItem: vi.fn(),
clear: vi.fn(),
length: 0,
key: vi.fn(),
} as Storage;
(globalThis as any).localStorage = localStorageMock;
// Mock sessionStorage
const sessionStorageMock = {
getItem: vi.fn(),
setItem: vi.fn(),
removeItem: vi.fn(),
clear: vi.fn(),
length: 0,
key: vi.fn(),
} as Storage;
(globalThis as any).sessionStorage = sessionStorageMock;
// Skip WebSocket mocking for now to avoid type issues