@@ -6,6 +6,7 @@ import findCacheDir from 'find-cache-dir';
6
6
import del from 'del' ;
7
7
8
8
import CompressionPlugin from '../src/index' ;
9
+ import Webpack4Cache from '../src/Webpack4Cache' ;
9
10
10
11
import {
11
12
compile ,
@@ -17,13 +18,15 @@ import {
17
18
18
19
const cacheDir = findCacheDir ( { name : 'compression-webpack-plugin' } ) ;
19
20
const otherCacheDir = findCacheDir ( { name : 'other-cache-directory' } ) ;
21
+ const uniqueDirectory = findCacheDir ( { name : 'unique-cache-directory' } ) ;
20
22
21
23
if ( getCompiler . isWebpack4 ( ) ) {
22
24
describe ( '"cache" option' , ( ) => {
23
25
beforeEach ( ( ) => {
24
26
return Promise . all ( [
25
27
cacache . rm . all ( cacheDir ) ,
26
28
cacache . rm . all ( otherCacheDir ) ,
29
+ cacache . rm . all ( uniqueDirectory ) ,
27
30
] ) ;
28
31
} ) ;
29
32
@@ -65,6 +68,12 @@ if (getCompiler.isWebpack4()) {
65
68
cacache . get = jest . fn ( cacache . get ) ;
66
69
cacache . put = jest . fn ( cacache . put ) ;
67
70
71
+ const getCacheDirectorySpy = jest
72
+ . spyOn ( Webpack4Cache , 'getCacheDirectory' )
73
+ . mockImplementation ( ( ) => {
74
+ return uniqueDirectory ;
75
+ } ) ;
76
+
68
77
const stats = await compile ( beforeCacheCompiler ) ;
69
78
70
79
expect ( getAssetsNameAndSize ( stats ) ) . toMatchSnapshot ( 'assets' ) ;
@@ -78,7 +87,7 @@ if (getCompiler.isWebpack4()) {
78
87
// Put files in cache
79
88
expect ( cacache . put . mock . calls . length ) . toBe ( countAssets / 2 ) ;
80
89
81
- const cacheEntriesList = await cacache . ls ( cacheDir ) ;
90
+ const cacheEntriesList = await cacache . ls ( uniqueDirectory ) ;
82
91
83
92
const cacheKeys = Object . keys ( cacheEntriesList ) ;
84
93
@@ -117,6 +126,8 @@ if (getCompiler.isWebpack4()) {
117
126
// Now we have cached files so we get their and don't put
118
127
expect ( cacache . get . mock . calls . length ) . toBe ( newCountAssets / 2 ) ;
119
128
expect ( cacache . put . mock . calls . length ) . toBe ( 0 ) ;
129
+
130
+ getCacheDirectorySpy . mockRestore ( ) ;
120
131
} ) ;
121
132
122
133
it ( 'matches snapshot for `other-cache-directory` value ({String})' , async ( ) => {
0 commit comments