-
-
Notifications
You must be signed in to change notification settings - Fork 591
/
parseArgs.test.ts
49 lines (40 loc) · 1.57 KB
/
parseArgs.test.ts
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
'use strict';
// TODO: update snapshots once we update to webpack-dev-server@4
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const errorMock: any = jest.fn();
jest.mock('webpack-cli/lib/utils/logger', () => {
return {
error: errorMock,
};
});
import WebpackCLI from 'webpack-cli';
import parseArgs from '../src/parseArgs';
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const processExitSpy: any = jest.spyOn(process, 'exit');
// eslint-disable-next-line @typescript-eslint/no-empty-function
processExitSpy.mockImplementation(() => {});
describe('parseArgs', () => {
const cli = new WebpackCLI();
beforeEach(() => {
errorMock.mockClear();
processExitSpy.mockClear();
});
it('parses webpack and dev server args', () => {
const args = parseArgs(cli, ['--bonjour', '--mode=development', '--port', '8080']);
expect(args).toMatchSnapshot();
expect(errorMock.mock.calls.length).toEqual(0);
expect(processExitSpy.mock.calls.length).toEqual(0);
});
it('handles hot arg', () => {
const args = parseArgs(cli, ['--hot']);
expect(args).toMatchSnapshot();
expect(errorMock.mock.calls.length).toEqual(0);
expect(processExitSpy.mock.calls.length).toEqual(0);
});
it('handles unknown args', () => {
parseArgs(cli, ['--unknown-arg', '--unknown-arg-2']);
expect(errorMock.mock.calls).toMatchSnapshot();
expect(processExitSpy.mock.calls.length).toEqual(1);
expect(processExitSpy.mock.calls[0]).toEqual([2]);
});
});