Skip to content

Commit

Permalink
tests: add test for no-mode flag
Browse files Browse the repository at this point in the history
  • Loading branch information
snitin315 committed Feb 28, 2020
1 parent 70af83b commit da88754
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 1 deletion.
11 changes: 11 additions & 0 deletions packages/webpack-cli/__tests__/ZeroConfigGroup.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,15 @@ describe('GroupHelper', function() {
const result = group.run();
expect(result.options.mode).toEqual('development');
});

it('should handle the mode option [none]', () => {
const group = new ZeroConfigGroup([
{
mode: 'none',
},
]);

const result = group.run();
expect(result.options.mode).toEqual('development');
});
});
12 changes: 12 additions & 0 deletions packages/webpack-cli/lib/groups/ZeroConfigGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,18 @@ class ZeroConfigGroup extends GroupHelper {
);
return this.args.mode;
}
if (isNoMode && this.args.mode) {
logger.warn(
'You Provided both mode and no-mode arguments. You Should Provide just one. "mode" will be used.'
)
}
if (isNoMode && (this.args.dev || this.args.prod)) {
logger.warn(
`You provided both no-mode and ${
this.args.prod ? '--prod' : '--dev'
} arguments. You should provide just one, "${this.args.prod ? '--prod' : '--dev'}" will be used`,
);
}
if (this.args.mode) {
return this.args.mode;
}
Expand Down
3 changes: 2 additions & 1 deletion test/help/__snapshots__/help-single-arg.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ Options
--standard Prints standard output
-d, --dev Run development build
-p, --prod Run production build
--mode string Defines the mode to pass to webpack
--mode string Defines the mode to pass to webpack
--no-mode Sets mode="none" which disables any default behavior
--version Get current version
--node-args string[] NodeJS flags
Expand Down
64 changes: 64 additions & 0 deletions test/no-mode/no-mode.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
'use strict';
const { run } = require('../utils/test-utils');
const { stat } = require('fs');
const { resolve } = require('path');
describe('no-mode flag', () => {
it('should load a development config when --no-mode is passed', done => {
const { stderr, stdout } = run(__dirname, ['--no-mode']);
expect(stderr).toBeFalsy();
expect(stdout).toBeTruthy();
stat(resolve(__dirname, './bin/main.js'), (err, stats) => {
expect(err).toBe(null);
expect(stats.isFile()).toBe(true);
done();
});
});

it('should load a development config when --no-mode and --dev are passed', done => {
const { stderr, stdout } = run(__dirname, ['--no-mode', '--dev']);
expect(stderr).toContain('"--dev" will be used');
expect(stdout).toBeTruthy();

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

it('should load a production config when --no-mode and --prod are passed', done => {
const { stderr, stdout } = run(__dirname, ['--no-mode', '--prod']);
expect(stderr).toContain('"--prod" will be used');
expect(stdout).toBeTruthy();

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

it('should load a production config when --mode=production & --no-mode are passed', done => {
const { stderr, stdout } = run(__dirname, ['--mode', 'production', '--no-mode']);
expect(stderr).toContain('"mode" will be used');
expect(stdout).toBeTruthy();

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

it('should load a development config when --mode=development and --no-mode are passed', done => {
const { stderr, stdout } = run(__dirname, ['--mode', 'development', '--no-mode']);
expect(stderr).toContain('"mode" will be used');
expect(stdout).toBeTruthy();

stat(resolve(__dirname, './bin/main.js'), (err, stats) => {
expect(err).toBe(null);
expect(stats.isFile()).toBe(true);
done();
});
});
});
1 change: 1 addition & 0 deletions test/no-mode/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('Test');

0 comments on commit da88754

Please sign in to comment.