/
help-flags.test.js
47 lines (36 loc) · 1.8 KB
/
help-flags.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
'use strict';
const { run } = require('../utils/test-utils');
const helpHeader = 'The build tool for modern web applications';
describe('commands help', () => {
it('log warning for invalid flag with --help flag', () => {
const { stdout, stderr, exitCode } = run(__dirname, ['--help', '--my-flag'], false);
expect(exitCode).toBe(0);
expect(stderr).toContain(`You provided an invalid option '--my-flag'`);
expect(stdout).toContain(helpHeader);
});
it('log warning for invalid flag with help command', () => {
const { stdout, stderr, exitCode } = run(__dirname, ['help', '--my-flag'], false);
expect(exitCode).toBe(0);
expect(stderr).toContain(`You provided an invalid option '--my-flag'`);
expect(stdout).toContain(helpHeader);
});
it('shows flag help with valid flag', () => {
const { stdout, stderr, exitCode } = run(__dirname, ['--help', '--merge'], false);
expect(exitCode).toBe(0);
expect(stderr).not.toContain(helpHeader);
expect(stdout).toContain('webpack -m, --merge');
});
it('should show help for --mode', () => {
const { stdout, stderr, exitCode } = run(__dirname, ['--mode', '--help'], false);
expect(exitCode).toBe(0);
expect(stderr).not.toContain(helpHeader);
expect(stdout).toContain('webpack --mode <development | production | none>');
expect(stdout).toContain('Defines the mode to pass to webpack');
});
it('gives precedence to earlier flag in case of multiple flags', () => {
const { stdout, stderr, exitCode } = run(__dirname, ['--help', '--entry', '--merge'], false);
expect(exitCode).toBe(0);
expect(stderr).not.toContain(helpHeader);
expect(stdout).toContain('webpack --entry <path to entry file>');
});
});