-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.test.ts
More file actions
68 lines (53 loc) · 2.04 KB
/
Copy pathcli.test.ts
File metadata and controls
68 lines (53 loc) · 2.04 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
import { describe, expect, it } from "vitest"
import { formatUsage, parseArgs } from "../src/shell/cli.js"
describe("parseArgs", () => {
it("reads token and project directory", () => {
const result = parseArgs(["--token", "abc", "my-project"])
expect(result.token).toBe("abc")
expect(result.projectDir).toBe("my-project")
})
it("leaves project directory empty when omitted so bootstrap can derive it from the token claim", () => {
const result = parseArgs(["--token", "abc"])
expect(result.projectDir).toBe("")
})
it("reads custom claim path", () => {
const result = parseArgs(["--token=abc", "--claim-path", "/claim", "my-project"])
expect(result.claimPath).toBe("/claim")
expect(result.projectDir).toBe("my-project")
})
it("reads project id overrides", () => {
const result = parseArgs(["--token=abc", "--project-id", "project_123", "my-project"])
expect(result.projectId).toBe("project_123")
})
it("reads control plane URL from environment", () => {
const result = parseArgs(
["--token", "abc", "my-project"],
{ SPAWNDOCK_CONTROL_PLANE_URL: "https://example.trycloudflare.com" },
)
expect(result.controlPlaneUrl).toBe("https://example.trycloudflare.com")
})
it("defaults control plane URL to the production VPS endpoint", () => {
const result = parseArgs(["--token", "abc"])
expect(result.controlPlaneUrl).toBe("https://spawn-dock.w3voice.net")
})
it("reads template repo and branch overrides", () => {
const result = parseArgs([
"--token",
"abc",
"--template-repo",
"https://example.com/tma.git",
"--template-branch",
"next",
"my-project",
])
expect(result.templateRepo).toBe("https://example.com/tma.git")
expect(result.templateBranch).toBe("next")
})
})
describe("formatUsage", () => {
it("renders a custom invocation", () => {
expect(formatUsage("npx @spawn-dock/create --token <pairing-token> [project-dir]")).toBe(
"Usage: npx @spawn-dock/create --token <pairing-token> [project-dir]",
)
})
})