11import { v4 } from 'uuid'
22import { beforeEach , describe , expect , test , vi } from 'vitest'
33import { 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'
511import { generateRandomObjectID , startMockBlobStore } from '../utils/helpers.js'
612import { LocalServer } from '../utils/local-server.js'
713import { nextVersionSatisfies } from '../utils/next-version-helpers.mjs'
@@ -30,7 +36,7 @@ test<FixtureTestContext>('should add request/response headers', async (ctx) => {
3036 ctx . cleanup ?. push ( ( ) => origin . stop ( ) )
3137
3238 const response = await invokeEdgeFunction ( ctx , {
33- functions : [ '___netlify-edge-handler-middleware' ] ,
39+ functions : [ EDGE_MIDDLEWARE_FUNCTION_NAME ] ,
3440 origin,
3541 url : '/test/next' ,
3642 } )
@@ -58,7 +64,7 @@ test<FixtureTestContext>('should add request/response headers when using src dir
5864 ctx . cleanup ?. push ( ( ) => origin . stop ( ) )
5965
6066 const response = await invokeEdgeFunction ( ctx , {
61- functions : [ '___netlify-edge-handler-src-middleware' ] ,
67+ functions : [ EDGE_MIDDLEWARE_SRC_FUNCTION_NAME ] ,
6268 origin,
6369 url : '/test/next' ,
6470 } )
@@ -78,7 +84,7 @@ describe('redirect', () => {
7884
7985 const origin = new LocalServer ( )
8086 const response = await invokeEdgeFunction ( ctx , {
81- functions : [ '___netlify-edge-handler-middleware' ] ,
87+ functions : [ EDGE_MIDDLEWARE_FUNCTION_NAME ] ,
8288 origin,
8389 redirect : 'manual' ,
8490 url : '/test/redirect' ,
@@ -101,7 +107,7 @@ describe('redirect', () => {
101107
102108 const origin = new LocalServer ( )
103109 const response = await invokeEdgeFunction ( ctx , {
104- functions : [ '___netlify-edge-handler-middleware' ] ,
110+ functions : [ EDGE_MIDDLEWARE_FUNCTION_NAME ] ,
105111 origin,
106112 redirect : 'manual' ,
107113 url : '/test/redirect-with-headers' ,
@@ -140,7 +146,7 @@ describe('rewrite', () => {
140146 ctx . cleanup ?. push ( ( ) => origin . stop ( ) )
141147
142148 const response = await invokeEdgeFunction ( ctx , {
143- functions : [ '___netlify-edge-handler-middleware' ] ,
149+ functions : [ EDGE_MIDDLEWARE_FUNCTION_NAME ] ,
144150 origin,
145151 url : `/test/rewrite-external?external-url=http://localhost:${ external . port } /some-path` ,
146152 } )
@@ -167,7 +173,7 @@ describe('rewrite', () => {
167173 ctx . cleanup ?. push ( ( ) => origin . stop ( ) )
168174
169175 const response = await invokeEdgeFunction ( ctx , {
170- functions : [ '___netlify-edge-handler-middleware' ] ,
176+ functions : [ EDGE_MIDDLEWARE_FUNCTION_NAME ] ,
171177 origin,
172178 url : `/test/rewrite-external?external-url=http://localhost:${ external . port } /some-path` ,
173179 redirect : 'manual' ,
@@ -196,7 +202,7 @@ describe("aborts middleware execution when the matcher conditions don't match th
196202 ctx . cleanup ?. push ( ( ) => origin . stop ( ) )
197203
198204 const response = await invokeEdgeFunction ( ctx , {
199- functions : [ '___netlify-edge-handler-middleware' ] ,
205+ functions : [ EDGE_MIDDLEWARE_FUNCTION_NAME ] ,
200206 origin,
201207 url : '/_next/data' ,
202208 } )
@@ -223,7 +229,7 @@ describe("aborts middleware execution when the matcher conditions don't match th
223229
224230 // Request 1: Middleware should run because we're not sending the header.
225231 const response1 = await invokeEdgeFunction ( ctx , {
226- functions : [ '___netlify-edge-handler-middleware' ] ,
232+ functions : [ EDGE_MIDDLEWARE_FUNCTION_NAME ] ,
227233 origin,
228234 url : '/foo' ,
229235 } )
@@ -238,7 +244,7 @@ describe("aborts middleware execution when the matcher conditions don't match th
238244 headers : {
239245 'x-custom-header' : 'custom-value' ,
240246 } ,
241- functions : [ '___netlify-edge-handler-middleware' ] ,
247+ functions : [ EDGE_MIDDLEWARE_FUNCTION_NAME ] ,
242248 origin,
243249 url : '/foo' ,
244250 } )
@@ -264,7 +270,7 @@ describe("aborts middleware execution when the matcher conditions don't match th
264270
265271 for ( const path of [ '/hello' , '/en/hello' , '/nl/hello' , '/nl/about' ] ) {
266272 const response = await invokeEdgeFunction ( ctx , {
267- functions : [ '___netlify-edge-handler-middleware' ] ,
273+ functions : [ EDGE_MIDDLEWARE_FUNCTION_NAME ] ,
268274 origin,
269275 url : path ,
270276 } )
@@ -278,7 +284,7 @@ describe("aborts middleware execution when the matcher conditions don't match th
278284
279285 for ( const path of [ '/invalid/hello' , '/hello/invalid' , '/about' , '/en/about' ] ) {
280286 const response = await invokeEdgeFunction ( ctx , {
281- functions : [ '___netlify-edge-handler-middleware' ] ,
287+ functions : [ EDGE_MIDDLEWARE_FUNCTION_NAME ] ,
282288 origin,
283289 url : path ,
284290 } )
@@ -299,7 +305,7 @@ describe('should run middleware on data requests', () => {
299305
300306 const origin = new LocalServer ( )
301307 const response = await invokeEdgeFunction ( ctx , {
302- functions : [ '___netlify-edge-handler-middleware' ] ,
308+ functions : [ EDGE_MIDDLEWARE_FUNCTION_NAME ] ,
303309 origin,
304310 redirect : 'manual' ,
305311 url : '/_next/data/dJvEyLV8MW7CBLFf0Ecbk/test/redirect-with-headers.json' ,
@@ -323,7 +329,7 @@ describe('should run middleware on data requests', () => {
323329
324330 const origin = new LocalServer ( )
325331 const response = await invokeEdgeFunction ( ctx , {
326- functions : [ '___netlify-edge-handler-middleware' ] ,
332+ functions : [ EDGE_MIDDLEWARE_FUNCTION_NAME ] ,
327333 origin,
328334 redirect : 'manual' ,
329335 url : '/_next/data/dJvEyLV8MW7CBLFf0Ecbk/test/redirect-with-headers.json' ,
@@ -357,7 +363,7 @@ describe('page router', () => {
357363 } )
358364 ctx . cleanup ?. push ( ( ) => origin . stop ( ) )
359365 const response = await invokeEdgeFunction ( ctx , {
360- functions : [ '___netlify-edge-handler-middleware' ] ,
366+ functions : [ EDGE_MIDDLEWARE_FUNCTION_NAME ] ,
361367 origin,
362368 url : `/api/edge-headers` ,
363369 } )
@@ -379,7 +385,7 @@ describe('page router', () => {
379385 } )
380386 ctx . cleanup ?. push ( ( ) => origin . stop ( ) )
381387 const response = await invokeEdgeFunction ( ctx , {
382- functions : [ '___netlify-edge-handler-middleware' ] ,
388+ functions : [ EDGE_MIDDLEWARE_FUNCTION_NAME ] ,
383389 headers : {
384390 'x-nextjs-data' : '1' ,
385391 } ,
@@ -408,7 +414,7 @@ describe('page router', () => {
408414 } )
409415 ctx . cleanup ?. push ( ( ) => origin . stop ( ) )
410416 const response = await invokeEdgeFunction ( ctx , {
411- functions : [ '___netlify-edge-handler-middleware' ] ,
417+ functions : [ EDGE_MIDDLEWARE_FUNCTION_NAME ] ,
412418 origin,
413419 url : `/_next/static/build-id/_devMiddlewareManifest.json?foo=1` ,
414420 } )
@@ -434,7 +440,7 @@ describe('page router', () => {
434440 } )
435441 ctx . cleanup ?. push ( ( ) => origin . stop ( ) )
436442 const response = await invokeEdgeFunction ( ctx , {
437- functions : [ '___netlify-edge-handler-middleware' ] ,
443+ functions : [ EDGE_MIDDLEWARE_FUNCTION_NAME ] ,
438444 headers : {
439445 'x-nextjs-data' : '1' ,
440446 } ,
@@ -462,7 +468,7 @@ describe('page router', () => {
462468 } )
463469 ctx . cleanup ?. push ( ( ) => origin . stop ( ) )
464470 const response = await invokeEdgeFunction ( ctx , {
465- functions : [ '___netlify-edge-handler-middleware' ] ,
471+ functions : [ EDGE_MIDDLEWARE_FUNCTION_NAME ] ,
466472 headers : {
467473 'x-nextjs-data' : '1' ,
468474 } ,
@@ -491,7 +497,7 @@ describe('page router', () => {
491497 } )
492498 ctx . cleanup ?. push ( ( ) => origin . stop ( ) )
493499 const response = await invokeEdgeFunction ( ctx , {
494- functions : [ '___netlify-edge-handler-middleware' ] ,
500+ functions : [ EDGE_MIDDLEWARE_FUNCTION_NAME ] ,
495501 origin,
496502 url : `/fr/old-home` ,
497503 redirect : 'manual' ,
@@ -515,7 +521,7 @@ describe('page router', () => {
515521 } )
516522 ctx . cleanup ?. push ( ( ) => origin . stop ( ) )
517523 const response = await invokeEdgeFunction ( ctx , {
518- functions : [ '___netlify-edge-handler-middleware' ] ,
524+ functions : [ EDGE_MIDDLEWARE_FUNCTION_NAME ] ,
519525 origin,
520526 url : `/fr/redirect-to-same-page-but-default-locale` ,
521527 redirect : 'manual' ,
@@ -540,7 +546,7 @@ describe('page router', () => {
540546 ctx . cleanup ?. push ( ( ) => origin . stop ( ) )
541547
542548 const response = await invokeEdgeFunction ( ctx , {
543- functions : [ '___netlify-edge-handler-middleware' ] ,
549+ functions : [ EDGE_MIDDLEWARE_FUNCTION_NAME ] ,
544550 origin,
545551 url : `/json` ,
546552 } )
@@ -552,7 +558,7 @@ describe('page router', () => {
552558 expect ( body . nextUrlLocale ) . toBe ( 'en' )
553559
554560 const responseEn = await invokeEdgeFunction ( ctx , {
555- functions : [ '___netlify-edge-handler-middleware' ] ,
561+ functions : [ EDGE_MIDDLEWARE_FUNCTION_NAME ] ,
556562 origin,
557563 url : `/en/json` ,
558564 } )
@@ -564,7 +570,7 @@ describe('page router', () => {
564570 expect ( bodyEn . nextUrlLocale ) . toBe ( 'en' )
565571
566572 const responseFr = await invokeEdgeFunction ( ctx , {
567- functions : [ '___netlify-edge-handler-middleware' ] ,
573+ functions : [ EDGE_MIDDLEWARE_FUNCTION_NAME ] ,
568574 origin,
569575 url : `/fr/json` ,
570576 } )
@@ -591,7 +597,7 @@ describe('page router', () => {
591597 ctx . cleanup ?. push ( ( ) => origin . stop ( ) )
592598
593599 const response = await invokeEdgeFunction ( ctx , {
594- functions : [ '___netlify-edge-handler-middleware' ] ,
600+ functions : [ EDGE_MIDDLEWARE_FUNCTION_NAME ] ,
595601 origin,
596602 url : `/json` ,
597603 } )
@@ -603,7 +609,7 @@ describe('page router', () => {
603609 expect ( body . nextUrlLocale ) . toBe ( 'en' )
604610
605611 const responseEn = await invokeEdgeFunction ( ctx , {
606- functions : [ '___netlify-edge-handler-middleware' ] ,
612+ functions : [ EDGE_MIDDLEWARE_FUNCTION_NAME ] ,
607613 origin,
608614 url : `/en/json` ,
609615 } )
@@ -615,7 +621,7 @@ describe('page router', () => {
615621 expect ( bodyEn . nextUrlLocale ) . toBe ( 'en' )
616622
617623 const responseFr = await invokeEdgeFunction ( ctx , {
618- functions : [ '___netlify-edge-handler-middleware' ] ,
624+ functions : [ EDGE_MIDDLEWARE_FUNCTION_NAME ] ,
619625 origin,
620626 url : `/fr/json` ,
621627 } )
0 commit comments