/
unknown.test.js
34 lines (29 loc) · 1.36 KB
/
unknown.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
const { run } = require('../utils/test-utils');
const unknownError = 'Unknown argument: --unknown';
describe('unknown behaviour', () => {
it('throws error if an unknown flag is passed in', () => {
const { stderr, exitCode } = run(__dirname, ['--unknown']);
expect(stderr).toBeTruthy();
expect(stderr).toContain(unknownError);
expect(exitCode).toBe(2);
});
it('should throw error and respect --color flag', () => {
const { stderr, exitCode } = run(__dirname, ['--unknown', '--color']);
expect(stderr).toBeTruthy();
expect(stderr).toContain(`[webpack-cli] \u001b[31m${unknownError}\u001b[31m`);
expect(exitCode).toBe(2);
});
it('throws error for unknow flag and respect --no-color', () => {
const { stderr, exitCode } = run(__dirname, ['--unknown', '--no-color']);
expect(stderr).toBeTruthy();
expect(stderr).not.toContain(`[webpack-cli] \u001b[31m${unknownError}\u001b[31m`);
expect(stderr).toContain(unknownError);
expect(exitCode).toBe(2);
});
it('suggests the closest match to an unknown flag', () => {
const { stderr, stdout, exitCode } = run(__dirname, ['--entyr', './a.js']);
expect(stderr).toContain('Unknown argument: --entyr');
expect(stdout).toContain('Did you mean --entry?');
expect(exitCode).toBe(2);
});
});