@@ -6,6 +6,7 @@ import findCacheDir from 'find-cache-dir';
66import del from 'del' ;
77
88import CompressionPlugin from '../src/index' ;
9+ import Webpack4Cache from '../src/Webpack4Cache' ;
910
1011import {
1112 compile ,
@@ -17,13 +18,15 @@ import {
1718
1819const cacheDir = findCacheDir ( { name : 'compression-webpack-plugin' } ) ;
1920const otherCacheDir = findCacheDir ( { name : 'other-cache-directory' } ) ;
21+ const uniqueDirectory = findCacheDir ( { name : 'unique-cache-directory' } ) ;
2022
2123if ( getCompiler . isWebpack4 ( ) ) {
2224 describe ( '"cache" option' , ( ) => {
2325 beforeEach ( ( ) => {
2426 return Promise . all ( [
2527 cacache . rm . all ( cacheDir ) ,
2628 cacache . rm . all ( otherCacheDir ) ,
29+ cacache . rm . all ( uniqueDirectory ) ,
2730 ] ) ;
2831 } ) ;
2932
@@ -65,6 +68,12 @@ if (getCompiler.isWebpack4()) {
6568 cacache . get = jest . fn ( cacache . get ) ;
6669 cacache . put = jest . fn ( cacache . put ) ;
6770
71+ const getCacheDirectorySpy = jest
72+ . spyOn ( Webpack4Cache , 'getCacheDirectory' )
73+ . mockImplementation ( ( ) => {
74+ return uniqueDirectory ;
75+ } ) ;
76+
6877 const stats = await compile ( beforeCacheCompiler ) ;
6978
7079 expect ( getAssetsNameAndSize ( stats ) ) . toMatchSnapshot ( 'assets' ) ;
@@ -78,7 +87,7 @@ if (getCompiler.isWebpack4()) {
7887 // Put files in cache
7988 expect ( cacache . put . mock . calls . length ) . toBe ( countAssets / 2 ) ;
8089
81- const cacheEntriesList = await cacache . ls ( cacheDir ) ;
90+ const cacheEntriesList = await cacache . ls ( uniqueDirectory ) ;
8291
8392 const cacheKeys = Object . keys ( cacheEntriesList ) ;
8493
@@ -117,6 +126,8 @@ if (getCompiler.isWebpack4()) {
117126 // Now we have cached files so we get their and don't put
118127 expect ( cacache . get . mock . calls . length ) . toBe ( newCountAssets / 2 ) ;
119128 expect ( cacache . put . mock . calls . length ) . toBe ( 0 ) ;
129+
130+ getCacheDirectorySpy . mockRestore ( ) ;
120131 } ) ;
121132
122133 it ( 'matches snapshot for `other-cache-directory` value ({String})' , async ( ) => {
0 commit comments