@@ -84,9 +84,6 @@ describe('redirect', () => {
84
84
85
85
ctx . cleanup ?. push ( ( ) => origin . stop ( ) )
86
86
87
- const foo = await response . text ( )
88
- console . log ( foo )
89
-
90
87
expect ( response . status ) . toBe ( 307 )
91
88
expect ( response . headers . get ( 'location' ) , 'added a location header' ) . toBeTypeOf ( 'string' )
92
89
expect (
@@ -199,3 +196,53 @@ describe("aborts middleware execution when the matcher conditions don't match th
199
196
expect ( origin . calls ) . toBe ( 2 )
200
197
} )
201
198
} )
199
+
200
+ describe ( 'should run middleware on data requests' , ( ) => {
201
+ test < FixtureTestContext > ( 'when `trailingSlash: false`' , async ( ctx ) => {
202
+ await createFixture ( 'middleware' , ctx )
203
+ await runPlugin ( ctx )
204
+
205
+ const origin = new LocalServer ( )
206
+ const response = await invokeEdgeFunction ( ctx , {
207
+ functions : [ '___netlify-edge-handler-middleware' ] ,
208
+ origin,
209
+ redirect : 'manual' ,
210
+ url : '/_next/data/dJvEyLV8MW7CBLFf0Ecbk/test/redirect-with-headers.json' ,
211
+ } )
212
+
213
+ ctx . cleanup ?. push ( ( ) => origin . stop ( ) )
214
+
215
+ expect ( response . status ) . toBe ( 307 )
216
+ expect ( response . headers . get ( 'location' ) , 'added a location header' ) . toBeTypeOf ( 'string' )
217
+ expect (
218
+ new URL ( response . headers . get ( 'location' ) as string ) . pathname ,
219
+ 'redirected to the correct path' ,
220
+ ) . toEqual ( '/other' )
221
+ expect ( response . headers . get ( 'x-header-from-redirect' ) , 'hello' ) . toBe ( 'hello' )
222
+ expect ( origin . calls ) . toBe ( 0 )
223
+ } )
224
+
225
+ test < FixtureTestContext > ( 'when `trailingSlash: true`' , async ( ctx ) => {
226
+ await createFixture ( 'middleware-trailing-slash' , ctx )
227
+ await runPlugin ( ctx )
228
+
229
+ const origin = new LocalServer ( )
230
+ const response = await invokeEdgeFunction ( ctx , {
231
+ functions : [ '___netlify-edge-handler-middleware' ] ,
232
+ origin,
233
+ redirect : 'manual' ,
234
+ url : '/_next/data/dJvEyLV8MW7CBLFf0Ecbk/test/redirect-with-headers.json' ,
235
+ } )
236
+
237
+ ctx . cleanup ?. push ( ( ) => origin . stop ( ) )
238
+
239
+ expect ( response . status ) . toBe ( 307 )
240
+ expect ( response . headers . get ( 'location' ) , 'added a location header' ) . toBeTypeOf ( 'string' )
241
+ expect (
242
+ new URL ( response . headers . get ( 'location' ) as string ) . pathname ,
243
+ 'redirected to the correct path' ,
244
+ ) . toEqual ( '/other' )
245
+ expect ( response . headers . get ( 'x-header-from-redirect' ) , 'hello' ) . toBe ( 'hello' )
246
+ expect ( origin . calls ) . toBe ( 0 )
247
+ } )
248
+ } )
0 commit comments