-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjest.setup.js
More file actions
97 lines (84 loc) · 2.6 KB
/
jest.setup.js
File metadata and controls
97 lines (84 loc) · 2.6 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
93
94
95
96
97
// Jest 전역 설정 파일
// 테스트 환경 변수 설정
process.env.NODE_ENV = 'test';
process.env.DATABASE_PATH = ':memory:'; // 메모리 데이터베이스 사용
// 콘솔 로그 억제 (필요한 경우)
if (process.env.SUPPRESS_LOGS === 'true') {
global.console = {
...console,
log: jest.fn(),
error: jest.fn(),
warn: jest.fn(),
info: jest.fn(),
};
}
// 전역 테스트 유틸리티
global.testUtils = {
// 시간 관련 유틸리티
mockDate: (dateString) => {
const mockDate = new Date(dateString);
jest.spyOn(global, 'Date').mockImplementation(() => mockDate);
return mockDate;
},
// 랜덤 문자열 생성
randomString: (length = 10) => {
return Math.random().toString(36).substring(2, length + 2);
},
// 랜덤 사용자 ID 생성
randomUserId: () => {
return `user_${Math.random().toString(36).substring(2, 10)}`;
},
// 랜덤 채널 ID 생성
randomChannelId: () => {
return `channel_${Math.random().toString(36).substring(2, 10)}`;
},
// 테스트용 리마인더 데이터 생성
createMockReminder: (overrides = {}) => {
return {
id: Math.floor(Math.random() * 1000) + 1,
user_id: global.testUtils.randomUserId(),
channel_id: global.testUtils.randomChannelId(),
message: '테스트 리마인더',
remind_time: new Date(Date.now() + 3600000).toISOString(), // 1시간 후
repeat_type: null,
repeat_interval: null,
created_at: new Date().toISOString(),
...overrides
};
},
// 테스트용 반복 리마인더 데이터 생성
createMockRepeatReminder: (type = 'days', interval = 1, overrides = {}) => {
return global.testUtils.createMockReminder({
repeat_type: type,
repeat_interval: interval,
...overrides
});
},
// 테스트용 스케줄 리마인더 데이터 생성
createMockScheduledReminder: (schedule, overrides = {}) => {
return global.testUtils.createMockReminder({
repeat_type: 'scheduled',
repeat_interval: JSON.stringify(schedule),
...overrides
});
}
};
// 테스트 시작 전 실행
beforeAll(async () => {
// 전역 설정이 필요한 경우 여기에 추가
});
// 각 테스트 전 실행
beforeEach(() => {
// 각 테스트마다 초기화가 필요한 경우 여기에 추가
jest.clearAllTimers();
});
// 각 테스트 후 실행
afterEach(() => {
// 테스트 후 정리가 필요한 경우 여기에 추가
jest.restoreAllMocks();
jest.useRealTimers();
});
// 모든 테스트 종료 후 실행
afterAll(async () => {
// 전역 정리가 필요한 경우 여기에 추가
});