-
Notifications
You must be signed in to change notification settings - Fork 2
/
test.js
111 lines (90 loc) · 2.98 KB
/
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
106
107
108
109
110
111
const ModuleDependencyWarning = require('webpack/lib/ModuleDependencyWarning');
const IgnoreNotFoundExportPlugin = require('.');
const [tsWarning, jsWarning, tsxWarning, jsxWarning] = [
new ModuleDependencyWarning(
{ resource: '/demo/project/lib/test.ts' },
new Error(
"export 'default' (reexported as 'Test') was not found in './test'",
),
),
new ModuleDependencyWarning(
{ resource: '/demo/project/lib/test2.js' },
new Error(
"export 'default' (reexported as 'Test') was not found in './test2'",
),
),
new ModuleDependencyWarning(
{ resource: '/demo/project/components/Component.tsx' },
new Error("export 'Component' was not found in 'components/Component'"),
),
new ModuleDependencyWarning(
{ resource: '/demo/project/components/Component2.jsx' },
new Error("export 'Component' was not found in 'components/Component2'"),
),
];
test('it throws if provided argument is not a RegExp', () => {
expect(() => {
new IgnoreNotFoundExportPlugin({ include: 123 });
}).toThrow(TypeError);
expect(() => {
new IgnoreNotFoundExportPlugin({ include: [123] });
}).toThrow(TypeError);
expect(() => {
new IgnoreNotFoundExportPlugin();
}).not.toThrow();
expect(() => {
new IgnoreNotFoundExportPlugin({ include: [] });
}).not.toThrow();
expect(() => {
new IgnoreNotFoundExportPlugin({ include: [/\.tsx?$/] });
}).not.toThrow();
});
test('it filters out all compiler warnings by default', () => {
const expectedWarnings = [];
const warnings = [tsWarning, jsWarning, tsxWarning, jsxWarning];
const stats = mockStats(warnings);
const compiler = mockCompiler(stats);
const plugin = new IgnoreNotFoundExportPlugin();
plugin.apply(compiler);
expect(stats.compilation.warnings).toEqual(expectedWarnings);
});
test('it filters out all compiler warnings where path matches the given include regular expression', () => {
const expectedWarnings = [jsWarning, jsxWarning, tsxWarning];
const warnings = [...expectedWarnings, tsWarning];
const stats = mockStats(warnings);
const compiler = mockCompiler(stats);
const plugin = new IgnoreNotFoundExportPlugin({
include: /\.ts$/,
});
plugin.apply(compiler);
expect(stats.compilation.warnings).toEqual(expectedWarnings);
});
test('it filters out all compiler warnings where path matches any of the given include regular expressions', () => {
const expectedWarnings = [jsxWarning, tsxWarning];
const warnings = [...expectedWarnings, jsWarning, tsWarning];
const stats = mockStats(warnings);
const compiler = mockCompiler(stats);
const plugin = new IgnoreNotFoundExportPlugin({
include: [/\.js$/, /\.ts$/],
});
plugin.apply(compiler);
expect(stats.compilation.warnings).toEqual(expectedWarnings);
});
function mockStats(warnings) {
return {
compilation: {
warnings,
},
};
}
function mockCompiler(stats) {
return {
hooks: {
done: {
tap: (_name, callback) => {
callback(stats);
},
},
},
};
}