@@ -10,7 +10,7 @@ import {
1010} from "./next-server.js" ;
1111
1212describe ( "Next Server" , ( ) => {
13- const nextServerCode = `
13+ const next15ServerCode = `
1414class NextNodeServer extends _baseserver.default {
1515 constructor(options){
1616 // Initialize super class
@@ -168,8 +168,27 @@ class NextNodeServer extends _baseserver.default {
168168 // ...
169169}` ;
170170
171+ const next16ServerCode = `
172+ class NextNodeServer extends _baseserver.default {
173+ // ...
174+
175+ async loadCustomCacheHandlers() {
176+ const { cacheMaxMemorySize, cacheHandlers } = this.nextConfig;
177+ if (!cacheHandlers) return;
178+ // If we've already initialized the cache handlers interface, don't do it
179+ // again.
180+ if (!(0, _handlers.initializeCacheHandlers)(cacheMaxMemorySize)) return;
181+ for (const [kind, handler] of Object.entries(cacheHandlers)){
182+ if (!handler) continue;
183+ (0, _handlers.setCacheHandler)(kind, (0, _interopdefault.interopDefault)(await dynamicImportEsmDefault((0, _formatdynamicimportpath.formatDynamicImportPath)(this.distDir, handler))));
184+ }
185+ }
186+ // ...
187+ }
188+ ` ;
189+
171190 test ( "build ID" , ( ) => {
172- expect ( computePatchDiff ( "next-server.js" , nextServerCode , buildIdRule ) ) . toMatchInlineSnapshot ( `
191+ expect ( computePatchDiff ( "next-server.js" , next15ServerCode , buildIdRule ) ) . toMatchInlineSnapshot ( `
173192 "Index: next-server.js
174193 ===================================================================
175194 --- next-server.js
@@ -206,7 +225,7 @@ class NextNodeServer extends _baseserver.default {
206225 } ) ;
207226
208227 test ( "cache handler" , ( ) => {
209- expect ( computePatchDiff ( "next-server.js" , nextServerCode , createCacheHandlerRule ( "manifest" ) ) )
228+ expect ( computePatchDiff ( "next-server.js" , next15ServerCode , createCacheHandlerRule ( "manifest" ) ) )
210229 . toMatchInlineSnapshot ( `
211230 "Index: next-server.js
212231 ===================================================================
@@ -234,9 +253,10 @@ class NextNodeServer extends _baseserver.default {
234253 ` ) ;
235254 } ) ;
236255
237- test ( "composable cache handler" , ( ) => {
238- expect ( computePatchDiff ( "next-server.js" , nextServerCode , createComposableCacheHandlersRule ( "manifest" ) ) )
239- . toMatchInlineSnapshot ( `
256+ test ( "composable cache handler (Next 15)" , ( ) => {
257+ expect (
258+ computePatchDiff ( "next-server.js" , next15ServerCode , createComposableCacheHandlersRule ( "manifest" ) )
259+ ) . toMatchInlineSnapshot ( `
240260 "Index: next-server.js
241261 ===================================================================
242262 --- next-server.js
@@ -268,8 +288,38 @@ class NextNodeServer extends _baseserver.default {
268288 ` ) ;
269289 } ) ;
270290
291+ test ( "composable cache handler (Next 16)" , ( ) => {
292+ expect (
293+ computePatchDiff ( "next-server.js" , next16ServerCode , createComposableCacheHandlersRule ( "manifest" ) )
294+ ) . toMatchInlineSnapshot ( `
295+ "Index: next-server.js
296+ ===================================================================
297+ --- next-server.js
298+ +++ next-server.js
299+ @@ -1,10 +1,15 @@
300+ -
301+ class NextNodeServer extends _baseserver.default {
302+ // ...
303+
304+ async loadCustomCacheHandlers() {
305+ - const { cacheMaxMemorySize, cacheHandlers } = this.nextConfig;
306+ + const cacheHandlers = null;
307+ +const handlersSymbol = Symbol.for('@next/cache-handlers');
308+ +const handlersMapSymbol = Symbol.for('@next/cache-handlers-map');
309+ +const handlersSetSymbol = Symbol.for('@next/cache-handlers-set');
310+ +globalThis[handlersMapSymbol] = new Map();
311+ +globalThis[handlersMapSymbol].set("default", require('manifest').default);
312+ +globalThis[handlersSetSymbol] = new Set(globalThis[handlersMapSymbol].values());
313+ if (!cacheHandlers) return;
314+ // If we've already initialized the cache handlers interface, don't do it
315+ // again.
316+ if (!(0, _handlers.initializeCacheHandlers)(cacheMaxMemorySize)) return;
317+ "
318+ ` ) ;
319+ } ) ;
320+
271321 test ( "disable node middleware" , ( ) => {
272- expect ( computePatchDiff ( "next-server.js" , nextServerCode , disableNodeMiddlewareRule ) )
322+ expect ( computePatchDiff ( "next-server.js" , next15ServerCode , disableNodeMiddlewareRule ) )
273323 . toMatchInlineSnapshot ( `
274324 "Index: next-server.js
275325 ===================================================================
@@ -312,7 +362,8 @@ class NextNodeServer extends _baseserver.default {
312362 } ) ;
313363
314364 test ( "attachRequestMeta" , ( ) => {
315- expect ( computePatchDiff ( "next-server.js" , nextServerCode , attachRequestMetaRule ) ) . toMatchInlineSnapshot ( `
365+ expect ( computePatchDiff ( "next-server.js" , next15ServerCode , attachRequestMetaRule ) )
366+ . toMatchInlineSnapshot ( `
316367 "Index: next-server.js
317368 ===================================================================
318369 --- next-server.js
0 commit comments