Skip to content

Commit

Permalink
chore: fix no-mode tests
Browse files Browse the repository at this point in the history
  • Loading branch information
knagaitsev committed Apr 18, 2020
1 parent 499ac4e commit ca94729
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 15 deletions.
3 changes: 2 additions & 1 deletion packages/webpack-cli/lib/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ async function runCLI(cli, commandIsUsed) {
cliExecuter();
return;
}
const result = await cli.run(parsedArgs.opts(), core);
const parsedArgsOpts = parsedArgs.opts();
const result = await cli.run(parsedArgsOpts, core);
if (!result) {
return;
}
Expand Down
6 changes: 4 additions & 2 deletions packages/webpack-cli/lib/groups/ZeroConfigGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ class ZeroConfigGroup extends GroupHelper {
if (process.env.NODE_ENV && (process.env.NODE_ENV === PRODUCTION || process.env.NODE_ENV === DEVELOPMENT)) {
return process.env.NODE_ENV;
} else {
if (this.args.mode !== undefined && (this.args.dev || this.args.prod)) {
// commander sets mode to false if --no-mode is specified
const noMode = this.args.mode === false;
if ((this.args.mode || noMode) && (this.args.dev || this.args.prod)) {
logger.warn(
`You provided both ${this.args.mode ? 'mode' : 'no-mode'} and ${
this.args.prod ? '--prod' : '--dev'
Expand All @@ -44,7 +46,7 @@ class ZeroConfigGroup extends GroupHelper {
return PRODUCTION;
} else if (this.args.dev) {
return DEVELOPMENT;
} else if (this.args.noMode) {
} else if (noMode) {
return NONE;
}
return PRODUCTION;
Expand Down
18 changes: 9 additions & 9 deletions packages/webpack-cli/lib/utils/cli-flags.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,20 +222,20 @@ module.exports = {
},
{
name: 'mode',
usage: '--mode <development | production>',
usage: '--mode <development | production | none>',
type: String,
group: ZERO_CONFIG_GROUP,
description: 'Defines the mode to pass to webpack',
link: 'https://webpack.js.org/concepts/#mode',
},
// {
// name: 'no-mode',
// usage: '--no-mode',
// type: Boolean,
// group: ZERO_CONFIG_GROUP,
// description: 'Sets mode="none" which disables any default behavior',
// link: 'https://webpack.js.org/concepts/#mode',
// },
{
name: 'no-mode',
usage: '--no-mode',
type: Boolean,
group: ZERO_CONFIG_GROUP,
description: 'Sets mode="none" which disables any default behavior',
link: 'https://webpack.js.org/concepts/#mode',
},
{
name: 'version',
usage: '--version | --version <external-package>',
Expand Down
8 changes: 5 additions & 3 deletions test/no-mode/no-mode.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ describe('no-mode flag', () => {
});
});

it('should load a production config when --mode=production & --no-mode are passed', (done) => {
it('should load a none config when --mode=production is passed before --no-mode', (done) => {
const { stderr, stdout } = run(__dirname, ['--mode', 'production', '--no-mode']);
expect(stderr).toBeFalsy();
expect(stdout).toBeTruthy();
expect(stdout).not.toContain('main.js.map');

stat(resolve(__dirname, './bin/main.js'), (err, stats) => {
expect(err).toBe(null);
Expand All @@ -50,10 +51,11 @@ describe('no-mode flag', () => {
});
});

it('should load a development config when --mode=development and --no-mode are passed', (done) => {
const { stderr, stdout } = run(__dirname, ['--mode', 'development', '--no-mode']);
it('should load a none config when --mode=production is passed after --no-mode', (done) => {
const { stderr, stdout } = run(__dirname, ['--no-mode', '--mode', 'production']);
expect(stderr).toBeFalsy();
expect(stdout).toBeTruthy();
expect(stdout).toContain('main.js.map');

stat(resolve(__dirname, './bin/main.js'), (err, stats) => {
expect(err).toBe(null);
Expand Down

0 comments on commit ca94729

Please sign in to comment.