forked from webpack/webpack-dev-server
-
Notifications
You must be signed in to change notification settings - Fork 1
/
updateOptions.test.js
75 lines (70 loc) · 1.97 KB
/
updateOptions.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
'use strict';
const webpack = require('webpack');
const updateOptions = require('../../../lib/utils/updateOptions');
describe('updateOptions', () => {
const cases = [
{
title: 'no options',
multiCompiler: false,
options: {},
optionsResults: null,
},
{
title: 'contentBase string',
multiCompiler: false,
options: {
contentBase: '/path/to/dist',
},
optionsResults: null,
},
{
title: 'contentBase array',
multiCompiler: false,
options: {
contentBase: ['/path/to/dist1', '/path/to/dist2'],
},
optionsResults: null,
},
{
title: 'watchOptions',
multiCompiler: false,
options: {
watchOptions: {
poll: true,
},
},
optionsResults: null,
},
];
cases.forEach((data) => {
describe(data.title, () => {
let compiler;
beforeAll(() => {
let webpackConfig;
if (data.multiCompiler) {
// eslint-disable-next-line global-require
webpackConfig = require('../../fixtures/multi-compiler-config/webpack.config');
} else {
// eslint-disable-next-line global-require
webpackConfig = require('../../fixtures/simple-config/webpack.config');
}
compiler = webpack(webpackConfig);
});
it('should set correct options', () => {
const originalContentBase = data.options.contentBase;
updateOptions(compiler, data.options);
if (data.optionsResults) {
expect(data.options).toEqual(data.optionsResults);
} else {
if (data.options.contentBase !== originalContentBase) {
// we don't want this in the snapshot, because it is
// the current working directory
expect(data.options.contentBase).toEqual(process.cwd());
delete data.options.contentBase;
}
expect(data.options).toMatchSnapshot();
}
});
});
});
});