-
Notifications
You must be signed in to change notification settings - Fork 80
Expand file tree
/
Copy pathindex.test.js
More file actions
146 lines (121 loc) · 4.01 KB
/
index.test.js
File metadata and controls
146 lines (121 loc) · 4.01 KB
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
const { describe, expect, it } = require("bun:test");
const SpeedMeasurePlugin = require("./index");
class IncludedPlugin {
apply() {}
}
class ExcludedPlugin {
apply() {}
}
class IncludedMinimizer {
apply() {}
}
class ExcludedMinimizer {
apply() {}
}
describe("wrap", () => {
it("should exclude named plugins and minimizers from wrapping", () => {
const includedPlugin = new IncludedPlugin();
const excludedPlugin = new ExcludedPlugin();
const includedMinimizer = new IncludedMinimizer();
const excludedMinimizer = new ExcludedMinimizer();
const smp = new SpeedMeasurePlugin({
excludedPlugins: ["ExcludedPlugin", "ExcludedMinimizer"],
});
const wrappedConfig = smp.wrap({
plugins: [includedPlugin, excludedPlugin],
optimization: {
minimizer: [includedMinimizer, excludedMinimizer],
},
});
expect(wrappedConfig.plugins[0]).not.toBe(includedPlugin);
expect(wrappedConfig.plugins[1]).toBe(excludedPlugin);
expect(wrappedConfig.optimization.minimizer[0]).not.toBe(includedMinimizer);
expect(wrappedConfig.optimization.minimizer[1]).toBe(excludedMinimizer);
});
it("should allow excluding plugins by constructor", () => {
const includedPlugin = new IncludedPlugin();
const excludedPlugin = new ExcludedPlugin();
const smp = new SpeedMeasurePlugin({
excludedPlugins: [ExcludedPlugin],
});
const wrappedConfig = smp.wrap({
plugins: [includedPlugin, excludedPlugin],
});
expect(wrappedConfig.plugins[0]).not.toBe(includedPlugin);
expect(wrappedConfig.plugins[1]).toBe(excludedPlugin);
});
it("should allow excluding plugins by regex", () => {
const includedPlugin = new IncludedPlugin();
const excludedPlugin = new ExcludedPlugin();
const smp = new SpeedMeasurePlugin({
excludedPlugins: [/Excluded/],
});
const wrappedConfig = smp.wrap({
plugins: [includedPlugin, excludedPlugin],
});
expect(wrappedConfig.plugins[0]).not.toBe(includedPlugin);
expect(wrappedConfig.plugins[1]).toBe(excludedPlugin);
});
it("should allow excluding plugins by custom pluginNames alias", () => {
const aliasedPlugin = new ExcludedPlugin();
const smp = new SpeedMeasurePlugin({
pluginNames: {
customPluginName: aliasedPlugin,
},
excludedPlugins: ["customPluginName"],
});
const wrappedConfig = smp.wrap({
plugins: [aliasedPlugin],
});
expect(wrappedConfig.plugins[0]).toBe(aliasedPlugin);
});
it("should skip injecting granular timing for excluded loaders by name", () => {
const smp = new SpeedMeasurePlugin({
granularLoaderData: true,
excludedLoaders: ["babel-loader"],
});
const wrappedConfig = smp.wrap({
module: {
rules: [{ use: ["babel-loader"] }, { use: ["file-loader"] }],
},
});
expect(wrappedConfig.module.rules[0].use).toEqual(["babel-loader"]);
expect(wrappedConfig.module.rules[1].use).toEqual([
"speed-measure-webpack-plugin/loader",
"file-loader",
]);
});
it("should skip injecting granular timing for excluded loaders by regex", () => {
const smp = new SpeedMeasurePlugin({
granularLoaderData: true,
excludedLoaders: [/css-loader/],
});
const wrappedConfig = smp.wrap({
module: {
rules: [
{
use: ["style-loader", "/tmp/node_modules/css-loader/dist/cjs.js"],
},
{ use: ["file-loader"] },
],
},
});
expect(wrappedConfig.module.rules[1].use).toEqual([
"speed-measure-webpack-plugin/loader",
"file-loader",
]);
expect(wrappedConfig.module.rules[0].use).toEqual([
"style-loader",
"/tmp/node_modules/css-loader/dist/cjs.js",
]);
});
it('should leave the webpack 5 "..." minimizer sentinel untouched', () => {
const smp = new SpeedMeasurePlugin();
const wrappedConfig = smp.wrap({
optimization: {
minimizer: ["..."],
},
});
expect(wrappedConfig.optimization.minimizer).toEqual(["..."]);
});
});