-
Notifications
You must be signed in to change notification settings - Fork 28k
/
Copy pathwarn-removed-experimental-config.test.ts
150 lines (133 loc) · 3.74 KB
/
warn-removed-experimental-config.test.ts
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import {
warnOptionHasBeenMovedOutOfExperimental,
warnOptionHasBeenDeprecated,
} from 'next/dist/server/config'
describe('warnOptionHasBeenMovedOutOfExperimental', () => {
let spy: jest.SpyInstance
beforeAll(() => {
spy = jest.spyOn(console, 'warn').mockImplementation(() => {})
})
it('should not log warning message without experimental config', () => {
warnOptionHasBeenMovedOutOfExperimental(
{},
'skipTrailingSlashRedirect',
'skipTrailingSlashRedirect',
'next.config.js',
false
)
warnOptionHasBeenMovedOutOfExperimental(
{
experimental: {},
},
'skipTrailingSlashRedirect',
'skipTrailingSlashRedirect',
'next.config.js',
false
)
expect(spy).not.toHaveBeenCalled()
})
it('should log warning message with removed experimental config', () => {
warnOptionHasBeenMovedOutOfExperimental(
{
experimental: {
skipTrailingSlashRedirect: true,
},
} as any,
'skipTrailingSlashRedirect',
'skipTrailingSlashRedirect',
'next.config.js',
false
)
expect(spy).toHaveBeenCalledWith(
expect.stringContaining('⚠'),
'`experimental.skipTrailingSlashRedirect` has been moved to `skipTrailingSlashRedirect`. Please update your next.config.js file accordingly.'
)
})
it('should log warning message with removed experimental config - complex key', () => {
warnOptionHasBeenMovedOutOfExperimental(
{
experimental: {
relay: true,
},
} as any,
'relay',
'compiler.relay',
'next.config.js',
false
)
expect(spy).toHaveBeenCalledWith(
expect.stringContaining('⚠'),
'`experimental.relay` has been moved to `compiler.relay`. Please update your next.config.js file accordingly.'
)
})
it('should update removed experimental config into new config', () => {
const config = {
experimental: {
skipTrailingSlashRedirect: true,
},
} as any
warnOptionHasBeenMovedOutOfExperimental(
config,
'skipTrailingSlashRedirect',
'skipTrailingSlashRedirect',
'next.config.js',
false
)
expect(config.experimental.skipTrailingSlashRedirect).toBe(true)
expect(config.skipTrailingSlashRedirect).toBe(true)
})
it('should update removed experimental config into new config - complex key', () => {
const config = {
experimental: {
foo: 'bar',
},
} as any
warnOptionHasBeenMovedOutOfExperimental(
config,
'foo',
'deep.prop.baz',
'next.config.js',
false
)
expect(config.experimental.foo).toBe('bar')
expect(config.deep.prop.baz).toBe('bar')
})
it('should show the new key name in the warning', () => {
const config = {
experimental: {
bundlePagesExternals: true,
},
} as any
warnOptionHasBeenMovedOutOfExperimental(
config,
'bundlePagesExternals',
'bundlePagesRouterDependencies',
'next.config.js',
false
)
expect(spy).toHaveBeenCalledWith(
expect.stringContaining('⚠'),
'`experimental.bundlePagesExternals` has been moved to `bundlePagesRouterDependencies`. Please update your next.config.js file accordingly.'
)
})
})
describe('warnOptionHasBeenDeprecated', () => {
let spy: jest.SpyInstance
beforeAll(() => {
spy = jest.spyOn(console, 'warn').mockImplementation(() => {})
})
it('should warn experimental.appDir has been deprecated', () => {
const config = {
experimental: {
appDir: true,
},
} as any
warnOptionHasBeenDeprecated(
config,
'experimental.appDir',
'experimental.appDir has been removed',
false
)
expect(spy).toHaveBeenCalled()
})
})