@@ -80,6 +80,12 @@ describe(OperationBuildCache.name, () => {
8080 describe ( 'direct file cloud cache restore' , ( ) => {
8181 let fakeLockRelease : jest . Mock ;
8282
83+ function mockTarSuccess ( ) : jest . Mock {
84+ const tryUntarAsync : jest . Mock = jest . fn ( ) . mockResolvedValue ( 0 ) ;
85+ _setTarUtilityPromiseForTesting ( Promise . resolve ( { tryUntarAsync } as unknown as TarExecutable ) ) ;
86+ return tryUntarAsync ;
87+ }
88+
8389 beforeEach ( ( ) => {
8490 fakeLockRelease = jest . fn ( ) ;
8591 // By default, simulate an uncontended lock acquisition and no pre-existing cache entry.
@@ -138,14 +144,13 @@ describe(OperationBuildCache.name, () => {
138144 tryDownloadCacheEntryToFileAsync
139145 } ) ;
140146 const terminal : Terminal = new Terminal ( new StringBufferTerminalProvider ( ) ) ;
141- const tryUntarAsync : jest . Mock = jest . fn ( ) . mockResolvedValue ( 0 ) ;
142147
143148 jest . spyOn ( FileSystem , 'deleteFolderAsync' ) . mockResolvedValue ( ) ;
144149 const moveAsyncSpy : jest . SpyInstance = jest . spyOn ( FileSystem , 'moveAsync' ) . mockResolvedValue ( ) ;
145150 const deleteFileAsyncSpy : jest . SpyInstance = jest
146151 . spyOn ( FileSystem , 'deleteFileAsync' )
147152 . mockResolvedValue ( ) ;
148- _setTarUtilityPromiseForTesting ( Promise . resolve ( { tryUntarAsync } as unknown as TarExecutable ) ) ;
153+ const tryUntarAsync : jest . Mock = mockTarSuccess ( ) ;
149154
150155 const result : boolean = await subject . tryRestoreFromCacheAsync ( terminal ) ;
151156
@@ -203,13 +208,12 @@ describe(OperationBuildCache.name, () => {
203208 tryDownloadCacheEntryToFileAsync
204209 } ) ;
205210 const terminal : Terminal = new Terminal ( new StringBufferTerminalProvider ( ) ) ;
206- const tryUntarAsync : jest . Mock = jest . fn ( ) . mockResolvedValue ( 0 ) ;
207211
208212 jest . spyOn ( FileSystem , 'deleteFolderAsync' ) . mockResolvedValue ( ) ;
209213 // Simulate the cache entry having been fully populated (e.g. by another local process)
210214 // by the time we acquired the lock.
211215 jest . spyOn ( FileSystem , 'existsAsync' ) . mockResolvedValue ( true ) ;
212- Reflect . set ( OperationBuildCache , '_tarUtilityPromise' , Promise . resolve ( { tryUntarAsync } ) ) ;
216+ const tryUntarAsync : jest . Mock = mockTarSuccess ( ) ;
213217
214218 const result : boolean = await subject . tryRestoreFromCacheAsync ( terminal ) ;
215219
@@ -233,11 +237,10 @@ describe(OperationBuildCache.name, () => {
233237 tryDownloadCacheEntryToFileAsync
234238 } ) ;
235239 const terminal : Terminal = new Terminal ( new StringBufferTerminalProvider ( ) ) ;
236- const tryUntarAsync : jest . Mock = jest . fn ( ) . mockResolvedValue ( 0 ) ;
237240
238241 jest . spyOn ( FileSystem , 'deleteFolderAsync' ) . mockResolvedValue ( ) ;
239242 jest . spyOn ( FileSystem , 'moveAsync' ) . mockResolvedValue ( ) ;
240- Reflect . set ( OperationBuildCache , '_tarUtilityPromise' , Promise . resolve ( { tryUntarAsync } ) ) ;
243+ mockTarSuccess ( ) ;
241244
242245 const result : boolean = await subject . tryRestoreFromCacheAsync ( terminal ) ;
243246
0 commit comments