Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit c8d7757

Browse files
test(plugin): add tests (#108)
* test: plugin * test: plugin
1 parent a389f2d commit c8d7757

31 files changed

+7938
-3755
lines changed

package-lock.json

+6,865-3,745
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+15-9
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"appveyor:test": "npm run test",
1414
"build": "cross-env NODE_ENV=production babel src -d dist --ignore 'src/**/*.test.js'",
1515
"clean": "del-cli dist",
16-
"lint": "eslint --cache src test",
16+
"lint": "eslint --cache src test --ignore-pattern fixtures",
1717
"lint-staged": "lint-staged",
1818
"prebuild": "npm run clean",
1919
"prepare": "npm run build",
@@ -36,7 +36,7 @@
3636
},
3737
"devDependencies": {
3838
"babel-cli": "^6.26.0",
39-
"babel-jest": "^21.2.0",
39+
"babel-jest": "^23.4.2",
4040
"babel-plugin-transform-object-rest-spread": "^6.26.0",
4141
"babel-polyfill": "^6.26.0",
4242
"babel-preset-env": "^1.6.1",
@@ -45,12 +45,13 @@
4545
"eslint": "^4.9.0",
4646
"eslint-config-webpack": "^1.2.5",
4747
"eslint-plugin-import": "^2.8.0",
48-
"jest": "^21.2.1",
49-
"lint-staged": "^4.3.0",
50-
"nsp": "^2.8.1",
48+
"file-loader": "^2.0.0",
49+
"jest": "^23.5.0",
50+
"lint-staged": "^7.2.2",
51+
"nsp": "^3.2.1",
5152
"pre-commit": "^1.2.2",
5253
"standard-version": "^4.2.0",
53-
"webpack": "^3.8.1",
54+
"webpack": "^4.17.1",
5455
"webpack-defaults": "^1.6.0"
5556
},
5657
"peerDependencies": {
@@ -69,9 +70,14 @@
6970
},
7071
"pre-commit": "lint-staged",
7172
"lint-staged": {
72-
"*.js": [
73-
"eslint --fix",
74-
"git add"
73+
"linters": {
74+
"*.js": [
75+
"eslint --fix",
76+
"git add"
77+
]
78+
},
79+
"ignore": [
80+
"**/fixtures/**"
7581
]
7682
}
7783
}

src/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ class CompressionPlugin {
124124
const sub = {
125125
file,
126126
path: parse.pathname,
127-
query: parse.query || '',
127+
query: parse.query ? `?${parse.query}` : '',
128128
};
129129

130130
let newAssetName = assetName.replace(/\[(file|path|query)\]/g, (p0, p1) => sub[p1]);

test/CompressionPlugin.test.js

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import Plugin from '../src/index';
2+
import { cleanErrorStack, createCompiler, compile } from './helpers';
3+
4+
describe('CompressionPlugin', () => {
5+
let compiler;
6+
7+
beforeEach(() => {
8+
compiler = createCompiler({
9+
entry: {
10+
js: `${__dirname}/fixtures/entry.js`,
11+
},
12+
output: {
13+
path: `${__dirname}/dist`,
14+
filename: '[name].js?var=[hash]',
15+
chunkFilename: '[id].[name].js?ver=[hash]',
16+
},
17+
});
18+
});
19+
20+
it('should works (without options)', () => {
21+
new Plugin().apply(compiler);
22+
23+
return compile(compiler).then((stats) => {
24+
const errors = stats.compilation.errors.map(cleanErrorStack);
25+
const warnings = stats.compilation.warnings.map(cleanErrorStack);
26+
27+
expect(errors).toMatchSnapshot('errors');
28+
expect(warnings).toMatchSnapshot('warnings');
29+
expect(Object.keys(stats.compilation.assets).sort()).toMatchSnapshot('assets');
30+
});
31+
});
32+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`CompressionPlugin should works (without options): assets 1`] = `
4+
Array [
5+
"1.async.js?ver=1ea6f97e389bd951fd50",
6+
"5b1f36bc41ab31f5b801d48ba1d65781.png",
7+
"96621d3c37d96ad3bf792fcc848d912f.svg",
8+
"96621d3c37d96ad3bf792fcc848d912f.svg.gz",
9+
"js.js.gz?var=1ea6f97e389bd951fd50",
10+
"js.js?var=1ea6f97e389bd951fd50",
11+
]
12+
`;
13+
14+
exports[`CompressionPlugin should works (without options): errors 1`] = `Array []`;
15+
16+
exports[`CompressionPlugin should works (without options): warnings 1`] = `Array []`;
+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`when applied with \`algorithm\` option matches snapshot for \`{Function}\` value: assets 1`] = `
4+
Array [
5+
"1.async.9ada34e1a37e6db8ef40.js",
6+
"1.async.9ada34e1a37e6db8ef40.js.gz",
7+
"5b1f36bc41ab31f5b801d48ba1d65781.png",
8+
"5b1f36bc41ab31f5b801d48ba1d65781.png.gz",
9+
"96621d3c37d96ad3bf792fcc848d912f.svg",
10+
"96621d3c37d96ad3bf792fcc848d912f.svg.gz",
11+
"js.f0111e97a13538df48f2.js",
12+
"js.f0111e97a13538df48f2.js.gz",
13+
]
14+
`;
15+
16+
exports[`when applied with \`algorithm\` option matches snapshot for \`{Function}\` value: errors 1`] = `Array []`;
17+
18+
exports[`when applied with \`algorithm\` option matches snapshot for \`{Function}\` value: warnings 1`] = `Array []`;
19+
20+
exports[`when applied with \`algorithm\` option matches snapshot for \`gzip\` value: assets 1`] = `
21+
Array [
22+
"1.async.9ada34e1a37e6db8ef40.js",
23+
"1.async.9ada34e1a37e6db8ef40.js.gz",
24+
"5b1f36bc41ab31f5b801d48ba1d65781.png",
25+
"5b1f36bc41ab31f5b801d48ba1d65781.png.gz",
26+
"96621d3c37d96ad3bf792fcc848d912f.svg",
27+
"96621d3c37d96ad3bf792fcc848d912f.svg.gz",
28+
"js.f0111e97a13538df48f2.js",
29+
"js.f0111e97a13538df48f2.js.gz",
30+
]
31+
`;
32+
33+
exports[`when applied with \`algorithm\` option matches snapshot for \`gzip\` value: errors 1`] = `Array []`;
34+
35+
exports[`when applied with \`algorithm\` option matches snapshot for \`gzip\` value: warnings 1`] = `Array []`;
36+
37+
exports[`when applied with \`algorithm\` option matches snapshot for \`unknown\` value ({String}) 1`] = `"Algorithm not found in zlib"`;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`when applied with \`asset\` option matches snapshot for \`[path].compressed.gz[query]\` value: assets 1`] = `
4+
Array [
5+
"1.async.js.compressed.gz?ver=1ea6f97e389bd951fd50",
6+
"1.async.js?ver=1ea6f97e389bd951fd50",
7+
"5b1f36bc41ab31f5b801d48ba1d65781.png",
8+
"5b1f36bc41ab31f5b801d48ba1d65781.png.compressed.gz",
9+
"96621d3c37d96ad3bf792fcc848d912f.svg",
10+
"96621d3c37d96ad3bf792fcc848d912f.svg.compressed.gz",
11+
"js.js.compressed.gz?var=1ea6f97e389bd951fd50",
12+
"js.js?var=1ea6f97e389bd951fd50",
13+
]
14+
`;
15+
16+
exports[`when applied with \`asset\` option matches snapshot for \`[path].compressed.gz[query]\` value: errors 1`] = `Array []`;
17+
18+
exports[`when applied with \`asset\` option matches snapshot for \`[path].compressed.gz[query]\` value: warnings 1`] = `Array []`;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`when applied with \`cache\` option matches snapshot for \`false\` value: assets 1`] = `
4+
Array [
5+
"1.async.9ada34e1a37e6db8ef40.js",
6+
"1.async.9ada34e1a37e6db8ef40.js.gz",
7+
"5b1f36bc41ab31f5b801d48ba1d65781.png",
8+
"5b1f36bc41ab31f5b801d48ba1d65781.png.gz",
9+
"96621d3c37d96ad3bf792fcc848d912f.svg",
10+
"96621d3c37d96ad3bf792fcc848d912f.svg.gz",
11+
"js.f0111e97a13538df48f2.js",
12+
"js.f0111e97a13538df48f2.js.gz",
13+
]
14+
`;
15+
16+
exports[`when applied with \`cache\` option matches snapshot for \`false\` value: errors 1`] = `Array []`;
17+
18+
exports[`when applied with \`cache\` option matches snapshot for \`false\` value: warnings 1`] = `Array []`;
19+
20+
exports[`when applied with \`cache\` option matches snapshot for \`true\` value: 1.async.9ada34e1a37e6db8ef40.js 1`] = `
21+
Array [
22+
"1.async.9ada34e1a37e6db8ef40.js",
23+
"c19de9cd1850eadbe1cb6718a4fdf014",
24+
]
25+
`;
26+
27+
exports[`when applied with \`cache\` option matches snapshot for \`true\` value: 5b1f36bc41ab31f5b801d48ba1d65781.png 1`] = `
28+
Array [
29+
"5b1f36bc41ab31f5b801d48ba1d65781.png",
30+
"09a1a1112c577c2794359715edfcb5ac",
31+
]
32+
`;
33+
34+
exports[`when applied with \`cache\` option matches snapshot for \`true\` value: 96621d3c37d96ad3bf792fcc848d912f.svg 1`] = `
35+
Array [
36+
"96621d3c37d96ad3bf792fcc848d912f.svg",
37+
"23fc1d3ac606d117e05a140e0de79806",
38+
]
39+
`;
40+
41+
exports[`when applied with \`cache\` option matches snapshot for \`true\` value: assets 1`] = `
42+
Array [
43+
"1.async.9ada34e1a37e6db8ef40.js",
44+
"1.async.9ada34e1a37e6db8ef40.js.gz",
45+
"5b1f36bc41ab31f5b801d48ba1d65781.png",
46+
"5b1f36bc41ab31f5b801d48ba1d65781.png.gz",
47+
"96621d3c37d96ad3bf792fcc848d912f.svg",
48+
"96621d3c37d96ad3bf792fcc848d912f.svg.gz",
49+
"js.f0111e97a13538df48f2.js",
50+
"js.f0111e97a13538df48f2.js.gz",
51+
]
52+
`;
53+
54+
exports[`when applied with \`cache\` option matches snapshot for \`true\` value: assets 2`] = `
55+
Array [
56+
"1.async.9ada34e1a37e6db8ef40.js",
57+
"1.async.9ada34e1a37e6db8ef40.js.gz",
58+
"5b1f36bc41ab31f5b801d48ba1d65781.png",
59+
"5b1f36bc41ab31f5b801d48ba1d65781.png.gz",
60+
"96621d3c37d96ad3bf792fcc848d912f.svg",
61+
"96621d3c37d96ad3bf792fcc848d912f.svg.gz",
62+
"js.f0111e97a13538df48f2.js",
63+
"js.f0111e97a13538df48f2.js.gz",
64+
]
65+
`;
66+
67+
exports[`when applied with \`cache\` option matches snapshot for \`true\` value: errors 1`] = `Array []`;
68+
69+
exports[`when applied with \`cache\` option matches snapshot for \`true\` value: errors 2`] = `Array []`;
70+
71+
exports[`when applied with \`cache\` option matches snapshot for \`true\` value: js.f0111e97a13538df48f2.js 1`] = `
72+
Array [
73+
"js.f0111e97a13538df48f2.js",
74+
"1c64a5f14981dc0e16e7e9ef6cb1d7e4",
75+
]
76+
`;
77+
78+
exports[`when applied with \`cache\` option matches snapshot for \`true\` value: warnings 1`] = `Array []`;
79+
80+
exports[`when applied with \`cache\` option matches snapshot for \`true\` value: warnings 2`] = `Array []`;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`when applied with \`test\` option matches snapshot for \`false\` value: assets 1`] = `
4+
Array [
5+
"1.async.9ada34e1a37e6db8ef40.js",
6+
"1.async.9ada34e1a37e6db8ef40.js.gz",
7+
"5b1f36bc41ab31f5b801d48ba1d65781.png",
8+
"5b1f36bc41ab31f5b801d48ba1d65781.png.gz",
9+
"96621d3c37d96ad3bf792fcc848d912f.svg",
10+
"96621d3c37d96ad3bf792fcc848d912f.svg.gz",
11+
"js.f0111e97a13538df48f2.js",
12+
"js.f0111e97a13538df48f2.js.gz",
13+
]
14+
`;
15+
16+
exports[`when applied with \`test\` option matches snapshot for \`false\` value: errors 1`] = `Array []`;
17+
18+
exports[`when applied with \`test\` option matches snapshot for \`false\` value: warnings 1`] = `Array []`;
19+
20+
exports[`when applied with \`test\` option matches snapshot for \`true\` value: assets 1`] = `
21+
Array [
22+
"1.async.9ada34e1a37e6db8ef40.js.gz",
23+
"5b1f36bc41ab31f5b801d48ba1d65781.png.gz",
24+
"96621d3c37d96ad3bf792fcc848d912f.svg.gz",
25+
"js.f0111e97a13538df48f2.js.gz",
26+
]
27+
`;
28+
29+
exports[`when applied with \`test\` option matches snapshot for \`true\` value: errors 1`] = `Array []`;
30+
31+
exports[`when applied with \`test\` option matches snapshot for \`true\` value: warnings 1`] = `Array []`;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`when applied with \`exclude\` option matches snapshot for a single \`exclude\` value: assets 1`] = `
4+
Array [
5+
"1.async.js.gz?ver=1ea6f97e389bd951fd50",
6+
"1.async.js?ver=1ea6f97e389bd951fd50",
7+
"5b1f36bc41ab31f5b801d48ba1d65781.png",
8+
"5b1f36bc41ab31f5b801d48ba1d65781.png.gz",
9+
"96621d3c37d96ad3bf792fcc848d912f.svg",
10+
"js.js.gz?var=1ea6f97e389bd951fd50",
11+
"js.js?var=1ea6f97e389bd951fd50",
12+
]
13+
`;
14+
15+
exports[`when applied with \`exclude\` option matches snapshot for a single \`exclude\` value: errors 1`] = `Array []`;
16+
17+
exports[`when applied with \`exclude\` option matches snapshot for a single \`exclude\` value: warnings 1`] = `Array []`;
18+
19+
exports[`when applied with \`exclude\` option matches snapshot for multiple \`exclude\` values: assets 1`] = `
20+
Array [
21+
"1.async.js.gz?ver=1ea6f97e389bd951fd50",
22+
"1.async.js?ver=1ea6f97e389bd951fd50",
23+
"5b1f36bc41ab31f5b801d48ba1d65781.png",
24+
"96621d3c37d96ad3bf792fcc848d912f.svg",
25+
"js.js.gz?var=1ea6f97e389bd951fd50",
26+
"js.js?var=1ea6f97e389bd951fd50",
27+
]
28+
`;
29+
30+
exports[`when applied with \`exclude\` option matches snapshot for multiple \`exclude\` values: errors 1`] = `Array []`;
31+
32+
exports[`when applied with \`exclude\` option matches snapshot for multiple \`exclude\` values: warnings 1`] = `Array []`;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`when applied with \`function\` option matches snapshot for \`{Function}\` value: assets 1`] = `
4+
Array [
5+
"1.async.js?ver=1ea6f97e389bd951fd50",
6+
"5b1f36bc41ab31f5b801d48ba1d65781.png",
7+
"96621d3c37d96ad3bf792fcc848d912f.svg",
8+
"js.js?var=1ea6f97e389bd951fd50",
9+
"path/to/my/1.async.js.gz?ver=1ea6f97e389bd951fd50",
10+
"path/to/my/5b1f36bc41ab31f5b801d48ba1d65781.png.gz",
11+
"path/to/my/96621d3c37d96ad3bf792fcc848d912f.svg.gz",
12+
"path/to/my/js.js.gz?var=1ea6f97e389bd951fd50",
13+
]
14+
`;
15+
16+
exports[`when applied with \`function\` option matches snapshot for \`{Function}\` value: errors 1`] = `Array []`;
17+
18+
exports[`when applied with \`function\` option matches snapshot for \`{Function}\` value: warnings 1`] = `Array []`;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`when applied with \`include\` option matches snapshot for a single \`include\` value: assets 1`] = `
4+
Array [
5+
"1.async.js.gz?ver=1ea6f97e389bd951fd50",
6+
"1.async.js?ver=1ea6f97e389bd951fd50",
7+
"5b1f36bc41ab31f5b801d48ba1d65781.png",
8+
"96621d3c37d96ad3bf792fcc848d912f.svg",
9+
"js.js.gz?var=1ea6f97e389bd951fd50",
10+
"js.js?var=1ea6f97e389bd951fd50",
11+
]
12+
`;
13+
14+
exports[`when applied with \`include\` option matches snapshot for a single \`include\` value: errors 1`] = `Array []`;
15+
16+
exports[`when applied with \`include\` option matches snapshot for a single \`include\` value: warnings 1`] = `Array []`;
17+
18+
exports[`when applied with \`include\` option matches snapshot for multiple \`include\` values: assets 1`] = `
19+
Array [
20+
"1.async.js.gz?ver=1ea6f97e389bd951fd50",
21+
"1.async.js?ver=1ea6f97e389bd951fd50",
22+
"5b1f36bc41ab31f5b801d48ba1d65781.png",
23+
"96621d3c37d96ad3bf792fcc848d912f.svg",
24+
"96621d3c37d96ad3bf792fcc848d912f.svg.gz",
25+
"js.js.gz?var=1ea6f97e389bd951fd50",
26+
"js.js?var=1ea6f97e389bd951fd50",
27+
]
28+
`;
29+
30+
exports[`when applied with \`include\` option matches snapshot for multiple \`include\` values: errors 1`] = `Array []`;
31+
32+
exports[`when applied with \`include\` option matches snapshot for multiple \`include\` values: warnings 1`] = `Array []`;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`when applied with \`minRatio\` option matches snapshot for \`0\` value: assets 1`] = `
4+
Array [
5+
"1.async.js?ver=1ea6f97e389bd951fd50",
6+
"5b1f36bc41ab31f5b801d48ba1d65781.png",
7+
"96621d3c37d96ad3bf792fcc848d912f.svg",
8+
"js.js?var=1ea6f97e389bd951fd50",
9+
]
10+
`;
11+
12+
exports[`when applied with \`minRatio\` option matches snapshot for \`0\` value: errors 1`] = `Array []`;
13+
14+
exports[`when applied with \`minRatio\` option matches snapshot for \`0\` value: warnings 1`] = `Array []`;
15+
16+
exports[`when applied with \`minRatio\` option matches snapshot for \`1\` value: assets 1`] = `
17+
Array [
18+
"1.async.js.gz?ver=1ea6f97e389bd951fd50",
19+
"1.async.js?ver=1ea6f97e389bd951fd50",
20+
"5b1f36bc41ab31f5b801d48ba1d65781.png",
21+
"5b1f36bc41ab31f5b801d48ba1d65781.png.gz",
22+
"96621d3c37d96ad3bf792fcc848d912f.svg",
23+
"96621d3c37d96ad3bf792fcc848d912f.svg.gz",
24+
"js.js.gz?var=1ea6f97e389bd951fd50",
25+
"js.js?var=1ea6f97e389bd951fd50",
26+
]
27+
`;
28+
29+
exports[`when applied with \`minRatio\` option matches snapshot for \`1\` value: errors 1`] = `Array []`;
30+
31+
exports[`when applied with \`minRatio\` option matches snapshot for \`1\` value: warnings 1`] = `Array []`;

0 commit comments

Comments
 (0)