-
-
Notifications
You must be signed in to change notification settings - Fork 549
Expand file tree
/
Copy pathcli-args.spec.ts
More file actions
32 lines (28 loc) · 878 Bytes
/
cli-args.spec.ts
File metadata and controls
32 lines (28 loc) · 878 Bytes
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
import { context } from './testlib';
import { ctxTsNode, testsDirRequire } from './helpers';
import type { ParsedArgv } from '../bin';
const test = context(ctxTsNode);
const argParseMacro = test.macro(
(args: string[], entrypointArgs: Record<string, any> | undefined, expectation: Partial<ParsedArgv>) => [
() => `"${args.join(' ')}"${entrypointArgs ? ` w/entrypoint args: ${JSON.stringify(entrypointArgs)}` : ``}`,
async (t) => {
const parsedArgs = t.context.tsNodeBin.parseArgv(args, entrypointArgs ?? {});
t.like(parsedArgs, expectation);
},
]
);
test(argParseMacro, ['-pe', '123'], undefined, {
print: true,
code: '123',
restArgs: [],
});
test(argParseMacro, ['-p', '123'], undefined, {
print: true,
code: '123',
restArgs: [],
});
test(argParseMacro, ['-e', '123'], undefined, {
print: false,
code: '123',
restArgs: [],
});