/
resolveConfig.test.js
58 lines (52 loc) · 2.46 KB
/
resolveConfig.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
const resolveConfig = require('../../lib/groups/resolveConfig.js');
const { resolve } = require('path');
const config1 = require('./webpack.config1.cjs');
const config2 = require('./webpack.config2.cjs');
const arrayConfig = require('./webpack.config.cjs');
const promiseConfig = require('./webpack.promise.config.cjs');
describe('resolveConfig', function () {
it('should handle merge properly', async () => {
const result = await resolveConfig({
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);
expect(result.outputOptions).toEqual({});
});
it('should return array for multiple config', async () => {
const result = await resolveConfig({
config: [resolve(__dirname, './webpack.config1.cjs'), resolve(__dirname, './webpack.config2.cjs')],
});
const expectedOptions = [config1, config2];
expect(result.options).toEqual(expectedOptions);
expect(result.outputOptions).toEqual({});
});
it('should return config object for single config', async () => {
const result = await resolveConfig({ config: [resolve(__dirname, './webpack.config1.cjs')] });
expect(result.options).toEqual(config1);
expect(result.outputOptions).toEqual({});
});
it('should return resolved config object for promise config', async () => {
const result = await resolveConfig({ config: [resolve(__dirname, './webpack.promise.config.cjs')] });
const expectedOptions = await promiseConfig();
expect(result.options).toEqual(expectedOptions);
expect(result.outputOptions).toEqual({});
});
it('should handle configs returning different types', async () => {
const result = await resolveConfig({
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);
expect(result.outputOptions).toEqual({});
});
});