44} from 'bun:test' ;
55import { memoryStore } from 'cache-manager' ;
66import {
7- initializeCache , selectorToCacheKey , cachedFunction , resetCache ,
7+ getOrInitializeCache , selectorToCacheKey , cachedFunction , resetCache ,
88} from '../src/index' ;
99import type { CachedFunctionInitializerOptions , CachedFunctionOptions } from '../src/index.d' ;
1010
@@ -19,7 +19,7 @@ describe('initializeCache', () => {
1919 config : { max : 100 , ttl : 60 } ,
2020 } ;
2121
22- const result = await initializeCache ( options ) ;
22+ const result = await getOrInitializeCache ( options ) ;
2323
2424 expect ( result ) . toBeDefined ( ) ;
2525 expect ( result . store ) . toBeDefined ( ) ;
@@ -30,7 +30,7 @@ describe('initializeCache', () => {
3030 store : memoryStore ( ) ,
3131 } ;
3232
33- const result = await initializeCache ( options ) ;
33+ const result = await getOrInitializeCache ( options ) ;
3434
3535 expect ( result ) . toBeDefined ( ) ;
3636 expect ( result . store ) . toBeDefined ( ) ;
@@ -41,8 +41,8 @@ describe('initializeCache', () => {
4141 store : memoryStore ( ) ,
4242 } ;
4343
44- const firstInit = await initializeCache ( options ) ;
45- const secondInit = await initializeCache ( options ) ;
44+ const firstInit = await getOrInitializeCache ( options ) ;
45+ const secondInit = await getOrInitializeCache ( options ) ;
4646
4747 expect ( firstInit ) . toBe ( secondInit ) ;
4848 } ) ;
@@ -52,11 +52,12 @@ describe('initializeCache', () => {
5252 config : { max : 100 , ttl : 60 } ,
5353 } as any ;
5454
55- await expect ( initializeCache ( options ) ) . rejects . toThrow ( 'store is required' ) ;
55+ await expect ( getOrInitializeCache ( options ) ) . rejects . toThrow ( 'Store is not provided in options but is required to initialize the cache ' ) ;
5656 } ) ;
5757
5858 it ( 'should throw an error if cache is not initialized and no options are provided' , async ( ) => {
59- await expect ( initializeCache ( ) ) . rejects . toThrow ( 'cache is not initialized and no options provided' ) ;
59+ resetCache ( ) ;
60+ await expect ( getOrInitializeCache ( ) ) . rejects . toThrow ( 'cache is not initialized and no options provided' ) ;
6061 } ) ;
6162
6263 it ( 'should initialize cache only once, even with multiple config calls' , async ( ) => {
@@ -65,8 +66,8 @@ describe('initializeCache', () => {
6566 config : { max : 100 , ttl : 60 } ,
6667 } ;
6768
68- const firstCall = await initializeCache ( options ) ;
69- const secondCall = await initializeCache ( ) ;
69+ const firstCall = await getOrInitializeCache ( options ) ;
70+ const secondCall = await getOrInitializeCache ( ) ;
7071
7172 expect ( firstCall ) . toBe ( secondCall ) ;
7273 } ) ;
0 commit comments