1
1
import { v4 } from 'uuid'
2
2
import { beforeEach , describe , expect , test , vi } from 'vitest'
3
3
import { type FixtureTestContext } from '../utils/contexts.js'
4
- import { createFixture , invokeEdgeFunction , runPlugin } from '../utils/fixture.js'
4
+ import {
5
+ createFixture ,
6
+ EDGE_MIDDLEWARE_FUNCTION_NAME ,
7
+ EDGE_MIDDLEWARE_SRC_FUNCTION_NAME ,
8
+ invokeEdgeFunction ,
9
+ runPlugin ,
10
+ } from '../utils/fixture.js'
5
11
import { generateRandomObjectID , startMockBlobStore } from '../utils/helpers.js'
6
12
import { LocalServer } from '../utils/local-server.js'
7
13
import { nextVersionSatisfies } from '../utils/next-version-helpers.mjs'
@@ -30,7 +36,7 @@ test<FixtureTestContext>('should add request/response headers', async (ctx) => {
30
36
ctx . cleanup ?. push ( ( ) => origin . stop ( ) )
31
37
32
38
const response = await invokeEdgeFunction ( ctx , {
33
- functions : [ '___netlify-edge-handler-middleware' ] ,
39
+ functions : [ EDGE_MIDDLEWARE_FUNCTION_NAME ] ,
34
40
origin,
35
41
url : '/test/next' ,
36
42
} )
@@ -58,7 +64,7 @@ test<FixtureTestContext>('should add request/response headers when using src dir
58
64
ctx . cleanup ?. push ( ( ) => origin . stop ( ) )
59
65
60
66
const response = await invokeEdgeFunction ( ctx , {
61
- functions : [ '___netlify-edge-handler-src-middleware' ] ,
67
+ functions : [ EDGE_MIDDLEWARE_SRC_FUNCTION_NAME ] ,
62
68
origin,
63
69
url : '/test/next' ,
64
70
} )
@@ -78,7 +84,7 @@ describe('redirect', () => {
78
84
79
85
const origin = new LocalServer ( )
80
86
const response = await invokeEdgeFunction ( ctx , {
81
- functions : [ '___netlify-edge-handler-middleware' ] ,
87
+ functions : [ EDGE_MIDDLEWARE_FUNCTION_NAME ] ,
82
88
origin,
83
89
redirect : 'manual' ,
84
90
url : '/test/redirect' ,
@@ -101,7 +107,7 @@ describe('redirect', () => {
101
107
102
108
const origin = new LocalServer ( )
103
109
const response = await invokeEdgeFunction ( ctx , {
104
- functions : [ '___netlify-edge-handler-middleware' ] ,
110
+ functions : [ EDGE_MIDDLEWARE_FUNCTION_NAME ] ,
105
111
origin,
106
112
redirect : 'manual' ,
107
113
url : '/test/redirect-with-headers' ,
@@ -140,7 +146,7 @@ describe('rewrite', () => {
140
146
ctx . cleanup ?. push ( ( ) => origin . stop ( ) )
141
147
142
148
const response = await invokeEdgeFunction ( ctx , {
143
- functions : [ '___netlify-edge-handler-middleware' ] ,
149
+ functions : [ EDGE_MIDDLEWARE_FUNCTION_NAME ] ,
144
150
origin,
145
151
url : `/test/rewrite-external?external-url=http://localhost:${ external . port } /some-path` ,
146
152
} )
@@ -167,7 +173,7 @@ describe('rewrite', () => {
167
173
ctx . cleanup ?. push ( ( ) => origin . stop ( ) )
168
174
169
175
const response = await invokeEdgeFunction ( ctx , {
170
- functions : [ '___netlify-edge-handler-middleware' ] ,
176
+ functions : [ EDGE_MIDDLEWARE_FUNCTION_NAME ] ,
171
177
origin,
172
178
url : `/test/rewrite-external?external-url=http://localhost:${ external . port } /some-path` ,
173
179
redirect : 'manual' ,
@@ -196,7 +202,7 @@ describe("aborts middleware execution when the matcher conditions don't match th
196
202
ctx . cleanup ?. push ( ( ) => origin . stop ( ) )
197
203
198
204
const response = await invokeEdgeFunction ( ctx , {
199
- functions : [ '___netlify-edge-handler-middleware' ] ,
205
+ functions : [ EDGE_MIDDLEWARE_FUNCTION_NAME ] ,
200
206
origin,
201
207
url : '/_next/data' ,
202
208
} )
@@ -223,7 +229,7 @@ describe("aborts middleware execution when the matcher conditions don't match th
223
229
224
230
// Request 1: Middleware should run because we're not sending the header.
225
231
const response1 = await invokeEdgeFunction ( ctx , {
226
- functions : [ '___netlify-edge-handler-middleware' ] ,
232
+ functions : [ EDGE_MIDDLEWARE_FUNCTION_NAME ] ,
227
233
origin,
228
234
url : '/foo' ,
229
235
} )
@@ -238,7 +244,7 @@ describe("aborts middleware execution when the matcher conditions don't match th
238
244
headers : {
239
245
'x-custom-header' : 'custom-value' ,
240
246
} ,
241
- functions : [ '___netlify-edge-handler-middleware' ] ,
247
+ functions : [ EDGE_MIDDLEWARE_FUNCTION_NAME ] ,
242
248
origin,
243
249
url : '/foo' ,
244
250
} )
@@ -264,7 +270,7 @@ describe("aborts middleware execution when the matcher conditions don't match th
264
270
265
271
for ( const path of [ '/hello' , '/en/hello' , '/nl/hello' , '/nl/about' ] ) {
266
272
const response = await invokeEdgeFunction ( ctx , {
267
- functions : [ '___netlify-edge-handler-middleware' ] ,
273
+ functions : [ EDGE_MIDDLEWARE_FUNCTION_NAME ] ,
268
274
origin,
269
275
url : path ,
270
276
} )
@@ -278,7 +284,7 @@ describe("aborts middleware execution when the matcher conditions don't match th
278
284
279
285
for ( const path of [ '/invalid/hello' , '/hello/invalid' , '/about' , '/en/about' ] ) {
280
286
const response = await invokeEdgeFunction ( ctx , {
281
- functions : [ '___netlify-edge-handler-middleware' ] ,
287
+ functions : [ EDGE_MIDDLEWARE_FUNCTION_NAME ] ,
282
288
origin,
283
289
url : path ,
284
290
} )
@@ -299,7 +305,7 @@ describe('should run middleware on data requests', () => {
299
305
300
306
const origin = new LocalServer ( )
301
307
const response = await invokeEdgeFunction ( ctx , {
302
- functions : [ '___netlify-edge-handler-middleware' ] ,
308
+ functions : [ EDGE_MIDDLEWARE_FUNCTION_NAME ] ,
303
309
origin,
304
310
redirect : 'manual' ,
305
311
url : '/_next/data/dJvEyLV8MW7CBLFf0Ecbk/test/redirect-with-headers.json' ,
@@ -323,7 +329,7 @@ describe('should run middleware on data requests', () => {
323
329
324
330
const origin = new LocalServer ( )
325
331
const response = await invokeEdgeFunction ( ctx , {
326
- functions : [ '___netlify-edge-handler-middleware' ] ,
332
+ functions : [ EDGE_MIDDLEWARE_FUNCTION_NAME ] ,
327
333
origin,
328
334
redirect : 'manual' ,
329
335
url : '/_next/data/dJvEyLV8MW7CBLFf0Ecbk/test/redirect-with-headers.json' ,
@@ -357,7 +363,7 @@ describe('page router', () => {
357
363
} )
358
364
ctx . cleanup ?. push ( ( ) => origin . stop ( ) )
359
365
const response = await invokeEdgeFunction ( ctx , {
360
- functions : [ '___netlify-edge-handler-middleware' ] ,
366
+ functions : [ EDGE_MIDDLEWARE_FUNCTION_NAME ] ,
361
367
origin,
362
368
url : `/api/edge-headers` ,
363
369
} )
@@ -379,7 +385,7 @@ describe('page router', () => {
379
385
} )
380
386
ctx . cleanup ?. push ( ( ) => origin . stop ( ) )
381
387
const response = await invokeEdgeFunction ( ctx , {
382
- functions : [ '___netlify-edge-handler-middleware' ] ,
388
+ functions : [ EDGE_MIDDLEWARE_FUNCTION_NAME ] ,
383
389
headers : {
384
390
'x-nextjs-data' : '1' ,
385
391
} ,
@@ -408,7 +414,7 @@ describe('page router', () => {
408
414
} )
409
415
ctx . cleanup ?. push ( ( ) => origin . stop ( ) )
410
416
const response = await invokeEdgeFunction ( ctx , {
411
- functions : [ '___netlify-edge-handler-middleware' ] ,
417
+ functions : [ EDGE_MIDDLEWARE_FUNCTION_NAME ] ,
412
418
origin,
413
419
url : `/_next/static/build-id/_devMiddlewareManifest.json?foo=1` ,
414
420
} )
@@ -434,7 +440,7 @@ describe('page router', () => {
434
440
} )
435
441
ctx . cleanup ?. push ( ( ) => origin . stop ( ) )
436
442
const response = await invokeEdgeFunction ( ctx , {
437
- functions : [ '___netlify-edge-handler-middleware' ] ,
443
+ functions : [ EDGE_MIDDLEWARE_FUNCTION_NAME ] ,
438
444
headers : {
439
445
'x-nextjs-data' : '1' ,
440
446
} ,
@@ -462,7 +468,7 @@ describe('page router', () => {
462
468
} )
463
469
ctx . cleanup ?. push ( ( ) => origin . stop ( ) )
464
470
const response = await invokeEdgeFunction ( ctx , {
465
- functions : [ '___netlify-edge-handler-middleware' ] ,
471
+ functions : [ EDGE_MIDDLEWARE_FUNCTION_NAME ] ,
466
472
headers : {
467
473
'x-nextjs-data' : '1' ,
468
474
} ,
@@ -491,7 +497,7 @@ describe('page router', () => {
491
497
} )
492
498
ctx . cleanup ?. push ( ( ) => origin . stop ( ) )
493
499
const response = await invokeEdgeFunction ( ctx , {
494
- functions : [ '___netlify-edge-handler-middleware' ] ,
500
+ functions : [ EDGE_MIDDLEWARE_FUNCTION_NAME ] ,
495
501
origin,
496
502
url : `/fr/old-home` ,
497
503
redirect : 'manual' ,
@@ -515,7 +521,7 @@ describe('page router', () => {
515
521
} )
516
522
ctx . cleanup ?. push ( ( ) => origin . stop ( ) )
517
523
const response = await invokeEdgeFunction ( ctx , {
518
- functions : [ '___netlify-edge-handler-middleware' ] ,
524
+ functions : [ EDGE_MIDDLEWARE_FUNCTION_NAME ] ,
519
525
origin,
520
526
url : `/fr/redirect-to-same-page-but-default-locale` ,
521
527
redirect : 'manual' ,
@@ -540,7 +546,7 @@ describe('page router', () => {
540
546
ctx . cleanup ?. push ( ( ) => origin . stop ( ) )
541
547
542
548
const response = await invokeEdgeFunction ( ctx , {
543
- functions : [ '___netlify-edge-handler-middleware' ] ,
549
+ functions : [ EDGE_MIDDLEWARE_FUNCTION_NAME ] ,
544
550
origin,
545
551
url : `/json` ,
546
552
} )
@@ -552,7 +558,7 @@ describe('page router', () => {
552
558
expect ( body . nextUrlLocale ) . toBe ( 'en' )
553
559
554
560
const responseEn = await invokeEdgeFunction ( ctx , {
555
- functions : [ '___netlify-edge-handler-middleware' ] ,
561
+ functions : [ EDGE_MIDDLEWARE_FUNCTION_NAME ] ,
556
562
origin,
557
563
url : `/en/json` ,
558
564
} )
@@ -564,7 +570,7 @@ describe('page router', () => {
564
570
expect ( bodyEn . nextUrlLocale ) . toBe ( 'en' )
565
571
566
572
const responseFr = await invokeEdgeFunction ( ctx , {
567
- functions : [ '___netlify-edge-handler-middleware' ] ,
573
+ functions : [ EDGE_MIDDLEWARE_FUNCTION_NAME ] ,
568
574
origin,
569
575
url : `/fr/json` ,
570
576
} )
@@ -591,7 +597,7 @@ describe('page router', () => {
591
597
ctx . cleanup ?. push ( ( ) => origin . stop ( ) )
592
598
593
599
const response = await invokeEdgeFunction ( ctx , {
594
- functions : [ '___netlify-edge-handler-middleware' ] ,
600
+ functions : [ EDGE_MIDDLEWARE_FUNCTION_NAME ] ,
595
601
origin,
596
602
url : `/json` ,
597
603
} )
@@ -603,7 +609,7 @@ describe('page router', () => {
603
609
expect ( body . nextUrlLocale ) . toBe ( 'en' )
604
610
605
611
const responseEn = await invokeEdgeFunction ( ctx , {
606
- functions : [ '___netlify-edge-handler-middleware' ] ,
612
+ functions : [ EDGE_MIDDLEWARE_FUNCTION_NAME ] ,
607
613
origin,
608
614
url : `/en/json` ,
609
615
} )
@@ -615,7 +621,7 @@ describe('page router', () => {
615
621
expect ( bodyEn . nextUrlLocale ) . toBe ( 'en' )
616
622
617
623
const responseFr = await invokeEdgeFunction ( ctx , {
618
- functions : [ '___netlify-edge-handler-middleware' ] ,
624
+ functions : [ EDGE_MIDDLEWARE_FUNCTION_NAME ] ,
619
625
origin,
620
626
url : `/fr/json` ,
621
627
} )
0 commit comments