-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcli-args.test.ts
More file actions
74 lines (65 loc) · 2.16 KB
/
Copy pathcli-args.test.ts
File metadata and controls
74 lines (65 loc) · 2.16 KB
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
import { describe, expect, test } from 'vitest';
import { parseCliArgs } from '../../materializer/src/cli-args.ts';
describe('parseCliArgs', () => {
test('default target is playwright', () => {
expect(parseCliArgs(['createWidget'])).toEqual({
target: 'playwright',
positional: 'createWidget',
help: false,
allTargets: false,
listTargets: false,
});
});
test('--target=<id> overrides the default', () => {
expect(parseCliArgs(['--target=typescript-sdk', 'createWidget'])).toEqual({
target: 'typescript-sdk',
positional: 'createWidget',
help: false,
allTargets: false,
listTargets: false,
});
});
test('--target after the positional still applies', () => {
expect(parseCliArgs(['--all', '--target=python-sdk'])).toEqual({
target: 'python-sdk',
positional: '--all',
help: false,
allTargets: false,
listTargets: false,
});
});
test('--help short and long', () => {
expect(parseCliArgs(['--help'])).toMatchObject({ help: true });
expect(parseCliArgs(['-h'])).toMatchObject({ help: true });
});
test('--all-targets sets allTargets and preserves the positional sentinel', () => {
expect(parseCliArgs(['--all-targets', '--all'])).toMatchObject({
allTargets: true,
positional: '--all',
});
});
test('list-targets subcommand sets listTargets', () => {
expect(parseCliArgs(['list-targets'])).toMatchObject({
listTargets: true,
positional: undefined,
});
});
test('--all is preserved as the positional sentinel', () => {
expect(parseCliArgs(['--all'])).toMatchObject({ positional: '--all' });
});
test('empty argv yields no positional and no help', () => {
expect(parseCliArgs([])).toEqual({
target: 'playwright',
positional: undefined,
help: false,
allTargets: false,
listTargets: false,
});
});
test('first positional wins; later positionals are ignored', () => {
// CLI accepts a single operationId; documenting the parser behaviour explicitly.
expect(parseCliArgs(['createWidget', 'extra'])).toMatchObject({
positional: 'createWidget',
});
});
});