-
-
Notifications
You must be signed in to change notification settings - Fork 668
Expand file tree
/
Copy pathresolve-config.test.js
More file actions
83 lines (69 loc) · 2.55 KB
/
resolve-config.test.js
File metadata and controls
83 lines (69 loc) · 2.55 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
const { resolve } = require("node:path");
const WebpackCLI = require("../../../packages/webpack-cli/lib/webpack-cli").default;
const arrayConfig = require("./webpack.config.cjs");
const config1 = require("./webpack.config1.cjs");
const config2 = require("./webpack.config2.cjs");
const promiseConfig = require("./webpack.promise.config.cjs");
const cli = new WebpackCLI();
describe("resolveConfig", () => {
it("should handle merge properly", async () => {
const result = await cli.loadConfig({
merge: true,
config: [resolve(__dirname, "./webpack.config.cjs")],
});
const expectedOptions = {
output: {
filename: "./dist-commonjs.js",
libraryTarget: "commonjs",
},
entry: "./a.js",
name: "amd",
mode: "production",
devtool: "eval-cheap-module-source-map",
target: "node",
};
expect(result.options).toEqual(expectedOptions);
});
it("should return array for multiple config", async () => {
const result = await cli.loadConfig({
config: [
resolve(__dirname, "./webpack.config1.cjs"),
resolve(__dirname, "./webpack.config2.cjs"),
],
});
const expectedOptions = [config1, config2];
expect(result.options).toEqual(expectedOptions);
});
it("should return config object for single config", async () => {
const result = await cli.loadConfig({
config: [resolve(__dirname, "./webpack.config1.cjs")],
});
expect(result.options).toEqual(config1);
});
it("should return resolved config object for promise config", async () => {
const result = await cli.loadConfig({
config: [resolve(__dirname, "./webpack.promise.config.cjs")],
});
const expectedOptions = await promiseConfig();
expect(result.options).toEqual(expectedOptions);
});
it("should handle configs returning different types", async () => {
const result = await cli.loadConfig({
config: [
resolve(__dirname, "./webpack.promise.config.cjs"),
resolve(__dirname, "./webpack.config.cjs"),
],
});
const resolvedPromiseConfig = await promiseConfig();
const expectedOptions = [resolvedPromiseConfig, ...arrayConfig];
expect(result.options).toEqual(expectedOptions);
});
it("should handle different env formats", async () => {
const result = await cli.loadConfig({
argv: { env: { test: true, name: "Hisoka" } },
config: [resolve(__dirname, "./env.webpack.config.cjs")],
});
const expectedOptions = { mode: "staging", name: "Hisoka" };
expect(result.options).toEqual(expectedOptions);
});
});