Repository navigation
Expand file tree
/
Copy pathcli.test.ts
More file actions
42 lines (35 loc) · 2.08 KB
/
Copy pathcli.test.ts
File metadata and controls
42 lines (35 loc) · 2.08 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
import {parseCliArgs} from "./cli.ts";
import {parseArgList, parseMixedArg} from "./config.ts";
test("recovers swallowed short option clusters, a recovered bare -M naming no modes", () => {
const positionals = ["package.json"];
expect(parseCliArgs(["-T", "-u", "package.json"])).toMatchObject({args: {timeout: true, update: true}, positionals});
expect(parseCliArgs(["-T", "-uj", "package.json"])).toMatchObject({args: {timeout: true, update: true, json: true}, positionals});
const recovered = parseCliArgs(["-i", "-ug", "react", "package.json"]);
expect(recovered).toMatchObject({args: {include: [], update: true, greatest: ["react"]}, positionals});
expect(parseMixedArg(recovered.args.include)).toBe(true);
expect(parseMixedArg(parseCliArgs(["--greatest", "react", "--greatest"]).args.greatest)).toBe(true);
expect(parseMixedArg(parseCliArgs(["-g", "react", "-g", "-uj"]).args.greatest)).toBe(true);
expect(parseArgList(parseCliArgs(["-g", "-M", "-Mu"]).args.modes)).toEqual(["u"]);
expect(parseCliArgs([
"-g", "-ulreact=*", "-l", "react=<19",
"-g", "-uT1000", "-T", "2000",
"-g", "-ufcluster.json", "-f", "explicit.json",
"package.json",
])).toMatchObject({args: {pin: ["react=*", "react=<19"], timeout: "2000", file: ["cluster.json", "explicit.json"]}, positionals});
expect(parseCliArgs(["-uj", "-T1000", "--", "--bogus", "-z", "-1"]))
.toMatchObject({args: {update: true, json: true, timeout: "1000"}, positionals: ["--bogus", "-z", "-1"]});
});
test.each(["--bogus", "-z"])("rejects unknown option %s", option => {
expect(() => parseCliArgs([option])).toThrow(`Unknown option: ${option}`);
});
test("rejects required options without a value", () => {
for (const name of [
"file", "modes", "include", "exclude", "pin", "cooldown", "types", "sockets", "timeout", "registry", "login",
"logout",
]) {
expect(() => parseCliArgs([`--${name}`])).toThrow(`Missing value for --${name}`);
}
for (const name of ["allow-downgrade", "greatest", "minor", "patch", "prerelease", "release"]) {
expect(() => parseCliArgs([`--${name}`])).not.toThrow();
}
});