Repository navigation
Expand file tree
/
Copy pathrun-install.test.ts
More file actions
70 lines (65 loc) · 2.59 KB
/
Copy pathrun-install.test.ts
File metadata and controls
70 lines (65 loc) · 2.59 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
import { describe, expect, it, vi } from "vite-plus/test";
import { parseRunInstall, runInstall } from "./run-install.js";
const sfwCommand = { executable: "/trusted/sfw", sfw: true };
describe("portable installs", () => {
it("parses YAML comments, anchors, quoted escapes and empty arguments", () => {
expect(
parseRunInstall(`- &install
cwd: "apps/web"
args: ["--filter", "a\\"b", 'it''s', ""] # comment
- *install
`),
).toEqual(
Array.from({ length: 2 }, () => ({ cwd: "apps/web", args: ["--filter", 'a"b', "it's", ""] })),
);
expect(parseRunInstall("True")).toEqual([{}]);
expect(parseRunInstall("False")).toEqual([]);
expect(() => parseRunInstall("args: [true]")).toThrow("array of strings");
});
it("warms PowerShell and retries the sfw command-lookup failure once", async () => {
const execute = vi
.fn()
.mockResolvedValueOnce({ exitCode: 1, stdout: "", stderr: "Command 'vp' not found in PATH" })
.mockRejectedValueOnce(new Error("warm-up failed"))
.mockResolvedValueOnce({ exitCode: 0, stdout: "", stderr: "" });
await runInstall([{}], "/project", sfwCommand, {}, { platform: "win32", execute });
expect(execute.mock.calls.map((call) => call[0])).toEqual([
sfwCommand.executable,
"powershell.exe",
sfwCommand.executable,
]);
});
it("runs later entries, aggregates failures, and never retries ordinary install errors", async () => {
const execute = vi
.fn()
.mockResolvedValue({ exitCode: 1, stdout: "", stderr: "lockfile mismatch" });
await expect(
runInstall([{ cwd: "a" }, { cwd: "b" }], "/project", sfwCommand, {}, { execute }),
).rejects.toThrow(/cwd:.*a[\s\S]*cwd:.*b/);
expect(execute).toHaveBeenCalledTimes(2);
});
it.each(["linux", "darwin"] as const)(
"does not claim PowerShell warm-up on %s",
async (platform) => {
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
try {
const execute = vi
.fn()
.mockResolvedValueOnce({
exitCode: 1,
stdout: "",
stderr: "Command 'vp' not found in PATH",
})
.mockResolvedValueOnce({ exitCode: 0, stdout: "", stderr: "" });
await runInstall([{}], "/project", sfwCommand, {}, { platform, execute });
expect(execute.mock.calls.map(([command]) => command)).toEqual([
sfwCommand.executable,
sfwCommand.executable,
]);
expect(warn).toHaveBeenCalledWith("setup-vp: sfw could not resolve vp; retrying once.");
} finally {
warn.mockRestore();
}
},
);
});