-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathinputs.test.ts
More file actions
118 lines (91 loc) · 3.14 KB
/
inputs.test.ts
File metadata and controls
118 lines (91 loc) · 3.14 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import { describe, it, expect, beforeEach, afterEach, vi } from "vite-plus/test";
import { getInput, getBooleanInput } from "@actions/core";
import { getInputs } from "./inputs.js";
// Mock @actions/core
vi.mock("@actions/core", () => ({
getInput: vi.fn(),
getBooleanInput: vi.fn(),
}));
describe("getInputs", () => {
beforeEach(() => {
vi.resetAllMocks();
});
afterEach(() => {
vi.resetAllMocks();
});
it("should return default values when no inputs provided", () => {
vi.mocked(getInput).mockReturnValue("");
vi.mocked(getBooleanInput).mockReturnValue(false);
const inputs = getInputs();
expect(inputs).toEqual({
version: "latest",
runInstall: [],
cache: false,
cacheDependencyPath: undefined,
cacheSaveIf: false,
});
});
it("should parse version input", () => {
vi.mocked(getInput).mockImplementation((name) => {
if (name === "version") return "1.2.3";
return "";
});
vi.mocked(getBooleanInput).mockReturnValue(false);
const inputs = getInputs();
expect(inputs.version).toBe("1.2.3");
});
it("should parse run-install as true", () => {
vi.mocked(getInput).mockImplementation((name) => {
if (name === "run-install") return "true";
return "";
});
vi.mocked(getBooleanInput).mockReturnValue(false);
const inputs = getInputs();
expect(inputs.runInstall).toEqual([{}]);
});
it("should parse run-install as false", () => {
vi.mocked(getInput).mockImplementation((name) => {
if (name === "run-install") return "false";
return "";
});
vi.mocked(getBooleanInput).mockReturnValue(false);
const inputs = getInputs();
expect(inputs.runInstall).toEqual([]);
});
it("should parse run-install as YAML object", () => {
vi.mocked(getInput).mockImplementation((name) => {
if (name === "run-install") return "cwd: ./packages/app\nargs:\n - --frozen-lockfile";
return "";
});
vi.mocked(getBooleanInput).mockReturnValue(false);
const inputs = getInputs();
expect(inputs.runInstall).toEqual([{ cwd: "./packages/app", args: ["--frozen-lockfile"] }]);
});
it("should parse run-install as YAML array", () => {
vi.mocked(getInput).mockImplementation((name) => {
if (name === "run-install") return "- cwd: ./app\n- cwd: ./lib";
return "";
});
vi.mocked(getBooleanInput).mockReturnValue(false);
const inputs = getInputs();
expect(inputs.runInstall).toEqual([{ cwd: "./app" }, { cwd: "./lib" }]);
});
it("should parse cache input", () => {
vi.mocked(getInput).mockReturnValue("");
vi.mocked(getBooleanInput).mockImplementation((name) => {
if (name === "cache") return true;
return false;
});
const inputs = getInputs();
expect(inputs.cache).toBe(true);
});
it("should parse cache-dependency-path input", () => {
vi.mocked(getInput).mockImplementation((name) => {
if (name === "cache-dependency-path") return "custom-lock.yaml";
return "";
});
vi.mocked(getBooleanInput).mockReturnValue(false);
const inputs = getInputs();
expect(inputs.cacheDependencyPath).toBe("custom-lock.yaml");
});
});