/
args.test.ts
82 lines (72 loc) · 2.68 KB
/
args.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/**
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
import {Config} from '@jest/types';
import {check} from '../../cli/args';
import {buildArgv} from '../../cli';
describe('check', () => {
it('returns true if the arguments are valid', () => {
const argv = {} as Config.Argv;
expect(check(argv)).toBe(true);
});
it('raises an exception if runInBand and maxWorkers are both specified', () => {
const argv = {maxWorkers: 2, runInBand: true} as Config.Argv;
expect(() => check(argv)).toThrow(
'Both --runInBand and --maxWorkers were specified',
);
});
it('raises an exception if onlyChanged and watchAll are both specified', () => {
const argv = {onlyChanged: true, watchAll: true} as Config.Argv;
expect(() => check(argv)).toThrow(
'Both --onlyChanged and --watchAll were specified',
);
});
it('raises an exception when lastCommit and watchAll are both specified', () => {
const argv = {lastCommit: true, watchAll: true} as Config.Argv;
expect(() => check(argv)).toThrow(
'Both --lastCommit and --watchAll were specified',
);
});
it('raises an exception if findRelatedTests is specified with no file paths', () => {
const argv = {
_: [] as Array<string>,
findRelatedTests: true,
} as Config.Argv;
expect(() => check(argv)).toThrow(
'The --findRelatedTests option requires file paths to be specified',
);
});
it('raises an exception if maxWorkers is specified with no number', () => {
const argv = ({maxWorkers: undefined} as unknown) as Config.Argv;
expect(() => check(argv)).toThrow(
'The --maxWorkers (-w) option requires a number or string to be specified',
);
});
it('allows maxWorkers to be a %', () => {
const argv = ({maxWorkers: '50%'} as unknown) as Config.Argv;
expect(() => check(argv)).not.toThrow();
});
it('raises an exception if config is not a valid JSON string', () => {
const argv = {config: 'x:1'} as Config.Argv;
expect(() => check(argv)).toThrow(
'The --config option requires a JSON string literal, or a file path with a .js or .json extension',
);
});
});
describe('buildArgv', () => {
it('should return only camelcased args ', () => {
// @ts-ignore
const mockProcessArgv = jest
.spyOn(process.argv, 'slice')
.mockImplementation(() => ['--clear-mocks']);
// @ts-ignore
const actual = buildArgv(null);
expect(actual).not.toHaveProperty('clear-mocks');
expect(actual).toHaveProperty('clearMocks', true);
mockProcessArgv.mockRestore();
});
});