forked from FRONT-END-BOOTCAMP-PLUS-5/Ttabook
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjest.setup.js
More file actions
97 lines (86 loc) · 2.37 KB
/
Copy pathjest.setup.js
File metadata and controls
97 lines (86 loc) · 2.37 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
import '@testing-library/jest-dom';
import util from 'node:util';
import { jest } from '@jest/globals';
// 테스트 환경 변수 설정
process.env.SUPABASE_URL = 'https://test.supabase.co';
process.env.SUPABASE_SERVICE_ROLE_KEY = 'test-service-role-key';
process.env.JWT_SECRET = 'test-jwt-secret-for-unit-tests-that-is-long-enough';
process.env.BCRYPT_ROUNDS = '12';
process.env.NODE_ENV = 'test';
// Node.js 환경 폴리필
if (typeof TextEncoder === 'undefined') {
global.TextEncoder = util.TextEncoder;
}
if (typeof TextDecoder === 'undefined') {
global.TextDecoder = util.TextDecoder;
}
// crypto 모듈 polyfill
import { webcrypto } from 'node:crypto';
if (typeof global.crypto === 'undefined') {
global.crypto = webcrypto;
}
// structuredClone 폴리필 (Node.js 18+에서 필요)
if (typeof structuredClone === 'undefined') {
global.structuredClone = (obj) => JSON.parse(JSON.stringify(obj));
}
// Request/Response 폴리필 (jsdom 환경용)
import { Request, Response } from 'whatwg-fetch';
if (typeof global.Request === 'undefined') {
global.Request = Request;
}
if (typeof global.Response === 'undefined') {
global.Response = Response;
}
// Global mocks for Node.js environment
global.fetch = global.fetch || require('whatwg-fetch').fetch;
// 공통 Mock 설정
global.mockSupabaseClient = null;
global.createMockSupabaseClient = () => {
const mockSelect = jest.fn();
const mockInsert = jest.fn();
const mockEq = jest.fn();
const mockSingle = jest.fn();
const mockUpdate = jest.fn();
const mockDelete = jest.fn();
const mockSupabaseClient = {
from: jest.fn(() => ({
select: mockSelect,
insert: mockInsert,
update: mockUpdate,
delete: mockDelete,
})),
};
mockSelect.mockReturnValue({
eq: mockEq,
single: mockSingle,
});
mockInsert.mockReturnValue({
select: mockSelect,
single: mockSingle,
});
mockEq.mockReturnValue({
single: mockSingle,
});
return {
client: mockSupabaseClient,
mocks: {
select: mockSelect,
insert: mockInsert,
eq: mockEq,
single: mockSingle,
update: mockUpdate,
delete: mockDelete,
},
};
};
beforeEach(() => {
// Next.js headers 모킹
jest.unstable_mockModule('next/headers', () => ({
cookies: jest.fn(() => ({
getAll: jest.fn(() => []),
get: jest.fn(),
set: jest.fn(),
delete: jest.fn(),
})),
}));
});