Skip to content

Commit

Permalink
test: improve tests for --merge (#2399)
Browse files Browse the repository at this point in the history
  • Loading branch information
snitin315 authored Feb 2, 2021
1 parent ad1a6b8 commit b50d71b
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 8 deletions.
8 changes: 6 additions & 2 deletions test/merge/config/1.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
const WebpackCLITestPlugin = require('../../utils/webpack-cli-test-plugin');

module.exports = {
entry: './old_entry.js',
entry: './first-entry.js',
mode: 'development',
output: {
filename: 'badfile.js',
filename: 'first-output.js',
},
plugins: [new WebpackCLITestPlugin()],
};
5 changes: 3 additions & 2 deletions test/merge/config/2.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module.exports = {
entry: './some_entry.js',
entry: './second-entry.js',
target: 'node',
output: {
filename: 'merged.js',
filename: 'second-output.js',
},
};
6 changes: 6 additions & 0 deletions test/merge/config/3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
entry: './third-entry.js',
output: {
filename: 'third-output.js',
},
};
1 change: 1 addition & 0 deletions test/merge/config/first-entry.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('first');
22 changes: 19 additions & 3 deletions test/merge/config/merge-config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,35 @@ describe('merge flag configuration', () => {

expect(exitCode).toBe(0);
expect(stderr).toBeFalsy();
expect(stdout).toContain('option has not been set, webpack will fallback to');
expect(stdout).toContain('WebpackCLITestPlugin'); // from 1.js
expect(stdout).toContain('second-output.js'); // from 2.js
});

it('merges more than two configurations together', () => {
const { exitCode, stderr, stdout } = run(
__dirname,
['--config', './1.js', '--config', './2.js', '--config', './3.js', '--merge'],
false,
);

expect(exitCode).toBe(0);
expect(stderr).toBeFalsy();
expect(stdout).toContain('WebpackCLITestPlugin'); // from 1.js
expect(stdout).toContain("target: 'node'"); // from 2.js
expect(stdout).toContain('third-output.js'); // from 3.js
});

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

expect(exitCode).toBe(0);
expect(stderr).toBeFalsy();
expect(stdout).toContain('merged.js');
expect(stdout).toContain('WebpackCLITestPlugin'); // from 1.js
expect(stdout).toContain('second-output.js'); // from 2.js
});

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

expect(exitCode).toBe(2);
expect(stderr).toContain('At least two configurations are required for merge.');
Expand Down
1 change: 1 addition & 0 deletions test/merge/config/second-entry.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('second');
1 change: 0 additions & 1 deletion test/merge/config/some_entry.js

This file was deleted.

1 change: 1 addition & 0 deletions test/merge/config/third-entry.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('third');

0 comments on commit b50d71b

Please sign in to comment.