-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.test.js
167 lines (148 loc) · 5.45 KB
/
index.test.js
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
import { jest } from "@jest/globals"
import { runAction, Mute, runJS, ignoreInstalled } from "./testutil"
Mute.all()
const NO_TEST_JAVA = !!process.env.NO_TEST_JAVA
beforeAll(() => {
process.env.RUN_ASYNC = "false"
})
describe("skipping slow tests", () => {
if (process.env.TEST_FAST) {
it.only("", () => {})
}
})
describe("run", () => {
afterEach(() => {
jest.resetAllMocks()
jest.clearAllMocks()
jest.restoreAllMocks()
})
it("skips all tools if INPUT env empty", async () => {
// this runJS is just a sanity check for invoking the subprocess
// directly without using Tool.subprocess
return runJS("index", {}).then((proc) => {
expect(proc.stderr.toString()).toBe("")
expect(proc.stdout).toMatch(/go.*skipping/)
expect(proc.stdout).toMatch(/java.*skipping/)
expect(proc.stdout).toMatch(/node.*skipping/)
expect(proc.stdout).toMatch(/python.*skipping/)
expect(proc.stdout).toMatch(/terraform.*skipping/)
})
})
it("skips asynchronously", async () => {
return runAction("index", { RUN_ASYNC: "true" }).then((proc) => {
expect(proc.stderr.toString()).toBe("")
expect(proc.stdout).toMatch(/go.*skipping/)
expect(proc.stdout).toMatch(/java.*skipping/)
expect(proc.stdout).toMatch(/node.*skipping/)
expect(proc.stdout).toMatch(/python.*skipping/)
expect(proc.stdout).toMatch(/terraform.*skipping/)
})
})
it("works with all tools", async () => {
const goVersion = "1.17.6"
const desiredJavaVersion = "17.0.5"
const sdkmanJavaVersionIdentifier = NO_TEST_JAVA
? ""
: `${desiredJavaVersion}-tem`
const tfVersion = "1.1.2"
const nodeVersion = "16.13.2"
const pyVersion = process.env.TEST_SLOW ? "3.10.2" : ""
return runAction("index", {
INPUT_GO: goVersion,
INPUT_JAVA: sdkmanJavaVersionIdentifier,
INPUT_NODE: nodeVersion,
INPUT_TERRAFORM: tfVersion,
INPUT_PYTHON: pyVersion,
...ignoreInstalled(),
}).then((proc) => {
expect(proc.stderr.toString()).toBe("")
expect(proc.stdout).toContain(`go version: ${goVersion}`)
expect(proc.stdout).toContain("golang success!")
expect(proc.stdout).toContain(
NO_TEST_JAVA
? "skipping"
: `java -version: ${desiredJavaVersion}`,
)
expect(proc.stdout).toContain(
NO_TEST_JAVA ? "skipping" : "java success!",
)
expect(proc.stdout).toContain(`node --version: ${nodeVersion}`)
expect(proc.stdout).toContain("node success!")
expect(proc.stdout).toContain(`terraform --version: ${tfVersion}`)
expect(proc.stdout).toContain("terraform success!")
if (process.env.SLOW_TEST) {
expect(proc.stdout).toContain(`python --version: ${pyVersion}`)
expect(proc.stdout).toContain("python success!")
} else {
expect(proc.stdout).toMatch(/python.*skipping/)
}
})
})
})
describe("inline", () => {
var run
var runner
var origEnv = { ...process.env }
const mockProcessExit = jest
.spyOn(process, "exit")
.mockImplementation((code) => {
throw new Error(`process.exit(${code})`)
})
beforeAll(async () =>
import("./index").then((m) => {
run = m.default
runner = m.runner
}),
)
beforeEach(() => mockProcessExit.mockClear())
beforeEach(() => {
process.env.RUN_AUTO = "false"
ignoreInstalled()
})
afterEach(() => {
process.env = { ...origEnv }
jest.resetModules()
})
it("doesn't error if there's nothing to run", async () => {
return run()
})
it("doesn't error if there's nothing to run in parallel", async () => {
process.env.RUN_ASYNC = "true"
return run()
})
it("doesn't error if there's nothing to run in serial", async () => {
process.env.RUN_ASYNC = "false"
return run()
})
it("works in parallel when there's actually tools", async () => {
process.env.RUN_ASYNC = "true"
process.env.INPUT_GO = "1.17.6"
return run()
})
it("works in serial when there's actually tools", async () => {
process.env.RUN_ASYNC = "false"
process.env.INPUT_GO = "1.17.6"
return run()
})
it("handles an error in serial", async () => {
process.env.RUN_ASYNC = "false"
process.env.INPUT_GO = "99.99.0" // deliberately bad version
return expect(run()).rejects.toThrow(
"subprocess exited with non-zero code: goenv",
)
})
it("handles multiple errors in parallel", async () => {
process.env.INPUT_GO = "99.99.1" // deliberately bad version
process.env.INPUT_NODE = "99.99.2" // deliberately bad version
return expect(run()).rejects.toThrow(
/subprocess exited with non-zero code: .*/,
)
})
it("handles an error wrapped in runner", async () => {
process.env.RUN_AUTO = "true"
process.env.INPUT_GO = "99.99.3" // deliberately bad version
return expect(runner()).resolves.toMatch(
/subprocess exited with non-zero code: goenv/,
)
})
})