-
-
Notifications
You must be signed in to change notification settings - Fork 158
/
Copy pathexclude-option.test.js
105 lines (86 loc) · 3.24 KB
/
exclude-option.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
103
104
105
import TerserPlugin from '../src/index';
import { cleanErrorStack, createCompiler, compile } from './helpers';
describe('when applied with `exclude` option', () => {
let compiler;
beforeEach(() => {
compiler = createCompiler({
entry: {
excluded1: `${__dirname}/fixtures/excluded1.js`,
excluded2: `${__dirname}/fixtures/excluded2.js`,
entry: `${__dirname}/fixtures/entry.js`,
},
});
});
it('matches snapshot for a single `exclude` value ({RegExp})', () => {
new TerserPlugin({
exclude: /excluded1/i,
}).apply(compiler);
return compile(compiler).then((stats) => {
const errors = stats.compilation.errors.map(cleanErrorStack);
const warnings = stats.compilation.warnings.map(cleanErrorStack);
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);
}
}
});
});
it('matches snapshot for a single `exclude` value ({String})', () => {
new TerserPlugin({
exclude: 'excluded1',
}).apply(compiler);
return compile(compiler).then((stats) => {
const errors = stats.compilation.errors.map(cleanErrorStack);
const warnings = stats.compilation.warnings.map(cleanErrorStack);
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);
}
}
});
});
it('matches snapshot for multiple `exclude` values ({RegExp})', () => {
new TerserPlugin({
exclude: [/excluded1/i, /excluded2/i],
}).apply(compiler);
return compile(compiler).then((stats) => {
const errors = stats.compilation.errors.map(cleanErrorStack);
const warnings = stats.compilation.warnings.map(cleanErrorStack);
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);
}
}
});
});
it('matches snapshot for multiple `exclude` values ({String})', () => {
new TerserPlugin({
exclude: ['excluded1', 'excluded2'],
}).apply(compiler);
return compile(compiler).then((stats) => {
const errors = stats.compilation.errors.map(cleanErrorStack);
const warnings = stats.compilation.warnings.map(cleanErrorStack);
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);
}
}
});
});
});