@@ -4,6 +4,7 @@ import { vi } from "vitest";
44
55declare global {
66 var disableIncrementalCache : boolean ;
7+ var disableDynamoDBCache : boolean ;
78 var isNextAfter15 : boolean ;
89}
910
@@ -39,6 +40,12 @@ describe("CacheHandler", () => {
3940 } ;
4041 globalThis . tagCache = tagCache ;
4142
43+ const invalidateCdnHandler = {
44+ name : "mock" ,
45+ invalidatePaths : vi . fn ( ) ,
46+ } ;
47+ globalThis . cdnInvalidationHandler = invalidateCdnHandler ;
48+
4249 globalThis . __openNextAls = {
4350 getStore : vi . fn ( ) . mockReturnValue ( {
4451 requestId : "123" ,
@@ -470,4 +477,72 @@ describe("CacheHandler", () => {
470477 ) . not . toThrow ( ) ;
471478 } ) ;
472479 } ) ;
480+
481+ describe ( "revalidateTag" , ( ) => {
482+ beforeEach ( ( ) => {
483+ globalThis . disableDynamoDBCache = false ;
484+ globalThis . disableIncrementalCache = false ;
485+ } ) ;
486+ it ( "Should do nothing if disableIncrementalCache is true" , async ( ) => {
487+ globalThis . disableIncrementalCache = true ;
488+
489+ await cache . revalidateTag ( "tag" ) ;
490+
491+ expect ( tagCache . writeTags ) . not . toHaveBeenCalled ( ) ;
492+ } ) ;
493+
494+ it ( "Should do nothing if disableTagCache is true" , async ( ) => {
495+ globalThis . disableDynamoDBCache = true ;
496+
497+ await cache . revalidateTag ( "tag" ) ;
498+
499+ expect ( tagCache . writeTags ) . not . toHaveBeenCalled ( ) ;
500+ } ) ;
501+
502+ it ( "Should call tagCache.writeTags" , async ( ) => {
503+ globalThis . tagCache . getByTag . mockResolvedValueOnce ( [ "/path" ] ) ;
504+ await cache . revalidateTag ( "tag" ) ;
505+
506+ expect ( globalThis . tagCache . getByTag ) . toHaveBeenCalledWith ( "tag" ) ;
507+
508+ expect ( tagCache . writeTags ) . toHaveBeenCalled ( ) ;
509+ expect ( tagCache . writeTags ) . toHaveBeenCalledWith ( [
510+ {
511+ path : "/path" ,
512+ tag : "tag" ,
513+ } ,
514+ ] ) ;
515+ } ) ;
516+
517+ it ( "Should call invalidateCdnHandler.invalidatePaths" , async ( ) => {
518+ globalThis . tagCache . getByTag . mockResolvedValueOnce ( [ "/path" ] ) ;
519+ globalThis . tagCache . getByPath . mockResolvedValueOnce ( [ ] ) ;
520+ await cache . revalidateTag ( "_N_T_/path" ) ;
521+
522+ expect ( tagCache . writeTags ) . toHaveBeenCalled ( ) ;
523+ expect ( tagCache . writeTags ) . toHaveBeenCalledWith ( [
524+ {
525+ path : "/path" ,
526+ tag : "_N_T_/path" ,
527+ } ,
528+ ] ) ;
529+
530+ expect ( invalidateCdnHandler . invalidatePaths ) . toHaveBeenCalled ( ) ;
531+ } ) ;
532+
533+ it ( "Should not call invalidateCdnHandler.invalidatePaths for fetch cache key " , async ( ) => {
534+ globalThis . tagCache . getByTag . mockResolvedValueOnce ( [ "123456" ] ) ;
535+ await cache . revalidateTag ( "tag" ) ;
536+
537+ expect ( tagCache . writeTags ) . toHaveBeenCalled ( ) ;
538+ expect ( tagCache . writeTags ) . toHaveBeenCalledWith ( [
539+ {
540+ path : "123456" ,
541+ tag : "tag" ,
542+ } ,
543+ ] ) ;
544+
545+ expect ( invalidateCdnHandler . invalidatePaths ) . not . toHaveBeenCalled ( ) ;
546+ } ) ;
547+ } ) ;
473548} ) ;
0 commit comments