-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjest.setup.js
More file actions
115 lines (103 loc) · 3.38 KB
/
Copy pathjest.setup.js
File metadata and controls
115 lines (103 loc) · 3.38 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
require('@testing-library/jest-dom')
const dotenv = require('dotenv')
const path = require('path')
// Load test environment variables
dotenv.config({ path: path.resolve(process.cwd(), '.env.test') })
// Ensure required environment variables are set
process.env.NEXT_PUBLIC_SUPABASE_URL = process.env.NEXT_PUBLIC_SUPABASE_URL || 'http://127.0.0.1:54321'
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY = process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY || 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6ImFub24iLCJleHAiOjE5ODM4MTI5OTZ9.CRXP1A7WOeoJeXxjNni43kdQwgnWNReilDMblYTn_I0'
process.env.SUPABASE_SERVICE_ROLE_KEY = process.env.SUPABASE_SERVICE_ROLE_KEY || 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImV4cCI6MTk4MzgxMjk5Nn0.EGIM96RAZx35lJzdJsyH-qQwv8Hdp7fsn3W0YpN81IU'
process.env.NODE_ENV = 'test'
// Global test utilities
const { TextEncoder, TextDecoder } = require('util')
global.TextEncoder = TextEncoder
global.TextDecoder = TextDecoder
// Polyfill Web APIs for Next.js integration tests
if (typeof global.Request === 'undefined') {
global.Request = class Request {
constructor(input, init) {
this.url = typeof input === 'string' ? input : input.url
this.method = init?.method || 'GET'
this.headers = new Map(Object.entries(init?.headers || {}))
this.body = init?.body || null
}
}
}
if (typeof global.Response === 'undefined') {
global.Response = class Response {
constructor(body, init) {
this.body = body
this.status = init?.status || 200
this.headers = new Map(Object.entries(init?.headers || {}))
}
json() {
return Promise.resolve(JSON.parse(this.body))
}
}
}
if (typeof global.Headers === 'undefined') {
global.Headers = class Headers extends Map {
get(name) {
return super.get(name.toLowerCase())
}
set(name, value) {
return super.set(name.toLowerCase(), value)
}
}
}
// Increase timeout for integration tests
jest.setTimeout(30000)
// Import test helpers and custom matchers (converted to require for Jest compatibility)
// Note: test-helpers.ts will be compiled by Jest's TypeScript transform
// Mock Next.js router for tests that need it
jest.mock('next/navigation', () => ({
useRouter() {
return {
push: jest.fn(),
replace: jest.fn(),
prefetch: jest.fn(),
back: jest.fn(),
forward: jest.fn(),
refresh: jest.fn(),
}
},
usePathname() {
return '/'
},
useSearchParams() {
return new URLSearchParams()
},
}))
// Mock Next.js Image component
jest.mock('next/image', () => {
const React = require('react');
return {
__esModule: true,
default: React.forwardRef(function Image(props, ref) {
const { src, alt, width, height, className, ...rest } = props;
// eslint-disable-next-line @next/next/no-img-element, jsx-a11y/alt-text
return React.createElement('img', {
ref,
src,
alt,
width,
height,
className,
...rest
});
})
};
})
// Mock console methods to reduce noise in tests
const originalError = console.error
beforeAll(() => {
console.error = (...args) => {
if (typeof args[0] === 'string' && args[0].includes('Warning: ReactDOM.render is no longer supported')) {
return
}
originalError.call(console, ...args)
}
})
afterAll(() => {
console.error = originalError
})