@@ -324,6 +324,62 @@ test("getProjectContext", async (t) => {
324324 t . is ( projectBuildContext , projectBuildContext2 ) ;
325325} ) ;
326326
327+ test ( "getCacheManager: Returns null when cache mode is 'Off'" , async ( t ) => {
328+ const { BuildContext} = t . context ;
329+
330+ const graph = {
331+ getRoot : ( ) => ( { getType : ( ) => "library" , getRootPath : ( ) => "" } ) ,
332+ } ;
333+ const buildContext = new BuildContext ( graph , "taskRepository" , {
334+ cache : "Off"
335+ } ) ;
336+
337+ const cacheManager = await buildContext . getCacheManager ( ) ;
338+ t . is ( cacheManager , null , "Returned null" ) ;
339+ t . is ( t . context . CacheManagerCreate . callCount , 0 ,
340+ "CacheManager.create was not called" ) ;
341+ } ) ;
342+
343+ test ( "getCacheManager: Creates and caches CacheManager for default cache mode" , async ( t ) => {
344+ const { BuildContext} = t . context ;
345+
346+ const cacheManagerInstance = { } ;
347+ t . context . CacheManagerCreate . resetBehavior ( ) ;
348+ t . context . CacheManagerCreate . resolves ( cacheManagerInstance ) ;
349+
350+ const graph = {
351+ getRoot : ( ) => ( { getType : ( ) => "library" , getRootPath : ( ) => "/some/path" } ) ,
352+ } ;
353+ const buildContext = new BuildContext ( graph , "taskRepository" ) ;
354+
355+ const cacheManager1 = await buildContext . getCacheManager ( ) ;
356+ t . is ( cacheManager1 , cacheManagerInstance , "Returned CacheManager instance" ) ;
357+ t . is ( t . context . CacheManagerCreate . callCount , 1 ,
358+ "CacheManager.create was called once" ) ;
359+
360+ const cacheManager2 = await buildContext . getCacheManager ( ) ;
361+ t . is ( cacheManager2 , cacheManagerInstance , "Returned same CacheManager instance" ) ;
362+ t . is ( t . context . CacheManagerCreate . callCount , 1 ,
363+ "CacheManager.create was not called again on subsequent invocations" ) ;
364+ } ) ;
365+
366+ test ( "closeCacheManager: No-op when cache mode is 'Off'" , async ( t ) => {
367+ const { BuildContext} = t . context ;
368+
369+ const graph = {
370+ getRoot : ( ) => ( { getType : ( ) => "library" , getRootPath : ( ) => "" } ) ,
371+ } ;
372+ const buildContext = new BuildContext ( graph , "taskRepository" , {
373+ cache : "Off"
374+ } ) ;
375+
376+ await buildContext . getCacheManager ( ) ;
377+
378+ t . notThrows ( ( ) => {
379+ buildContext . closeCacheManager ( ) ;
380+ } , "closeCacheManager does not throw when no CacheManager was created" ) ;
381+ } ) ;
382+
327383test ( "executeCleanupTasks" , async ( t ) => {
328384 const { BuildContext} = t . context ;
329385
0 commit comments