Skip to content

Commit 10035b9

Browse files
authored
fix: Add explicitly null checks (#22)
* fix(job): Add explicitly null check * fix(step): Add explicitly null check * fix(on): Add explicitly null check * fix(on): Added event name conversion * fix(job): Add tests for job * chore(workflow): Add tests for workflow * fix: fix
1 parent 71bf3ba commit 10035b9

File tree

7 files changed

+1065
-374
lines changed

7 files changed

+1065
-374
lines changed

lib/package/job.spec.ts

Lines changed: 73 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,78 @@ import { describe, expect, test } from "bun:test";
22
import { Job } from "./job";
33

44
describe("Job", () => {
5-
test("simple job", () => {
6-
const job = new Job("test", { runsOn: "ubuntu-latest" });
7-
job.run("echo 'Hello, world!'");
8-
expect(job.toJSON()).toEqual({
9-
"runs-on": "ubuntu-latest",
10-
steps: [{ run: "echo 'Hello, world!'" }],
11-
});
5+
test.each<[Job, Record<string, unknown>]>([
6+
[
7+
new Job("test", { runsOn: "ubuntu-latest" }).run("echo 'Hello, world!'"),
8+
{
9+
"runs-on": "ubuntu-latest",
10+
steps: [{ run: "echo 'Hello, world!'" }],
11+
},
12+
],
13+
[
14+
new Job("test", {
15+
runsOn: "ubuntu-latest",
16+
permissions: {
17+
contents: "read",
18+
pullRequests: "write",
19+
},
20+
}),
21+
{
22+
"runs-on": "ubuntu-latest",
23+
permissions: {
24+
contents: "read",
25+
"pull-requests": "write",
26+
},
27+
steps: [],
28+
},
29+
],
30+
[
31+
new Job("test", {
32+
runsOn: "ubuntu-latest",
33+
timeoutMinutes: 10,
34+
}),
35+
{
36+
"runs-on": "ubuntu-latest",
37+
"timeout-minutes": 10,
38+
steps: [],
39+
},
40+
],
41+
[
42+
new Job("test", {
43+
runsOn: "ubuntu-latest",
44+
outputs: {
45+
"output-name": "output-value",
46+
},
47+
}).run("echo 'Hello, world!'"),
48+
{
49+
"runs-on": "ubuntu-latest",
50+
outputs: { "output-name": "output-value" },
51+
steps: [{ run: "echo 'Hello, world!'" }],
52+
},
53+
],
54+
[
55+
new Job("test", {
56+
runsOn: "ubuntu-latest",
57+
needs: "job-name",
58+
}).run("echo 'Hello, world!'"),
59+
{
60+
"runs-on": "ubuntu-latest",
61+
needs: "job-name",
62+
steps: [{ run: "echo 'Hello, world!'" }],
63+
},
64+
],
65+
[
66+
new Job("test", {
67+
runsOn: "ubuntu-latest",
68+
if: "always()",
69+
}).run("echo 'Hello, world!'"),
70+
{
71+
"runs-on": "ubuntu-latest",
72+
if: "always()",
73+
steps: [{ run: "echo 'Hello, world!'" }],
74+
},
75+
],
76+
])("job.toJSON(%j) -> %j", (job, expected) => {
77+
expect(job.toJSON()).toEqual(expected);
1278
});
1379
});

lib/package/job.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,19 @@ export class Job {
5252
return {
5353
"runs-on": this._config.runsOn,
5454

55-
...(this._config.permissions && {
55+
...(this._config.permissions != null && {
5656
permissions: permissionsJSON(this._config.permissions),
5757
}),
5858

59-
...(this._config.timeoutMinutes && {
59+
...(this._config.timeoutMinutes != null && {
6060
"timeout-minutes": this._config.timeoutMinutes,
6161
}),
6262

63-
...(this._config.outputs && { outputs: this._config.outputs }),
63+
...(this._config.outputs != null && { outputs: this._config.outputs }),
6464

65-
...(this._config.needs && { needs: this._config.needs }),
65+
...(this._config.needs != null && { needs: this._config.needs }),
6666

67-
...(this._config.if && { if: this._config.if }),
67+
...(this._config.if != null && { if: this._config.if }),
6868

6969
steps: this._steps.map((step) => stepJSON(step)),
7070
};

0 commit comments

Comments
 (0)