forked from payloadcms/website
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjest.setup.js
More file actions
66 lines (58 loc) · 1.67 KB
/
Copy pathjest.setup.js
File metadata and controls
66 lines (58 loc) · 1.67 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
/**
* Jest Setup File
*
* Runs before each test suite.
* Configure global test utilities, mocks, and environment.
*/
// Suppress console output during tests unless explicitly checking for it
const originalWarn = console.warn
const originalError = console.error
global.console.warn = (...args) => {
// Filter out known warnings
if (
args[0]?.includes?.('[Cache]') ||
args[0]?.includes?.('[Storage]') ||
args[0]?.includes?.('[Images]')
) {
return // Suppress capability warnings in tests
}
originalWarn.call(console, ...args)
}
global.console.error = (...args) => {
// Filter out known errors during initialization
if (
args[0]?.includes?.('Failed to initialize') ||
args[0]?.includes?.('not available')
) {
return
}
originalError.call(console, ...args)
}
// Mock environment variables
process.env.NEXT_PUBLIC_SITE_URL = 'http://localhost:3000'
process.env.PAYLOAD_SECRET = 'test-secret'
// Mock Next.js router
jest.mock('next/router', () => ({
useRouter: () => ({
push: jest.fn(),
pathname: '/',
query: {},
asPath: '/',
}),
}))
// Mock Next.js navigation
jest.mock('next/navigation', () => ({
useRouter: () => ({
push: jest.fn(),
refresh: jest.fn(),
}),
usePathname: () => '/',
useSearchParams: () => new URLSearchParams(),
}))
// Mock fetch globally if needed
if (typeof global.fetch === 'undefined') {
global.fetch = jest.fn()
}
// Deprecation warnings are suppressed via NODE_OPTIONS=--no-deprecation in the `test` script.
// Don't reassign process.noDeprecation here: once the flag is set it's a read-only property
// (Node 24) and assigning throws "Cannot assign to read only property 'noDeprecation'".