Skip to content

Commit 69c144c

Browse files
Tests refactor
1 parent 997e00f commit 69c144c

9 files changed

+271
-197
lines changed

test/CssMinimizerPlugin.test.js

+5-10
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ describe('CssMinimizerPlugin', () => {
3939

4040
afterEach(() => Promise.all([removeCache()]));
4141

42-
it('should respect the hash options #1', () => {
42+
it('should respect the hash options #1', async () => {
4343
const compiler = getCompiler({
4444
output: {
4545
pathinfo: false,
@@ -61,16 +61,11 @@ describe('CssMinimizerPlugin', () => {
6161
},
6262
}).apply(compiler);
6363

64-
return compile(compiler).then((stats) => {
65-
expect(stats.compilation.errors).toEqual([]);
66-
expect(stats.compilation.warnings).toEqual([]);
64+
const stats = await compile(compiler);
6765

68-
for (const file in stats.compilation.assets) {
69-
// eslint-disable-next-line no-continue
70-
if (/\.js$/.test(file)) continue;
71-
expect(readAsset(file, compiler, stats)).toMatchSnapshot(file);
72-
}
73-
});
66+
expect(readAssets(compiler, stats, '.css')).toMatchSnapshot('assets');
67+
expect(getErrors(stats)).toMatchSnapshot('errors');
68+
expect(getWarnings(stats)).toMatchSnapshot('warnings');
7469
});
7570

7671
it('should write stdout and stderr of workers to stdout and stderr of main process in parallel mode', async () => {

test/__snapshots__/CssMinimizerPlugin.test.js.snap.webpack4

+9-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,15 @@ Array [
4949
]
5050
`;
5151

52-
exports[`CssMinimizerPlugin should respect the hash options #1: entry.css 1`] = `"a{text-align:center}"`;
52+
exports[`CssMinimizerPlugin should respect the hash options #1: assets 1`] = `
53+
Object {
54+
"entry.css": "a{text-align:center}",
55+
}
56+
`;
57+
58+
exports[`CssMinimizerPlugin should respect the hash options #1: errors 1`] = `Array []`;
59+
60+
exports[`CssMinimizerPlugin should respect the hash options #1: warnings 1`] = `Array []`;
5361

5462
exports[`CssMinimizerPlugin should work with assets using querystring: entry.css.map?v=test 1`] = `"{\\"version\\":3,\\"sources\\": [replaced for tests], \\"names\\":[],\\"mappings\\":\\"AAAA,KACE,SACF,CACA,EACE,UACF\\",\\"file\\":\\"entry.css?v=test\\",\\"sourcesContent\\":[\\"body {\\\\n color: red;\\\\n}\\\\na {\\\\n color: blue;\\\\n}\\"],\\"sourceRoot\\":\\"\\"}"`;
5563

test/__snapshots__/CssMinimizerPlugin.test.js.snap.webpack5

+9-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,15 @@ Array [
4949
]
5050
`;
5151

52-
exports[`CssMinimizerPlugin should respect the hash options #1: entry.css 1`] = `"a{text-align:center}"`;
52+
exports[`CssMinimizerPlugin should respect the hash options #1: assets 1`] = `
53+
Object {
54+
"entry.css": "a{text-align:center}",
55+
}
56+
`;
57+
58+
exports[`CssMinimizerPlugin should respect the hash options #1: errors 1`] = `Array []`;
59+
60+
exports[`CssMinimizerPlugin should respect the hash options #1: warnings 1`] = `Array []`;
5361

5462
exports[`CssMinimizerPlugin should work with assets using querystring: entry.css.map?v=test 1`] = `"{\\"version\\":3,\\"sources\\": [replaced for tests], \\"names\\":[],\\"mappings\\":\\"AAAA,KACE,SACF,CACA,EACE,UACF\\",\\"file\\":\\"entry.css?v=test\\",\\"sourcesContent\\":[\\"body {\\\\n color: red;\\\\n}\\\\na {\\\\n color: blue;\\\\n}\\"],\\"sourceRoot\\":\\"\\"}"`;
5563

test/__snapshots__/sourceMap-option.test.js.snap.webpack4

+54-31
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,79 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`when applied with "sourceMap" option matches snapshot for "false" value, using previous sourcemap: entry.css 1`] = `"body{font-weight:700;color:red}body a{text-align:center}"`;
4-
5-
exports[`when applied with "sourceMap" option matches snapshot for "false" value, using previous sourcemap: entry2.css 1`] = `"body{font-weight:700;color:red}body a{text-align:center}"`;
3+
exports[`when applied with "sourceMap" option matches snapshot for "false" value, using previous sourcemap: assets 1`] = `
4+
Object {
5+
"entry.css": "body{font-weight:700;color:red}body a{text-align:center}",
6+
"entry2.css": "body{font-weight:700;color:red}body a{text-align:center}",
7+
}
8+
`;
69

7-
exports[`when applied with "sourceMap" option matches snapshot for "false" value, without previous sourcemap: entry.css 1`] = `"body{font-weight:700;color:red}body a{text-align:center}"`;
10+
exports[`when applied with "sourceMap" option matches snapshot for "false" value, using previous sourcemap: errors 1`] = `Array []`;
811

9-
exports[`when applied with "sourceMap" option matches snapshot for "false" value, without previous sourcemap: entry2.css 1`] = `"body{font-weight:700;color:red}body a{text-align:center}"`;
12+
exports[`when applied with "sourceMap" option matches snapshot for "false" value, using previous sourcemap: warnings 1`] = `Array []`;
1013

11-
exports[`when applied with "sourceMap" option matches snapshot for "true" value, using previous sourcemap: entry.css 1`] = `
12-
"body{font-weight:700;color:red}body a{text-align:center}
13-
/*# sourceMappingURL=entry.css.map*/"
14+
exports[`when applied with "sourceMap" option matches snapshot for "false" value, without previous sourcemap: assets 1`] = `
15+
Object {
16+
"entry.css": "body{font-weight:700;color:red}body a{text-align:center}",
17+
"entry2.css": "body{font-weight:700;color:red}body a{text-align:center}",
18+
}
1419
`;
1520

16-
exports[`when applied with "sourceMap" option matches snapshot for "true" value, using previous sourcemap: entry.css.map 1`] = `"{\\"version\\":3,\\"sources\\": [replaced for tests], \\"names\\":[],\\"mappings\\":\\"AAAA,KACE,gBCEA,SDFiB,CCCnB,OAGI,iBAAkB\\",\\"file\\":\\"entry.css\\",\\"sourcesContent\\":[\\"body {\\\\n font-weight: bold;\\\\n}\\",\\"@import 'bar';\\\\n\\\\nbody {\\\\n color: red;\\\\n a {\\\\n text-align: center;\\\\n }\\\\n}\\"],\\"sourceRoot\\":\\"\\"}"`;
21+
exports[`when applied with "sourceMap" option matches snapshot for "false" value, without previous sourcemap: errors 1`] = `Array []`;
22+
23+
exports[`when applied with "sourceMap" option matches snapshot for "false" value, without previous sourcemap: warnings 1`] = `Array []`;
1724

18-
exports[`when applied with "sourceMap" option matches snapshot for "true" value, using previous sourcemap: entry2.css 1`] = `
19-
"body{font-weight:700;color:red}body a{text-align:center}
20-
/*# sourceMappingURL=entry2.css.map*/"
25+
exports[`when applied with "sourceMap" option matches snapshot for "true" value, using previous sourcemap: assets 1`] = `
26+
Object {
27+
"entry.css": "body{font-weight:700;color:red}body a{text-align:center}
28+
/*# sourceMappingURL=entry.css.map*/",
29+
"entry2.css": "body{font-weight:700;color:red}body a{text-align:center}
30+
/*# sourceMappingURL=entry2.css.map*/",
31+
}
2132
`;
2233

34+
exports[`when applied with "sourceMap" option matches snapshot for "true" value, using previous sourcemap: entry.css.map 1`] = `"{\\"version\\":3,\\"sources\\": [replaced for tests], \\"names\\":[],\\"mappings\\":\\"AAAA,KACE,gBCEA,SDFiB,CCCnB,OAGI,iBAAkB\\",\\"file\\":\\"entry.css\\",\\"sourcesContent\\":[\\"body {\\\\n font-weight: bold;\\\\n}\\",\\"@import 'bar';\\\\n\\\\nbody {\\\\n color: red;\\\\n a {\\\\n text-align: center;\\\\n }\\\\n}\\"],\\"sourceRoot\\":\\"\\"}"`;
35+
2336
exports[`when applied with "sourceMap" option matches snapshot for "true" value, using previous sourcemap: entry2.css.map 1`] = `"{\\"version\\":3,\\"sources\\": [replaced for tests], \\"names\\":[],\\"mappings\\":\\"AAAA,KACE,gBCEA,SDFiB,CCGlB,OAGC,iBAAkB\\",\\"file\\":\\"entry2.css\\",\\"sourcesContent\\":[\\"body {\\\\n font-weight: bold;\\\\n}\\",\\"@import 'bar';\\\\n\\\\nbody {\\\\n color: red;\\\\n}\\\\n\\\\nbody a {\\\\n text-align: center;\\\\n}\\"],\\"sourceRoot\\":\\"\\"}"`;
2437

25-
exports[`when applied with "sourceMap" option matches snapshot for "true" value, without previous sourcemap: entry.css 1`] = `
26-
"body{font-weight:700;color:red}body a{text-align:center}
27-
/*# sourceMappingURL=entry.css.map*/"
28-
`;
38+
exports[`when applied with "sourceMap" option matches snapshot for "true" value, using previous sourcemap: errors 1`] = `Array []`;
2939

30-
exports[`when applied with "sourceMap" option matches snapshot for "true" value, without previous sourcemap: entry.css.map 1`] = `"{\\"version\\":3,\\"sources\\": [replaced for tests], \\"names\\":[],\\"mappings\\":\\"AAAA,KACE,gBCEA,SDFiB,CCCnB,OAGI,iBAAkB\\",\\"file\\":\\"entry.css\\",\\"sourcesContent\\":[\\"body {\\\\n font-weight: bold;\\\\n}\\",\\"@import 'bar';\\\\n\\\\nbody {\\\\n color: red;\\\\n a {\\\\n text-align: center;\\\\n }\\\\n}\\"],\\"sourceRoot\\":\\"\\"}"`;
40+
exports[`when applied with "sourceMap" option matches snapshot for "true" value, using previous sourcemap: warnings 1`] = `Array []`;
3141

32-
exports[`when applied with "sourceMap" option matches snapshot for "true" value, without previous sourcemap: entry2.css 1`] = `
33-
"body{font-weight:700;color:red}body a{text-align:center}
34-
/*# sourceMappingURL=entry2.css.map*/"
42+
exports[`when applied with "sourceMap" option matches snapshot for "true" value, without previous sourcemap: assets 1`] = `
43+
Object {
44+
"entry.css": "body{font-weight:700;color:red}body a{text-align:center}
45+
/*# sourceMappingURL=entry.css.map*/",
46+
"entry2.css": "body{font-weight:700;color:red}body a{text-align:center}
47+
/*# sourceMappingURL=entry2.css.map*/",
48+
}
3549
`;
3650

51+
exports[`when applied with "sourceMap" option matches snapshot for "true" value, without previous sourcemap: entry.css.map 1`] = `"{\\"version\\":3,\\"sources\\": [replaced for tests], \\"names\\":[],\\"mappings\\":\\"AAAA,KACE,gBCEA,SDFiB,CCCnB,OAGI,iBAAkB\\",\\"file\\":\\"entry.css\\",\\"sourcesContent\\":[\\"body {\\\\n font-weight: bold;\\\\n}\\",\\"@import 'bar';\\\\n\\\\nbody {\\\\n color: red;\\\\n a {\\\\n text-align: center;\\\\n }\\\\n}\\"],\\"sourceRoot\\":\\"\\"}"`;
52+
3753
exports[`when applied with "sourceMap" option matches snapshot for "true" value, without previous sourcemap: entry2.css.map 1`] = `"{\\"version\\":3,\\"sources\\": [replaced for tests], \\"names\\":[],\\"mappings\\":\\"AAAA,KACE,gBCEA,SDFiB,CCGlB,OAGC,iBAAkB\\",\\"file\\":\\"entry2.css\\",\\"sourcesContent\\":[\\"body {\\\\n font-weight: bold;\\\\n}\\",\\"@import 'bar';\\\\n\\\\nbody {\\\\n color: red;\\\\n}\\\\n\\\\nbody a {\\\\n text-align: center;\\\\n}\\"],\\"sourceRoot\\":\\"\\"}"`;
3854

39-
exports[`when applied with "sourceMap" option matches snapshot when using SourceMapDevToolPlugin (with filename, publicPath and fileContext options): dist/entry.css 1`] = `
40-
"body{font-weight:700;color:red}body a{text-align:center}
41-
/*# sourceMappingURL=https://example.com/project/sourcemaps/entry.css.map*/"
42-
`;
55+
exports[`when applied with "sourceMap" option matches snapshot for "true" value, without previous sourcemap: errors 1`] = `Array []`;
4356

44-
exports[`when applied with "sourceMap" option matches snapshot when using SourceMapDevToolPlugin (with filename, publicPath and fileContext options): dist/entry2.css 1`] = `
45-
"body{font-weight:700;color:red}body a{text-align:center}
46-
/*# sourceMappingURL=https://example.com/project/sourcemaps/entry2.css.map*/"
57+
exports[`when applied with "sourceMap" option matches snapshot for "true" value, without previous sourcemap: warnings 1`] = `Array []`;
58+
59+
exports[`when applied with "sourceMap" option matches snapshot when using SourceMapDevToolPlugin (with filename, publicPath and fileContext options): assets 1`] = `
60+
Object {
61+
"dist/entry.css": "body{font-weight:700;color:red}body a{text-align:center}
62+
/*# sourceMappingURL=https://example.com/project/sourcemaps/entry.css.map*/",
63+
"dist/entry2.css": "body{font-weight:700;color:red}body a{text-align:center}
64+
/*# sourceMappingURL=https://example.com/project/sourcemaps/entry2.css.map*/",
65+
}
4766
`;
4867

49-
exports[`when applied with "sourceMap" option matches snapshot when using SourceMapDevToolPlugin (with filename, publicPath and fileContext options): sourcemaps/entry.css.map 1`] = `"{\\"version\\":3,\\"sources\\":[\\"webpack:///./test/fixtures/sourcemap/bar.scss\\",\\"webpack:///./test/fixtures/sourcemap/foo.scss\\"],\\"names\\":[],\\"mappings\\":\\"AAAA,KACE,gBCEA,SDFiB,CCCnB,OAGI,iBAAkB\\",\\"file\\":\\"dist/entry.css\\",\\"sourcesContent\\":[\\"body {\\\\n font-weight: bold;\\\\n}\\",\\"@import 'bar';\\\\n\\\\nbody {\\\\n color: red;\\\\n a {\\\\n text-align: center;\\\\n }\\\\n}\\"],\\"sourceRoot\\":\\"\\"}"`;
68+
exports[`when applied with "sourceMap" option matches snapshot when using SourceMapDevToolPlugin (with filename, publicPath and fileContext options): errors 1`] = `Array []`;
69+
70+
exports[`when applied with "sourceMap" option matches snapshot when using SourceMapDevToolPlugin (with filename, publicPath and fileContext options): sourcemaps/entry.css.map 1`] = `"{\\"version\\":3,\\"sources\\": [replaced for tests], \\"names\\":[],\\"mappings\\":\\"AAAA,KACE,gBCEA,SDFiB,CCCnB,OAGI,iBAAkB\\",\\"file\\":\\"dist/entry.css\\",\\"sourcesContent\\":[\\"body {\\\\n font-weight: bold;\\\\n}\\",\\"@import 'bar';\\\\n\\\\nbody {\\\\n color: red;\\\\n a {\\\\n text-align: center;\\\\n }\\\\n}\\"],\\"sourceRoot\\":\\"\\"}"`;
71+
72+
exports[`when applied with "sourceMap" option matches snapshot when using SourceMapDevToolPlugin (with filename, publicPath and fileContext options): sourcemaps/entry2.css.map 1`] = `"{\\"version\\":3,\\"sources\\": [replaced for tests], \\"names\\":[],\\"mappings\\":\\"AAAA,KACE,gBCEA,SDFiB,CCGlB,OAGC,iBAAkB\\",\\"file\\":\\"dist/entry2.css\\",\\"sourcesContent\\":[\\"body {\\\\n font-weight: bold;\\\\n}\\",\\"@import 'bar';\\\\n\\\\nbody {\\\\n color: red;\\\\n}\\\\n\\\\nbody a {\\\\n text-align: center;\\\\n}\\"],\\"sourceRoot\\":\\"\\"}"`;
5073

51-
exports[`when applied with "sourceMap" option matches snapshot when using SourceMapDevToolPlugin (with filename, publicPath and fileContext options): sourcemaps/entry2.css.map 1`] = `"{\\"version\\":3,\\"sources\\":[\\"webpack:///./test/fixtures/sourcemap/bar.scss\\",\\"webpack:///./test/fixtures/sourcemap/foo.css\\"],\\"names\\":[],\\"mappings\\":\\"AAAA,KACE,gBCEA,SDFiB,CCGlB,OAGC,iBAAkB\\",\\"file\\":\\"dist/entry2.css\\",\\"sourcesContent\\":[\\"body {\\\\n font-weight: bold;\\\\n}\\",\\"@import 'bar';\\\\n\\\\nbody {\\\\n color: red;\\\\n}\\\\n\\\\nbody a {\\\\n text-align: center;\\\\n}\\"],\\"sourceRoot\\":\\"\\"}"`;
74+
exports[`when applied with "sourceMap" option matches snapshot when using SourceMapDevToolPlugin (with filename, publicPath and fileContext options): warnings 1`] = `Array []`;
5275

53-
exports[`when applied with "sourceMap" option should emit warning when broken sourcemap: error 1`] = `
76+
exports[`when applied with "sourceMap" option should emit warning when broken sourcemap: errors 1`] = `
5477
Array [
5578
"Error: broken-source-map.css from Css Minimizer
5679
Error: \\"version\\" is a required argument.",
@@ -59,7 +82,7 @@ Error: broken-source-map.css from Css Minimizer",
5982
]
6083
`;
6184

62-
exports[`when applied with "sourceMap" option should emit warning when broken sourcemap: warning 1`] = `
85+
exports[`when applied with "sourceMap" option should emit warning when broken sourcemap: warnings 1`] = `
6386
Array [
6487
"Error: broken-source-map.css contains invalid source map",
6588
]

0 commit comments

Comments
 (0)