/
mode-single-arg.test.js
52 lines (41 loc) · 1.96 KB
/
mode-single-arg.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
'use strict';
const { run } = require('../../utils/test-utils');
describe('mode flags', () => {
it('should not set mode=production by default', () => {
const { stderr, stdout, exitCode } = run(__dirname);
expect(exitCode).toBe(0);
expect(stderr).toBeFalsy();
expect(stdout).not.toContain(`mode: 'production'`);
expect(stdout).toContain(`The 'mode' option has not been set, webpack will fallback to 'production' for this value.`);
});
it('should load a development config when --mode=development is passed', () => {
const { stderr, stdout, exitCode } = run(__dirname, ['--mode', 'development']);
expect(exitCode).toBe(0);
expect(stderr).toBeFalsy();
expect(stdout).toContain(`mode: 'development'`);
});
it('should load a production config when --mode=production is passed', () => {
const { stderr, stdout, exitCode } = run(__dirname, ['--mode', 'production']);
expect(exitCode).toBe(0);
expect(stderr).toBeFalsy();
expect(stdout).toContain(`mode: 'production'`);
});
it('should load a none config when --mode=none is passed', () => {
const { stderr, stdout, exitCode } = run(__dirname, ['--mode', 'none']);
expect(exitCode).toBe(0);
expect(stderr).toBeFalsy();
expect(stdout).toContain(`mode: 'none'`);
});
it('should pick mode form NODE_ENV', () => {
const { stderr, stdout, exitCode } = run(__dirname, [], false, [], { NODE_ENV: 'development' });
expect(exitCode).toBe(0);
expect(stderr).toBeFalsy();
expect(stdout).toContain(`mode: 'development'`);
});
it('should throw error when --mode=abcd is passed', () => {
const { stderr, exitCode } = run(__dirname, ['--mode', 'abcd']);
expect(exitCode).toBe(2);
expect(stderr).toContain('configuration.mode should be one of these');
expect(stderr).toContain(`"development" | "production" | "none"`);
});
});