-
-
Notifications
You must be signed in to change notification settings - Fork 591
/
resolveArgs.test.js
142 lines (120 loc) · 4.54 KB
/
resolveArgs.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
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
const { resolve } = require('path');
const webpackCLI = require('../lib/webpack-cli');
const targetValues = ['web', 'webworker', 'node', 'async-node', 'node-webkit', 'electron-main', 'electron-renderer', 'electron-preload'];
const basicResolver = new webpackCLI().resolveArgs;
describe('BasicResolver', () => {
it('should handle the output option', async () => {
const result = await basicResolver({
outputPath: './bundle',
});
expect(result.options.output.path).toEqual(resolve('bundle'));
});
it('should handle the mode option [production]', async () => {
const result = await basicResolver(
{
mode: 'production',
},
{},
);
// ensure no other properties are added
expect(result.options).toMatchObject({ mode: 'production' });
expect(result.options.mode).toEqual('production');
});
it('should handle the mode option [development]', async () => {
const result = await basicResolver(
{
mode: 'development',
},
{},
);
// ensure no other properties are added
expect(result.options).toMatchObject({ mode: 'development' });
expect(result.options.mode).toEqual('development');
});
it('should handle the mode option [none]', async () => {
const result = await basicResolver(
{
mode: 'none',
},
{},
);
// ensure no other properties are added
expect(result.options).toMatchObject({ mode: 'none' });
expect(result.options.mode).toEqual('none');
});
it('should prefer supplied move flag over NODE_ENV', async () => {
process.env.NODE_ENV = 'production';
const result = await basicResolver(
{
mode: 'development',
},
{},
);
// ensure no other properties are added
expect(result.options).toMatchObject({ mode: 'development' });
});
it('should prefer supplied move flag over mode from config', async () => {
const result = await basicResolver(
{
mode: 'development',
},
{ mode: 'production' },
);
// ensure no other properties are added
expect(result.options).toMatchObject({ mode: 'development' });
});
it('should prefer mode form config over NODE_ENV', async () => {
process.env.NODE_ENV = 'development';
const result = await basicResolver({}, { mode: 'production' });
// ensure no other properties are added
expect(result.options).toMatchObject({ mode: 'production' });
});
it('should prefer mode form flag over NODE_ENV and config', async () => {
process.env.NODE_ENV = 'development';
const result = await basicResolver({ mode: 'none' }, { mode: 'production' });
// ensure no other properties are added
expect(result.options).toMatchObject({ mode: 'none' });
});
it('should assign json correctly', async () => {
const result = await basicResolver({
json: true,
});
expect(result.options.stats).toBeFalsy();
expect(result.outputOptions.json).toBeTruthy();
});
it('should assign stats correctly', async () => {
const result = await basicResolver({
stats: 'warning',
});
expect(result.options.stats).toEqual('warning');
expect(result.outputOptions.json).toBeFalsy();
});
it('should load the HMR plugin', async () => {
const result = await basicResolver({
hot: true,
});
expect(result.options.plugins[0].constructor.name).toEqual('HotModuleReplacementPlugin');
});
it('should load the prefetch plugin', async () => {
const result = await basicResolver({
prefetch: 'url',
});
expect(result.options.plugins[0].constructor.name).toEqual('PrefetchPlugin');
});
it('should load the webpack-bundle-analyzer plugin', async () => {
const result = await basicResolver({
analyze: true,
});
expect(result.options.plugins[0].constructor.name).toEqual('BundleAnalyzerPlugin');
});
{
targetValues.map((option) => {
it(`should handle ${option} option`, async () => {
const result = await basicResolver({
target: option,
});
expect(result.options.target).toEqual(option);
});
});
}
});