Skip to content

Commit b50d71b

Browse files
authored
test: improve tests for --merge (#2399)
1 parent ad1a6b8 commit b50d71b

File tree

8 files changed

+37
-8
lines changed

8 files changed

+37
-8
lines changed

test/merge/config/1.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1+
const WebpackCLITestPlugin = require('../../utils/webpack-cli-test-plugin');
2+
13
module.exports = {
2-
entry: './old_entry.js',
4+
entry: './first-entry.js',
5+
mode: 'development',
36
output: {
4-
filename: 'badfile.js',
7+
filename: 'first-output.js',
58
},
9+
plugins: [new WebpackCLITestPlugin()],
610
};

test/merge/config/2.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module.exports = {
2-
entry: './some_entry.js',
2+
entry: './second-entry.js',
3+
target: 'node',
34
output: {
4-
filename: 'merged.js',
5+
filename: 'second-output.js',
56
},
67
};

test/merge/config/3.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
entry: './third-entry.js',
3+
output: {
4+
filename: 'third-output.js',
5+
},
6+
};

test/merge/config/first-entry.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log('first');

test/merge/config/merge-config.test.js

+19-3
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,35 @@ describe('merge flag configuration', () => {
88

99
expect(exitCode).toBe(0);
1010
expect(stderr).toBeFalsy();
11-
expect(stdout).toContain('option has not been set, webpack will fallback to');
11+
expect(stdout).toContain('WebpackCLITestPlugin'); // from 1.js
12+
expect(stdout).toContain('second-output.js'); // from 2.js
13+
});
14+
15+
it('merges more than two configurations together', () => {
16+
const { exitCode, stderr, stdout } = run(
17+
__dirname,
18+
['--config', './1.js', '--config', './2.js', '--config', './3.js', '--merge'],
19+
false,
20+
);
21+
22+
expect(exitCode).toBe(0);
23+
expect(stderr).toBeFalsy();
24+
expect(stdout).toContain('WebpackCLITestPlugin'); // from 1.js
25+
expect(stdout).toContain("target: 'node'"); // from 2.js
26+
expect(stdout).toContain('third-output.js'); // from 3.js
1227
});
1328

1429
it('merges two configurations together with flag alias', () => {
1530
const { exitCode, stderr, stdout } = run(__dirname, ['--config', './1.js', '--config', './2.js', '-m'], false);
1631

1732
expect(exitCode).toBe(0);
1833
expect(stderr).toBeFalsy();
19-
expect(stdout).toContain('merged.js');
34+
expect(stdout).toContain('WebpackCLITestPlugin'); // from 1.js
35+
expect(stdout).toContain('second-output.js'); // from 2.js
2036
});
2137

2238
it('fails when there are less than 2 configurations to merge', () => {
23-
const { exitCode, stderr, stdout } = run(__dirname, ['--config', './1.js', '-m'], false);
39+
const { exitCode, stderr, stdout } = run(__dirname, ['--config', './1.js', '--merge'], false);
2440

2541
expect(exitCode).toBe(2);
2642
expect(stderr).toContain('At least two configurations are required for merge.');

test/merge/config/second-entry.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log('second');

test/merge/config/some_entry.js

-1
This file was deleted.

test/merge/config/third-entry.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log('third');

0 commit comments

Comments
 (0)