@@ -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
} ) ;
@@ -350,7 +355,8 @@ describe('cache mechanism works as expected', () => {
350
355
351
356
describe ( 'CLI works with a custom cache path' , ( ) => {
352
357
let writeSpy ;
353
- const customCachePath = path . join ( __dirname , '__custom_cache__' ) ;
358
+ const projectRoot = path . resolve ( __dirname , '../../../' ) ;
359
+ const customCachePath = path . join ( projectRoot , '__custom_cache__' ) ;
354
360
const config : TransformConfig = {
355
361
input : path . resolve ( './source' ) ,
356
362
output : path . resolve ( './src' ) ,
@@ -392,31 +398,21 @@ describe('CLI works with a custom cache path', () => {
392
398
test ( 'uses the custom cache path for caching' , async ( ) => {
393
399
await compileDirectory ( config ) ;
394
400
395
- const customFilePath = path . join ( config . input , 'index.js' ) ;
396
-
397
- const cacheFilePath = path . join (
398
- customCachePath ,
399
- path . relative ( config . input , customFilePath ) + '.json' ,
400
- ) ;
401
-
402
- expect (
403
- await fs
404
- . access ( customCachePath )
405
- . then ( ( ) => true )
406
- . catch ( ( ) => false ) ,
407
- ) . toBe ( true ) ;
408
- expect (
409
- await fs
410
- . access ( cacheFilePath )
411
- . then ( ( ) => true )
412
- . catch ( ( ) => false ) ,
413
- ) . toBe ( true ) ;
401
+ const cacheFiles = await fs . readdir ( customCachePath ) ;
402
+ expect ( cacheFiles . length ) . toEqual ( 3 ) ;
414
403
415
- const cacheData = JSON . parse ( await fs . readFile ( cacheFilePath , 'utf-8' ) ) ;
416
- expect ( cacheData ) . toHaveProperty ( 'inputHash' ) ;
417
- expect ( cacheData ) . toHaveProperty ( 'outputHash' ) ;
418
- expect ( cacheData ) . toHaveProperty ( 'collectedCSS' ) ;
404
+ for ( const cacheFile of cacheFiles ) {
405
+ const cacheFilePath = path . join ( customCachePath , cacheFile ) ;
406
+ const cacheContent = JSON . parse (
407
+ await fs . readFile ( cacheFilePath , 'utf-8' ) ,
408
+ ) ;
409
+ expect ( cacheContent ) . toHaveProperty ( 'inputHash' ) ;
410
+ expect ( cacheContent ) . toHaveProperty ( 'outputHash' ) ;
411
+ expect ( cacheContent ) . toHaveProperty ( 'collectedCSS' ) ;
412
+ expect ( cacheContent ) . toHaveProperty ( 'configHash' ) ;
413
+ }
419
414
} ) ;
415
+
420
416
test ( 'skips transformation when cache is valid' , async ( ) => {
421
417
await compileDirectory ( config ) ;
422
418
0 commit comments