This repository was archived by the owner on Dec 5, 2019. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 179
/
Copy pathsupports-multicompiler.test.js
102 lines (90 loc) · 2.97 KB
/
supports-multicompiler.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import MultiCompiler from 'webpack/lib/MultiCompiler';
import MultiStats from 'webpack/lib/MultiStats';
import UglifyJsPlugin from '../src/index';
import {
cleanErrorStack,
createCompiler,
countPlugins,
compile,
} from './helpers';
describe('when using MultiCompiler', () => {
it('matches snapshot with empty options', () => {
const multiCompiler = createCompiler([
{
mode: 'production',
bail: true,
cache: false,
entry: `${__dirname}/fixtures/entry.js`,
output: {
path: `${__dirname}/dist`,
filename: '[name].[chunkhash].js',
chunkFilename: '[id].[name].[chunkhash].js',
},
optimization: {
minimize: false,
},
},
{
mode: 'production',
bail: true,
cache: false,
entry: `${__dirname}/fixtures/entry.js`,
output: {
path: `${__dirname}/dist`,
filename: '[name].[chunkhash].js',
chunkFilename: '[id].[name].[chunkhash].js',
},
optimization: {
minimize: false,
},
plugins: [new UglifyJsPlugin()],
},
{
mode: 'production',
bail: true,
cache: false,
entry: `${__dirname}/fixtures/import-export/entry.js`,
output: {
path: `${__dirname}/dist-MultiCompiler`,
filename: '[name].[chunkhash].js',
chunkFilename: '[id].[name].[chunkhash].js',
},
optimization: {
minimize: false,
},
plugins: [new UglifyJsPlugin()],
},
]);
const emptyPluginCount = countPlugins(multiCompiler.compilers[0]);
const expectedPluginCount = countPlugins(multiCompiler.compilers[1]);
expect(emptyPluginCount).not.toEqual(expectedPluginCount);
expect(multiCompiler).toBeInstanceOf(MultiCompiler);
multiCompiler.compilers.slice(2).forEach((compiler) => {
const pluginCount = countPlugins(compiler);
expect(pluginCount).not.toEqual(emptyPluginCount);
expect(pluginCount).toEqual(expectedPluginCount);
expect(pluginCount).toMatchSnapshot('compiler plugin count');
});
expect(multiCompiler).toBeInstanceOf(MultiCompiler);
return compile(multiCompiler).then((multiStats) => {
expect(multiStats).toBeInstanceOf(MultiStats);
multiStats.stats.forEach((stats) => {
const errors = stats.compilation.errors.map(cleanErrorStack);
const warnings = stats.compilation.warnings.map(cleanErrorStack);
expect(errors.length).toEqual(0);
expect(warnings.length).toEqual(0);
expect(errors).toMatchSnapshot('errors');
expect(warnings).toMatchSnapshot('warnings');
for (const file in stats.compilation.assets) {
if (
Object.prototype.hasOwnProperty.call(stats.compilation.assets, file)
) {
expect(stats.compilation.assets[file].source()).toMatchSnapshot(
file
);
}
}
});
});
});
});