-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathmain.test.ts
140 lines (118 loc) · 4.57 KB
/
main.test.ts
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import * as core from "@actions/core";
import * as io from "@actions/io";
import * as path from "path";
import * as os from "os";
import * as fs from "fs";
import nock from "nock";
const toolDir = path.join(__dirname, "runner", "tools");
const tempDir = path.join(__dirname, "runner", "temp");
const dataDir = path.join(__dirname, "testdata");
const IS_WINDOWS = process.platform === "win32";
process.env["RUNNER_TEMP"] = tempDir;
process.env["RUNNER_TOOL_CACHE"] = toolDir;
import * as installer from "../src/installer";
// Inputs for mock @actions/core
let inputs = {
token: process.env.GITHUB_TOKEN || "",
} as any;
describe("installer tests", () => {
beforeEach(async function () {
// Mock getInput
jest.spyOn(core, "getInput").mockImplementation((name: string) => {
return inputs[name];
});
await io.rmRF(toolDir);
await io.rmRF(tempDir);
await io.mkdirP(toolDir);
await io.mkdirP(tempDir);
});
afterAll(async () => {
try {
await io.rmRF(toolDir);
await io.rmRF(tempDir);
} catch {
console.log("Failed to remove test directories");
}
jest.restoreAllMocks();
});
it("Downloads version of Arduino CLI if no matching version is installed", async () => {
await installer.getArduinoCli("0.4.0");
const bindir = path.join(toolDir, "arduino-cli", "0.4.0", os.arch());
expect(fs.existsSync(`${bindir}.complete`)).toBe(true);
if (IS_WINDOWS) {
expect(fs.existsSync(path.join(bindir, "arduino-cli.exe"))).toBe(true);
} else {
expect(fs.existsSync(path.join(bindir, "arduino-cli"))).toBe(true);
}
}, 20000);
describe("Gets the latest release of Arduino CLI", () => {
beforeEach(() => {
jest.spyOn(core, "getInput").mockImplementation((name: string) => {
return inputs[name];
});
nock("https://api.github.com")
.get("/repos/Arduino/arduino-cli/git/refs/tags")
.replyWithFile(200, path.join(dataDir, "tags.json"));
});
afterEach(() => {
nock.cleanAll();
nock.enableNetConnect();
jest.clearAllMocks();
});
it("Gets the latest version of Arduino CLI 0.4.0 using 0.4 and no matching version is installed", async () => {
await installer.getArduinoCli("0.4");
const bindir = path.join(toolDir, "arduino-cli", "0.4.0", os.arch());
expect(fs.existsSync(`${bindir}.complete`)).toBe(true);
if (IS_WINDOWS) {
expect(fs.existsSync(path.join(bindir, "arduino-cli.exe"))).toBe(true);
} else {
expect(fs.existsSync(path.join(bindir, "arduino-cli"))).toBe(true);
}
}, 20000);
it("Gets the latest version of Arduino CLI v1.0.0 using 1.0.0 with no `v` prefix", async () => {
await installer.getArduinoCli("1.0.0");
const bindir = path.join(toolDir, "arduino-cli", "1.0.0", os.arch());
expect(fs.existsSync(`${bindir}.complete`)).toBe(true);
if (IS_WINDOWS) {
expect(fs.existsSync(path.join(bindir, "arduino-cli.exe"))).toBe(true);
} else {
expect(fs.existsSync(path.join(bindir, "arduino-cli"))).toBe(true);
}
}, 20000);
it("Gets the latest version of Arduino CLI v1.0.0 using the `v` prefix (v1.0.0)", async () => {
await installer.getArduinoCli("v1.0.0");
const bindir = path.join(toolDir, "arduino-cli", "1.0.0", os.arch());
expect(fs.existsSync(`${bindir}.complete`)).toBe(true);
if (IS_WINDOWS) {
expect(fs.existsSync(path.join(bindir, "arduino-cli.exe"))).toBe(true);
} else {
expect(fs.existsSync(path.join(bindir, "arduino-cli"))).toBe(true);
}
}, 20000);
it("Gets the latest version of Arduino CLI using the v1.x", async () => {
await installer.getArduinoCli("v1.x");
const bindir = path.join(toolDir, "arduino-cli", "1.0.1", os.arch());
expect(fs.existsSync(`${bindir}.complete`)).toBe(true);
if (IS_WINDOWS) {
expect(fs.existsSync(path.join(bindir, "arduino-cli.exe"))).toBe(true);
} else {
expect(fs.existsSync(path.join(bindir, "arduino-cli"))).toBe(true);
}
}, 20000);
it("Gets latest version of Arduino CLI using 0.x and no matching version is installed", async () => {
await installer.getArduinoCli("0.x");
const bindir = path.join(
toolDir,
"arduino-cli",
"0.36.0-rc.2",
os.arch(),
);
expect(fs.existsSync(`${bindir}.complete`)).toBe(true);
if (IS_WINDOWS) {
expect(fs.existsSync(path.join(bindir, "arduino-cli.exe"))).toBe(true);
} else {
expect(fs.existsSync(path.join(bindir, "arduino-cli"))).toBe(true);
}
}, 20000);
});
});