@@ -13,6 +13,7 @@ import {
1313 CacheEntry ,
1414 GetFreshValue ,
1515 createCacheEntry ,
16+ getPendingValuesCache ,
1617} from './index' ;
1718import { Deferred } from './createBatch' ;
1819import { delay , report } from './testHelpers' ;
@@ -1112,6 +1113,23 @@ describe('cachified', () => {
11121113 expect ( await getValue ( ( ) => 'FOUR' ) ) . toBe ( 'THREE' ) ;
11131114 } ) ;
11141115
1116+ it ( 'provides access to internal pending values cache' , async ( ) => {
1117+ const cache = new Map < string , CacheEntry > ( ) ;
1118+ const pendingValuesCache = getPendingValuesCache ( cache ) ;
1119+ const d = new Deferred < string > ( ) ;
1120+
1121+ cachified ( { cache, key : 'test' , ttl : 5 , getFreshValue : ( ) => d . promise } ) ;
1122+ await delay ( 0 ) ; // pending values are not set immediately
1123+
1124+ expect ( pendingValuesCache . get ( 'test' ) ) . toEqual (
1125+ expect . objectContaining ( {
1126+ metadata : anyMetadata ,
1127+ value : expect . any ( Promise ) ,
1128+ resolve : expect . any ( Function ) ,
1129+ } ) ,
1130+ ) ;
1131+ } ) ;
1132+
11151133 it ( 'uses stale cache while revalidating' , async ( ) => {
11161134 const cache = new Map < string , CacheEntry > ( ) ;
11171135 const reporter = createReporter ( ) ;
@@ -1679,7 +1697,7 @@ describe('cachified', () => {
16791697 } ) ;
16801698
16811699 it ( 'supports trace ids' , async ( ) => {
1682- expect . assertions ( 6 ) ;
1700+ expect . assertions ( 7 ) ;
16831701
16841702 const cache = new Map < string , CacheEntry > ( ) ;
16851703 const traceId1 = Symbol ( ) ;
@@ -1698,6 +1716,11 @@ describe('cachified', () => {
16981716 } ) ;
16991717 await delay ( 0 ) ;
17001718
1719+ // on pending values cache
1720+ expect ( getPendingValuesCache ( cache ) . get ( 'test-1' ) ?. metadata . traceId ) . toBe (
1721+ traceId1 ,
1722+ ) ;
1723+
17011724 d . resolve ( 'ONE' ) ;
17021725 expect ( await value ) . toBe ( 'ONE' ) ;
17031726
0 commit comments