Skip to content

Commit

Permalink
fix: none env
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait committed Feb 2, 2021
1 parent a924bf4 commit eaf042b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/webpack-cli/lib/webpack-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -1529,7 +1529,7 @@ class WebpackCLI {
!configOptions.mode &&
process.env &&
process.env.NODE_ENV &&
(process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'production' || process.env.NODE_ENV === 'node')
(process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'production' || process.env.NODE_ENV === 'none')
) {
configOptions.mode = process.env.NODE_ENV;
}
Expand Down
5 changes: 5 additions & 0 deletions test/node-env/auto-mode.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const WebpackCLITestPlugin = require('../utils/webpack-cli-test-plugin');

module.exports = {
plugins: [new WebpackCLITestPlugin()],
};
34 changes: 29 additions & 5 deletions test/node-env/node-env.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,48 @@
const { run } = require('../utils/test-utils');

describe('--node-env flag', () => {
it('should set process.env.NODE_ENV to "production"', () => {
it('should set "process.env.NODE_ENV" to "development"', () => {
const { exitCode, stderr, stdout } = run(__dirname, ['--node-env', 'development']);

expect(exitCode).toBe(0);
expect(stderr).toBeFalsy();
expect(stdout).toContain("mode: 'development'");
});

it('should set "process.env.NODE_ENV" to "production"', () => {
const { exitCode, stderr, stdout } = run(__dirname, ['--node-env', 'production']);

expect(exitCode).toBe(0);
expect(stderr).toBeFalsy();
expect(stdout).toContain("mode: 'production'");
});

it('should set process.env.NODE_ENV to "development"', () => {
const { exitCode, stderr, stdout } = run(__dirname, ['--node-env', 'development']);
it('should set "process.env.NODE_ENV" to "none"', () => {
const { exitCode, stderr, stdout } = run(__dirname, ['--node-env', 'none']);

expect(exitCode).toBe(0);
expect(stderr).toBeFalsy();
expect(stdout).toContain("mode: 'none'");
});

it('should set "process.env.NODE_ENV" and the "mode" option to "development"', () => {
const { exitCode, stderr, stdout } = run(__dirname, ['--node-env', 'development', '--config', './auto-mode.config.js']);

expect(exitCode).toBe(0);
expect(stderr).toBeFalsy();
expect(stdout).toContain("mode: 'development'");
});

it('should set process.env.NODE_ENV to "none"', () => {
const { exitCode, stderr, stdout } = run(__dirname, ['--node-env', 'none']);
it('should set "process.env.NODE_ENV" and the "mode" option to "production"', () => {
const { exitCode, stderr, stdout } = run(__dirname, ['--node-env', 'production', '--config', './auto-mode.config.js']);

expect(exitCode).toBe(0);
expect(stderr).toBeFalsy();
expect(stdout).toContain("mode: 'production'");
});

it('should set "process.env.NODE_ENV" and the "mode" option to "none"', () => {
const { exitCode, stderr, stdout } = run(__dirname, ['--node-env', 'none', '--config', './auto-mode.config.js']);

expect(exitCode).toBe(0);
expect(stderr).toBeFalsy();
Expand Down

0 comments on commit eaf042b

Please sign in to comment.