@@ -4,6 +4,7 @@ import { vi } from "vitest";
4
4
5
5
declare global {
6
6
var disableIncrementalCache : boolean ;
7
+ var disableDynamoDBCache : boolean ;
7
8
var isNextAfter15 : boolean ;
8
9
}
9
10
@@ -39,6 +40,12 @@ describe("CacheHandler", () => {
39
40
} ;
40
41
globalThis . tagCache = tagCache ;
41
42
43
+ const invalidateCdnHandler = {
44
+ name : "mock" ,
45
+ invalidatePaths : vi . fn ( ) ,
46
+ } ;
47
+ globalThis . cdnInvalidationHandler = invalidateCdnHandler ;
48
+
42
49
globalThis . __openNextAls = {
43
50
getStore : vi . fn ( ) . mockReturnValue ( {
44
51
requestId : "123" ,
@@ -470,4 +477,72 @@ describe("CacheHandler", () => {
470
477
) . not . toThrow ( ) ;
471
478
} ) ;
472
479
} ) ;
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 ) . toHaveBeenCalledTimes ( 1 ) ;
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 ) . toHaveBeenCalledTimes ( 1 ) ;
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 ) . toHaveBeenCalledTimes ( 1 ) ;
538
+ expect ( tagCache . writeTags ) . toHaveBeenCalledWith ( [
539
+ {
540
+ path : "123456" ,
541
+ tag : "tag" ,
542
+ } ,
543
+ ] ) ;
544
+
545
+ expect ( invalidateCdnHandler . invalidatePaths ) . not . toHaveBeenCalled ( ) ;
546
+ } ) ;
547
+ } ) ;
473
548
} ) ;
0 commit comments