-
Notifications
You must be signed in to change notification settings - Fork 366
Expand file tree
/
Copy pathargs.test.ts
More file actions
77 lines (64 loc) · 2.31 KB
/
Copy pathargs.test.ts
File metadata and controls
77 lines (64 loc) · 2.31 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
75
76
77
import { beforeAll, describe, expect, it, mock } from "bun:test";
let parseArgs: typeof import("../args.ts").parseArgs;
beforeAll(async () => {
mock.module("../../version.ts", () => ({
VERSION: "test",
}));
({ parseArgs } = await import("../args.ts"));
});
function parseCliArgs(args: string[]) {
return parseArgs(["bun", "ralphy", ...args]);
}
describe("parseArgs repeat options", () => {
it("parses --repeat 5 with task", () => {
const { options, task } = parseCliArgs(["--repeat", "5", "do something"]);
expect(task).toBe("do something");
expect(options.repeatCount).toBe(5);
expect(options.continueOnFailure).toBe(false);
});
it("throws on --repeat 0", () => {
expect(() => parseCliArgs(["--repeat", "0", "task"])).toThrow(
"--repeat must be an integer >= 1",
);
});
it("throws on --repeat -1", () => {
expect(() => parseCliArgs(["--repeat", "-1", "task"])).toThrow(
"--repeat must be an integer >= 1",
);
});
it("throws on --repeat abc", () => {
expect(() => parseCliArgs(["--repeat", "abc", "task"])).toThrow(
"--repeat must be an integer >= 1",
);
});
it("throws on --repeat 1.5", () => {
expect(() => parseCliArgs(["--repeat", "1.5", "task"])).toThrow(
"--repeat must be an integer >= 1",
);
});
it("parses --repeat with --continue-on-failure", () => {
const { options } = parseCliArgs(["--repeat", "3", "--continue-on-failure", "task"]);
expect(options.repeatCount).toBe(3);
expect(options.continueOnFailure).toBe(true);
});
it("throws when --repeat is used without task", () => {
expect(() => parseCliArgs(["--repeat", "3"])).toThrow(
"--repeat and --continue-on-failure require a task argument",
);
});
it("throws when --continue-on-failure is used without task", () => {
expect(() => parseCliArgs(["--continue-on-failure"])).toThrow(
"--repeat and --continue-on-failure require a task argument",
);
});
it("throws when repeat options are combined with task source flags", () => {
expect(() => parseCliArgs(["--repeat", "3", "--yaml", "tasks.yaml", "task"])).toThrow(
"--repeat and --continue-on-failure cannot be used with --prd, --yaml, --json, or --github",
);
});
it("defaults to repeatCount 1", () => {
const { options } = parseCliArgs(["task"]);
expect(options.repeatCount).toBe(1);
expect(options.continueOnFailure).toBe(false);
});
});