Skip to content

Commit 4ae2d09

Browse files
test: coverage
1 parent accb414 commit 4ae2d09

7 files changed

+305
-140
lines changed

src/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,9 +315,9 @@ class CompressionPlugin {
315315
.for('asset.info.compressed')
316316
.tap(
317317
'compression-webpack-plugin',
318-
(minimized, { green, formatFlag }) =>
318+
(compressed, { green, formatFlag }) =>
319319
// eslint-disable-next-line no-undefined
320-
minimized ? green(formatFlag('compressed')) : undefined
320+
compressed ? green(formatFlag('compressed')) : undefined
321321
);
322322
});
323323
});

test/CompressionPlugin.test.js

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ describe('CompressionPlugin', () => {
172172
expect(getErrors(stats)).toMatchSnapshot('warnings');
173173
});
174174

175-
it('should work in watch mode', async () => {
175+
it('should work and use weak cache', async () => {
176176
const compiler = getCompiler('./entry.js');
177177

178178
new CompressionPlugin().apply(compiler);
@@ -214,7 +214,7 @@ describe('CompressionPlugin', () => {
214214
});
215215
});
216216

217-
it('should work in watch mode when "cache" is "false"', async () => {
217+
it('should work and use weak cache when "cache" is "false"', async () => {
218218
if (getCompiler.isWebpack4()) {
219219
expect(true).toBe(true);
220220
} else {
@@ -243,4 +243,32 @@ describe('CompressionPlugin', () => {
243243
});
244244
}
245245
});
246+
247+
it('should work and show compress assets in stats', async () => {
248+
const compiler = getCompiler(
249+
'./entry.js',
250+
{},
251+
{
252+
stats: 'verbose',
253+
output: {
254+
path: `${__dirname}/dist`,
255+
filename: '[name].js',
256+
chunkFilename: '[id].[name].js',
257+
},
258+
}
259+
);
260+
261+
new CompressionPlugin().apply(compiler);
262+
263+
const stats = await compile(compiler);
264+
const stringStats = stats.toString({ relatedAssets: true });
265+
const printedCompressed = stringStats.match(/\[compressed]/g);
266+
267+
expect(printedCompressed ? printedCompressed.length : 0).toBe(
268+
getCompiler.isWebpack4() ? 0 : 3
269+
);
270+
expect(getAssetsNameAndSize(stats)).toMatchSnapshot('assets');
271+
expect(getWarnings(stats)).toMatchSnapshot('errors');
272+
expect(getErrors(stats)).toMatchSnapshot('warnings');
273+
});
246274
});

test/__snapshots__/CompressionPlugin.test.js.snap.webpack4

Lines changed: 96 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,43 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`CompressionPlugin should work child compilations: assets 1`] = `
3+
exports[`CompressionPlugin should work and show compress assets in stats: assets 1`] = `
44
Array [
55
Array [
66
"09a1a1112c577c2794359715edfcb5ac.png",
77
78117,
8-
Object {},
98
],
109
Array [
1110
"23fc1d3ac606d117e05a140e0de79806.svg",
1211
672,
13-
Object {
14-
"related": Object {
15-
"gziped": "23fc1d3ac606d117e05a140e0de79806.svg.gz",
16-
},
17-
},
1812
],
1913
Array [
2014
"23fc1d3ac606d117e05a140e0de79806.svg.gz",
2115
393,
22-
Object {
23-
"compressed": true,
24-
},
25-
],
26-
Array [
27-
"async.async.js.gz",
28-
171,
29-
Object {
30-
"compressed": true,
31-
},
3216
],
3317
Array [
34-
"async.async.js?ver=810493800e70254b803c",
18+
"async.async.js",
3519
249,
36-
Object {
37-
"immutable": true,
38-
"related": Object {
39-
"gziped": "async.async.js.gz",
40-
},
41-
},
4220
],
4321
Array [
44-
"copied.js",
45-
400,
46-
Object {
47-
"copied": true,
48-
"related": Object {
49-
"gziped": "copied.js.gz",
50-
},
51-
},
22+
"async.async.js.gz",
23+
171,
5224
],
5325
Array [
54-
"copied.js.gz",
55-
29,
56-
Object {
57-
"compressed": true,
58-
},
26+
"main.js",
27+
11595,
5928
],
6029
Array [
6130
"main.js.gz",
62-
3001,
63-
Object {
64-
"compressed": true,
65-
},
66-
],
67-
Array [
68-
"main.js?var=810493800e70254b803c",
69-
11627,
70-
Object {
71-
"immutable": true,
72-
"related": Object {
73-
"gziped": "main.js.gz",
74-
},
75-
},
31+
2974,
7632
],
7733
]
7834
`;
7935

80-
exports[`CompressionPlugin should work child compilations: errors 1`] = `Array []`;
36+
exports[`CompressionPlugin should work and show compress assets in stats: errors 1`] = `Array []`;
8137

82-
exports[`CompressionPlugin should work child compilations: warnings 1`] = `Array []`;
38+
exports[`CompressionPlugin should work and show compress assets in stats: warnings 1`] = `Array []`;
8339

84-
exports[`CompressionPlugin should work in watch mode: assets 1`] = `
40+
exports[`CompressionPlugin should work and use weak cache: assets 1`] = `
8541
Array [
8642
Array [
8743
"09a1a1112c577c2794359715edfcb5ac.png",
@@ -114,7 +70,7 @@ Array [
11470
]
11571
`;
11672

117-
exports[`CompressionPlugin should work in watch mode: assets 2`] = `
73+
exports[`CompressionPlugin should work and use weak cache: assets 2`] = `
11874
Array [
11975
Array [
12076
"09a1a1112c577c2794359715edfcb5ac.png",
@@ -147,13 +103,94 @@ Array [
147103
]
148104
`;
149105

150-
exports[`CompressionPlugin should work in watch mode: errors 1`] = `Array []`;
106+
exports[`CompressionPlugin should work and use weak cache: errors 1`] = `Array []`;
107+
108+
exports[`CompressionPlugin should work and use weak cache: errors 2`] = `Array []`;
151109

152-
exports[`CompressionPlugin should work in watch mode: errors 2`] = `Array []`;
110+
exports[`CompressionPlugin should work and use weak cache: warnings 1`] = `Array []`;
111+
112+
exports[`CompressionPlugin should work and use weak cache: warnings 2`] = `Array []`;
113+
114+
exports[`CompressionPlugin should work child compilations: assets 1`] = `
115+
Array [
116+
Array [
117+
"09a1a1112c577c2794359715edfcb5ac.png",
118+
78117,
119+
Object {},
120+
],
121+
Array [
122+
"23fc1d3ac606d117e05a140e0de79806.svg",
123+
672,
124+
Object {
125+
"related": Object {
126+
"gziped": "23fc1d3ac606d117e05a140e0de79806.svg.gz",
127+
},
128+
},
129+
],
130+
Array [
131+
"23fc1d3ac606d117e05a140e0de79806.svg.gz",
132+
393,
133+
Object {
134+
"compressed": true,
135+
},
136+
],
137+
Array [
138+
"async.async.js.gz",
139+
171,
140+
Object {
141+
"compressed": true,
142+
},
143+
],
144+
Array [
145+
"async.async.js?ver=810493800e70254b803c",
146+
249,
147+
Object {
148+
"immutable": true,
149+
"related": Object {
150+
"gziped": "async.async.js.gz",
151+
},
152+
},
153+
],
154+
Array [
155+
"copied.js",
156+
400,
157+
Object {
158+
"copied": true,
159+
"related": Object {
160+
"gziped": "copied.js.gz",
161+
},
162+
},
163+
],
164+
Array [
165+
"copied.js.gz",
166+
29,
167+
Object {
168+
"compressed": true,
169+
},
170+
],
171+
Array [
172+
"main.js.gz",
173+
3001,
174+
Object {
175+
"compressed": true,
176+
},
177+
],
178+
Array [
179+
"main.js?var=810493800e70254b803c",
180+
11627,
181+
Object {
182+
"immutable": true,
183+
"related": Object {
184+
"gziped": "main.js.gz",
185+
},
186+
},
187+
],
188+
]
189+
`;
153190

154-
exports[`CompressionPlugin should work in watch mode: warnings 1`] = `Array []`;
191+
exports[`CompressionPlugin should work child compilations: errors 1`] = `Array []`;
155192

156-
exports[`CompressionPlugin should work in watch mode: warnings 2`] = `Array []`;
193+
exports[`CompressionPlugin should work child compilations: warnings 1`] = `Array []`;
157194

158195
exports[`CompressionPlugin should work with assets info: assets 1`] = `
159196
Array [

0 commit comments

Comments
 (0)