/
runner.test.ts
144 lines (118 loc) · 5.08 KB
/
runner.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
141
142
143
144
jest.mock("../../utils/runDangerSubprocess")
import { runDangerSubprocess } from "../../utils/runDangerSubprocess"
const mockRunDangerSubprocess = runDangerSubprocess as jest.Mock<typeof runDangerSubprocess>
import { runRunner } from "../runner"
import { SharedCLI } from "../../utils/sharedDangerfileArgs"
import { FakeCI } from "../../../ci_source/providers/Fake"
import { FakePlatform } from "../../../platforms/FakePlatform"
import { Executor } from "../../../runner/Executor"
const defaultAppArgs: Partial<SharedCLI> = {
verbose: false,
textOnly: false,
}
const source = new FakeCI({})
const platform = new FakePlatform()
beforeEach(() => {
mockRunDangerSubprocess.mockReset()
})
it("uses the source and platform from config", async () => {
await runRunner(defaultAppArgs as SharedCLI, { platform, source })
// Pull the executor out of the call to runDangerSubprocess
const executor: Executor = mockRunDangerSubprocess.mock.calls[0][2]
expect(executor.ciSource).toEqual(source)
expect(executor.platform).toEqual(platform)
})
it("does not use GitHub Checks by default", async () => {
await runRunner(defaultAppArgs as SharedCLI, { platform, source })
// Pull the executor out of the call to runDangerSubprocess
const executor: Executor = mockRunDangerSubprocess.mock.calls[0][2]
expect(executor.ciSource).toEqual(source)
expect(executor.platform).toEqual(platform)
expect(executor.options.disableGitHubChecksSupport).toEqual(true)
})
it("uses GitHub Checks if requested", async () => {
const customArgs = {
...defaultAppArgs,
useGithubChecks: true,
} as SharedCLI
await runRunner(customArgs, { platform, source })
// Pull the executor out of the call to runDangerSubprocess
const executor: Executor = mockRunDangerSubprocess.mock.calls[0][2]
expect(executor.ciSource).toEqual(source)
expect(executor.platform).toEqual(platform)
expect(executor.options.disableGitHubChecksSupport).toEqual(false)
})
it("does not use GitHub Checks if requested not to", async () => {
const customArgs = {
...defaultAppArgs,
useGithubChecks: false,
} as SharedCLI
await runRunner(customArgs, { platform, source })
// Pull the executor out of the call to runDangerSubprocess
const executor: Executor = mockRunDangerSubprocess.mock.calls[0][2]
expect(executor.ciSource).toEqual(source)
expect(executor.platform).toEqual(platform)
expect(executor.options.disableGitHubChecksSupport).toEqual(true)
})
it("passes the strictm option from args into the executor config", async () => {
const customArgs = {
...defaultAppArgs,
failOnErrors: true,
} as SharedCLI
await runRunner(customArgs, { platform, source })
// Pull the executor out of the call to runDangerSubprocess
const executor: Executor = mockRunDangerSubprocess.mock.calls[0][2]
expect(executor.options.failOnErrors).toEqual(true)
})
// TODO: This occasionally fails!
// eslint-disable-next-line jest/no-disabled-tests
it.skip("passes the dangerID from args into the executor config", async () => {
const customArgs = {
...defaultAppArgs,
id: "test-danger-run",
} as SharedCLI
await runRunner(customArgs, { platform, source })
// Pull the executor out of the call to runDangerSubprocess
const executor: Executor = mockRunDangerSubprocess.mock.calls[0][2]
expect(executor.options.dangerID).toEqual("test-danger-run")
})
it("sets newComment to false by default", async () => {
await runRunner(defaultAppArgs as SharedCLI, { platform, source })
// Pull the executor out of the call to runDangerSubprocess
const executor: Executor = mockRunDangerSubprocess.mock.calls[0][2]
expect(executor.ciSource).toEqual(source)
expect(executor.platform).toEqual(platform)
expect(executor.options.newComment).toEqual(false)
})
it("passes newComment option if requested", async () => {
const customArgs = {
...defaultAppArgs,
newComment: true,
} as SharedCLI
await runRunner(customArgs, { platform, source })
// Pull the executor out of the call to runDangerSubprocess
const executor: Executor = mockRunDangerSubprocess.mock.calls[0][2]
expect(executor.ciSource).toEqual(source)
expect(executor.platform).toEqual(platform)
expect(executor.options.newComment).toEqual(true)
})
it("sets removePreviousComments to false by default", async () => {
await runRunner(defaultAppArgs as SharedCLI, { platform, source })
// Pull the executor out of the call to runDangerSubprocess
const executor: Executor = mockRunDangerSubprocess.mock.calls[0][2]
expect(executor.ciSource).toEqual(source)
expect(executor.platform).toEqual(platform)
expect(executor.options.removePreviousComments).toEqual(false)
})
it("passes removePreviousComments option if requested", async () => {
const customArgs = {
...defaultAppArgs,
removePreviousComments: true,
} as SharedCLI
await runRunner(customArgs, { platform, source })
// Pull the executor out of the call to runDangerSubprocess
const executor: Executor = mockRunDangerSubprocess.mock.calls[0][2]
expect(executor.ciSource).toEqual(source)
expect(executor.platform).toEqual(platform)
expect(executor.options.removePreviousComments).toEqual(true)
})