-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathinstall-viteplus.test.ts
More file actions
71 lines (55 loc) · 1.93 KB
/
install-viteplus.test.ts
File metadata and controls
71 lines (55 loc) · 1.93 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
import { describe, it, expect, afterEach, vi } from "vite-plus/test";
import { exec } from "@actions/exec";
import { warning } from "@actions/core";
import { installVitePlus } from "./install-viteplus.js";
import type { Inputs } from "./types.js";
vi.mock("@actions/core", () => ({
info: vi.fn(),
warning: vi.fn(),
addPath: vi.fn(),
}));
vi.mock("@actions/exec", () => ({
exec: vi.fn(),
}));
vi.mock("node:timers/promises", () => ({
setTimeout: vi.fn().mockResolvedValue(undefined),
}));
const baseInputs: Inputs = {
version: "latest",
nodeVersion: undefined,
nodeVersionFile: undefined,
workingDirectory: undefined,
runInstall: [],
cache: false,
cacheDependencyPath: undefined,
registryUrl: undefined,
scope: undefined,
};
describe("installVitePlus", () => {
afterEach(() => {
vi.resetAllMocks();
});
it("should succeed on first attempt without retrying", async () => {
vi.mocked(exec).mockResolvedValueOnce(0);
await installVitePlus(baseInputs);
expect(exec).toHaveBeenCalledTimes(1);
expect(warning).not.toHaveBeenCalled();
});
it("should retry on transient failure and eventually succeed", async () => {
vi.mocked(exec).mockResolvedValueOnce(6).mockResolvedValueOnce(6).mockResolvedValueOnce(0);
await installVitePlus(baseInputs);
expect(exec).toHaveBeenCalledTimes(3);
expect(warning).toHaveBeenCalledTimes(2);
});
it("should throw after exhausting all retries", async () => {
vi.mocked(exec).mockResolvedValue(6);
await expect(installVitePlus(baseInputs)).rejects.toThrow(/after 3 attempts/);
expect(exec).toHaveBeenCalledTimes(3);
});
it("should retry when exec itself throws (e.g. process spawn error)", async () => {
vi.mocked(exec).mockRejectedValueOnce(new Error("spawn bash ENOENT")).mockResolvedValueOnce(0);
await installVitePlus(baseInputs);
expect(exec).toHaveBeenCalledTimes(2);
expect(warning).toHaveBeenCalledTimes(1);
});
});