@@ -258,6 +258,11 @@ describe('cache mechanism works as expected', () => {
258
258
copiedNodeModules : false ,
259
259
} ,
260
260
} ;
261
+
262
+ beforeAll ( async ( ) => {
263
+ await fs . rm ( cachePath , { recursive : true , force : true } ) ;
264
+ } ) ;
265
+
261
266
beforeEach ( ( ) => {
262
267
writeSpy = jest . spyOn ( cacheModule , 'writeCache' ) ;
263
268
} ) ;
@@ -280,6 +285,7 @@ describe('cache mechanism works as expected', () => {
280
285
expect ( writeSpy ) . toHaveBeenCalledTimes ( 3 ) ;
281
286
282
287
const cacheFiles = await fs . readdir ( cachePath ) ;
288
+ console . log ( 'cacheFiles' , cacheFiles )
283
289
expect ( cacheFiles . length ) . toEqual ( 3 ) ;
284
290
285
291
for ( const cacheFile of cacheFiles ) {
@@ -327,7 +333,8 @@ describe('cache mechanism works as expected', () => {
327
333
328
334
describe ( 'CLI works with a custom cache path' , ( ) => {
329
335
let writeSpy ;
330
- const customCachePath = path . join ( __dirname , '__custom_cache__' ) ;
336
+ const projectRoot = path . resolve ( __dirname , '../../../' ) ;
337
+ const customCachePath = path . join ( projectRoot , '__custom_cache__' ) ;
331
338
const config : TransformConfig = {
332
339
input : path . resolve ( './source' ) ,
333
340
output : path . resolve ( './src' ) ,
@@ -369,31 +376,21 @@ describe('CLI works with a custom cache path', () => {
369
376
test ( 'uses the custom cache path for caching' , async ( ) => {
370
377
await compileDirectory ( config ) ;
371
378
372
- const customFilePath = path . join ( config . input , 'index.js' ) ;
373
-
374
- const cacheFilePath = path . join (
375
- customCachePath ,
376
- path . relative ( config . input , customFilePath ) + '.json' ,
377
- ) ;
378
-
379
- expect (
380
- await fs
381
- . access ( customCachePath )
382
- . then ( ( ) => true )
383
- . catch ( ( ) => false ) ,
384
- ) . toBe ( true ) ;
385
- expect (
386
- await fs
387
- . access ( cacheFilePath )
388
- . then ( ( ) => true )
389
- . catch ( ( ) => false ) ,
390
- ) . toBe ( true ) ;
379
+ const cacheFiles = await fs . readdir ( customCachePath ) ;
380
+ console . log ( 'cacheFiles' , cacheFiles )
381
+ expect ( cacheFiles . length ) . toEqual ( 3 ) ;
391
382
392
- const cacheData = JSON . parse ( await fs . readFile ( cacheFilePath , 'utf-8' ) ) ;
393
- expect ( cacheData ) . toHaveProperty ( 'inputHash' ) ;
394
- expect ( cacheData ) . toHaveProperty ( 'outputHash' ) ;
395
- expect ( cacheData ) . toHaveProperty ( 'collectedCSS' ) ;
383
+ for ( const cacheFile of cacheFiles ) {
384
+ const cacheFilePath = path . join ( customCachePath , cacheFile ) ;
385
+ const cacheContent = JSON . parse (
386
+ await fs . readFile ( cacheFilePath , 'utf-8' ) ,
387
+ ) ;
388
+ expect ( cacheContent ) . toHaveProperty ( 'inputHash' ) ;
389
+ expect ( cacheContent ) . toHaveProperty ( 'outputHash' ) ;
390
+ expect ( cacheContent ) . toHaveProperty ( 'collectedCSS' ) ;
391
+ }
396
392
} ) ;
393
+
397
394
test ( 'skips transformation when cache is valid' , async ( ) => {
398
395
await compileDirectory ( config ) ;
399
396
0 commit comments