@@ -22,20 +22,26 @@ describe('headers', () => {
22
22
23
23
setVaryHeaders ( headers , request , defaultConfig )
24
24
25
- expect ( headers . set ) . toBeCalledWith ( 'netlify-vary' , 'cookie=__prerender_bypass|__next_preview_data' )
25
+ expect ( headers . set ) . toBeCalledWith (
26
+ 'netlify-vary' ,
27
+ 'cookie=__prerender_bypass|__next_preview_data' ,
28
+ )
26
29
} )
27
30
28
31
test ( 'with expected vary headers' , ( ) => {
29
32
const givenHeaders = {
30
- ' vary' : 'Accept, Accept-Language' ,
33
+ vary : 'Accept, Accept-Language' ,
31
34
}
32
35
const headers = new Headers ( givenHeaders )
33
36
const request = new Request ( defaultUrl )
34
37
vi . spyOn ( headers , 'set' )
35
38
36
39
setVaryHeaders ( headers , request , defaultConfig )
37
40
38
- expect ( headers . set ) . toBeCalledWith ( 'netlify-vary' , 'header=Accept|Accept-Language,cookie=__prerender_bypass|__next_preview_data' )
41
+ expect ( headers . set ) . toBeCalledWith (
42
+ 'netlify-vary' ,
43
+ 'header=Accept|Accept-Language,cookie=__prerender_bypass|__next_preview_data' ,
44
+ )
39
45
} )
40
46
41
47
test ( 'with no languages if i18n config has localeDetection disabled' , ( ) => {
@@ -53,7 +59,30 @@ describe('headers', () => {
53
59
54
60
setVaryHeaders ( headers , request , config )
55
61
56
- expect ( headers . set ) . toBeCalledWith ( 'netlify-vary' , 'cookie=__prerender_bypass|__next_preview_data' )
62
+ expect ( headers . set ) . toBeCalledWith (
63
+ 'netlify-vary' ,
64
+ 'cookie=__prerender_bypass|__next_preview_data' ,
65
+ )
66
+ } )
67
+
68
+ test ( 'with no languages if path is root index' , ( ) => {
69
+ const headers = new Headers ( )
70
+ const request = new Request ( `${ defaultUrl } /another/path` )
71
+ const config = {
72
+ ...defaultConfig ,
73
+ i18n : {
74
+ locales : [ 'en' , 'de' ] ,
75
+ defaultLocale : 'default' ,
76
+ } ,
77
+ }
78
+ vi . spyOn ( headers , 'set' )
79
+
80
+ setVaryHeaders ( headers , request , config )
81
+
82
+ expect ( headers . set ) . toBeCalledWith (
83
+ 'netlify-vary' ,
84
+ 'cookie=__prerender_bypass|__next_preview_data' ,
85
+ )
57
86
} )
58
87
59
88
test ( 'with expected languages if i18n config has locales' , ( ) => {
@@ -70,7 +99,10 @@ describe('headers', () => {
70
99
71
100
setVaryHeaders ( headers , request , config )
72
101
73
- expect ( headers . set ) . toBeCalledWith ( 'netlify-vary' , 'language=en|de|fr,cookie=__prerender_bypass|__next_preview_data|NEXT_LOCALE' )
102
+ expect ( headers . set ) . toBeCalledWith (
103
+ 'netlify-vary' ,
104
+ 'language=en|de|fr,cookie=__prerender_bypass|__next_preview_data|NEXT_LOCALE' ,
105
+ )
74
106
} )
75
107
76
108
test ( 'with expected languages if i18n config has locales and basePath matches the current path' , ( ) => {
@@ -88,7 +120,10 @@ describe('headers', () => {
88
120
89
121
setVaryHeaders ( headers , request , config )
90
122
91
- expect ( headers . set ) . toBeCalledWith ( 'netlify-vary' , 'language=en|de|fr,cookie=__prerender_bypass|__next_preview_data|NEXT_LOCALE' )
123
+ expect ( headers . set ) . toBeCalledWith (
124
+ 'netlify-vary' ,
125
+ 'language=en|de|fr,cookie=__prerender_bypass|__next_preview_data|NEXT_LOCALE' ,
126
+ )
92
127
} )
93
128
} )
94
129
} )
@@ -138,8 +173,16 @@ describe('headers', () => {
138
173
139
174
setCacheControlHeaders ( headers )
140
175
141
- expect ( headers . set ) . toHaveBeenNthCalledWith ( 1 , 'cache-control' , 'public, max-age=0, must-revalidate' )
142
- expect ( headers . set ) . toHaveBeenNthCalledWith ( 2 , 'netlify-cdn-cache-control' , 'public, max-age=0, must-revalidate' )
176
+ expect ( headers . set ) . toHaveBeenNthCalledWith (
177
+ 1 ,
178
+ 'cache-control' ,
179
+ 'public, max-age=0, must-revalidate' ,
180
+ )
181
+ expect ( headers . set ) . toHaveBeenNthCalledWith (
182
+ 2 ,
183
+ 'netlify-cdn-cache-control' ,
184
+ 'public, max-age=0, must-revalidate' ,
185
+ )
143
186
} )
144
187
145
188
test ( 'should remove "s-maxage" from "cache-control" header' , ( ) => {
@@ -152,7 +195,11 @@ describe('headers', () => {
152
195
setCacheControlHeaders ( headers )
153
196
154
197
expect ( headers . set ) . toHaveBeenNthCalledWith ( 1 , 'cache-control' , 'public' )
155
- expect ( headers . set ) . toHaveBeenNthCalledWith ( 2 , 'netlify-cdn-cache-control' , 'public, s-maxage=604800' )
198
+ expect ( headers . set ) . toHaveBeenNthCalledWith (
199
+ 2 ,
200
+ 'netlify-cdn-cache-control' ,
201
+ 'public, s-maxage=604800' ,
202
+ )
156
203
} )
157
204
158
205
test ( 'should remove "stale-while-revalidate" from "cache-control" header' , ( ) => {
@@ -165,10 +212,14 @@ describe('headers', () => {
165
212
setCacheControlHeaders ( headers )
166
213
167
214
expect ( headers . set ) . toHaveBeenNthCalledWith ( 1 , 'cache-control' , 'max-age=604800' )
168
- expect ( headers . set ) . toHaveBeenNthCalledWith ( 2 , 'netlify-cdn-cache-control' , 'max-age=604800, stale-while-revalidate=86400' )
215
+ expect ( headers . set ) . toHaveBeenNthCalledWith (
216
+ 2 ,
217
+ 'netlify-cdn-cache-control' ,
218
+ 'max-age=604800, stale-while-revalidate=86400' ,
219
+ )
169
220
} )
170
221
171
- test ( 'should set default "cache-control" header if it contains both "s-maxage" and "stale-whie-revalidate"' , ( ) => {
222
+ test ( 'should set default "cache-control" header if it contains only "s-maxage" and "stale-whie-revalidate"' , ( ) => {
172
223
const givenHeaders = {
173
224
'cache-control' : 's-maxage=604800, stale-while-revalidate=86400' ,
174
225
}
@@ -177,8 +228,16 @@ describe('headers', () => {
177
228
178
229
setCacheControlHeaders ( headers )
179
230
180
- expect ( headers . set ) . toHaveBeenNthCalledWith ( 1 , 'cache-control' , 'public, max-age=0, must-revalidate' )
181
- expect ( headers . set ) . toHaveBeenNthCalledWith ( 2 , 'netlify-cdn-cache-control' , 's-maxage=604800, stale-while-revalidate=86400' )
231
+ expect ( headers . set ) . toHaveBeenNthCalledWith (
232
+ 1 ,
233
+ 'cache-control' ,
234
+ 'public, max-age=0, must-revalidate' ,
235
+ )
236
+ expect ( headers . set ) . toHaveBeenNthCalledWith (
237
+ 2 ,
238
+ 'netlify-cdn-cache-control' ,
239
+ 's-maxage=604800, stale-while-revalidate=86400' ,
240
+ )
182
241
} )
183
242
} )
184
243
0 commit comments