Skip to content

Commit

Permalink
tests: --config-name
Browse files Browse the repository at this point in the history
  • Loading branch information
snitin315 committed Aug 18, 2020
1 parent 3845ef1 commit a0ca62c
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/webpack-cli/lib/groups/ConfigGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class ConfigGroup extends GroupHelper {
} else if (Array.isArray(configOptions) && this.args.configName) {
const namedOption = configOptions.filter((opt) => this.args.configName.includes(opt.name));
if (namedOption.length === 0) {
logger.error(`Configuration with name ${this.args.configName} was not found.`);
logger.error(`Configuration with name "${this.args.configName}" was not found.`);
process.exit(1);
} else {
newOptionsObject['options'] = namedOption;
Expand Down
45 changes: 45 additions & 0 deletions test/config-name/config-name.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
'use strict';
const { run } = require('../utils/test-utils');
const { stat } = require('fs');
const { resolve } = require('path');

describe('--config-name flag', () => {
it('should select only the config whose name is passed with --config-name', (done) => {
const { stderr, stdout } = run(__dirname, ['--config-name', 'first'], false);
expect(stderr).toBeFalsy();
expect(stdout).toContain('Child first');
expect(stdout).not.toContain('Child second');
expect(stdout).not.toContain('Child third');

stat(resolve(__dirname, './dist/dist-first.js'), (err, stats) => {
expect(err).toBe(null);
expect(stats.isFile()).toBe(true);
done();
});
});

it('should work with multiple values for --config-name', (done) => {
const { stderr, stdout } = run(__dirname, ['--config-name', 'first', '--config-name', 'third'], false);
expect(stderr).toBeFalsy();
expect(stdout).toContain('Child first');
expect(stdout).not.toContain('Child second');
expect(stdout).toContain('Child third');

stat(resolve(__dirname, './dist/dist-first.js'), (err, stats) => {
expect(err).toBe(null);
expect(stats.isFile()).toBe(true);
done();
});
stat(resolve(__dirname, './dist/dist-third.js'), (err, stats) => {
expect(err).toBe(null);
expect(stats.isFile()).toBe(true);
done();
});
});

it('should log error if invalid config name is provided', () => {
const { stderr, stdout } = run(__dirname, ['--config-name', 'test'], false);
expect(stderr).toContain('Configuration with name test was not found.');
expect(stdout).toBeFalsy();
});
});
1 change: 1 addition & 0 deletions test/config-name/src/first.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('first config');
1 change: 1 addition & 0 deletions test/config-name/src/second.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('second config');
1 change: 1 addition & 0 deletions test/config-name/src/third.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('third config');
26 changes: 26 additions & 0 deletions test/config-name/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module.exports = [
{
output: {
filename: './dist-first.js',
},
name: 'first',
entry: './src/first.js',
mode: 'development',
},
{
output: {
filename: './dist-second.js',
},
name: 'second',
entry: './src/second.js',
mode: 'production',
},
{
output: {
filename: './dist-third.js',
},
name: 'third',
entry: './src/third.js',
mode: 'none',
},
];

0 comments on commit a0ca62c

Please sign in to comment.