@@ -22,6 +22,7 @@ import {
2222 isUsingImageOptimization ,
2323 isUsingAppDirectory ,
2424 allDependencyNames ,
25+ getMiddlewareMatcherRegexes ,
2526 getNonStaticRoutes ,
2627 getNonStaticServerComponents ,
2728 getHeadersFromMetaFiles ,
@@ -34,8 +35,8 @@ import {
3435 exportMarkerWithoutImage ,
3536 imagesManifest ,
3637 imagesManifestUnoptimized ,
37- middlewareManifestWhenNotUsed ,
38- middlewareManifestWhenUsed ,
38+ middlewareV2ManifestWhenNotUsed ,
39+ middlewareV2ManifestWhenUsed ,
3940 pathsAsGlobs ,
4041 pathsWithEscapedChars ,
4142 pathsWithRegex ,
@@ -48,6 +49,8 @@ import {
4849 unsupportedRedirects ,
4950 unsupportedRewritesArray ,
5051 npmLsReturn ,
52+ middlewareV1ManifestWhenUsed ,
53+ middlewareV1ManifestWhenNotUsed ,
5154 pagesManifest ,
5255 prerenderManifest ,
5356 appPathsManifest ,
@@ -266,12 +269,12 @@ describe("Next.js utils", () => {
266269 } ) ;
267270
268271 it ( "should return true if using middleware in production" , async ( ) => {
269- sandbox . stub ( fsExtra , "readJSON" ) . resolves ( middlewareManifestWhenUsed ) ;
272+ sandbox . stub ( fsExtra , "readJSON" ) . resolves ( middlewareV2ManifestWhenUsed ) ;
270273 expect ( await isUsingMiddleware ( "" , false ) ) . to . be . true ;
271274 } ) ;
272275
273276 it ( "should return false if not using middleware in production" , async ( ) => {
274- sandbox . stub ( fsExtra , "readJSON" ) . resolves ( middlewareManifestWhenNotUsed ) ;
277+ sandbox . stub ( fsExtra , "readJSON" ) . resolves ( middlewareV2ManifestWhenNotUsed ) ;
275278 expect ( await isUsingMiddleware ( "" , false ) ) . to . be . false ;
276279 } ) ;
277280 } ) ;
@@ -374,6 +377,36 @@ describe("Next.js utils", () => {
374377 } ) ;
375378 } ) ;
376379
380+ describe ( "getMiddlewareMatcherRegexes" , ( ) => {
381+ it ( "should return regexes when using version 1" , ( ) => {
382+ const middlewareMatcherRegexes = getMiddlewareMatcherRegexes ( middlewareV1ManifestWhenUsed ) ;
383+
384+ for ( const regex of middlewareMatcherRegexes ) {
385+ expect ( regex ) . to . be . an . instanceOf ( RegExp ) ;
386+ }
387+ } ) ;
388+
389+ it ( "should return empty array when using version 1 but not using middleware" , ( ) => {
390+ const middlewareMatcherRegexes = getMiddlewareMatcherRegexes ( middlewareV1ManifestWhenNotUsed ) ;
391+
392+ expect ( middlewareMatcherRegexes ) . to . eql ( [ ] ) ;
393+ } ) ;
394+
395+ it ( "should return regexes when using version 2" , ( ) => {
396+ const middlewareMatcherRegexes = getMiddlewareMatcherRegexes ( middlewareV2ManifestWhenUsed ) ;
397+
398+ for ( const regex of middlewareMatcherRegexes ) {
399+ expect ( regex ) . to . be . an . instanceOf ( RegExp ) ;
400+ }
401+ } ) ;
402+
403+ it ( "should return empty array when using version 2 but not using middleware" , ( ) => {
404+ const middlewareMatcherRegexes = getMiddlewareMatcherRegexes ( middlewareV2ManifestWhenNotUsed ) ;
405+
406+ expect ( middlewareMatcherRegexes ) . to . eql ( [ ] ) ;
407+ } ) ;
408+ } ) ;
409+
377410 describe ( "getNonStaticRoutes" , ( ) => {
378411 it ( "should get non-static routes" , ( ) => {
379412 expect (
0 commit comments