/
dangerRunToRunnerCLI.test.ts
118 lines (105 loc) · 4.21 KB
/
dangerRunToRunnerCLI.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
import dangerRunToRunnerCLI from "../dangerRunToRunnerCLI"
import { addSubprocessCallArguments } from "../runDangerSubprocess"
describe("it can handle the command", () => {
it("`danger ci`", () => {
expect(dangerRunToRunnerCLI(["danger", "ci"])).toEqual("danger runner".split(" "))
})
it("`danger local`", () => {
expect(dangerRunToRunnerCLI(["danger", "local"])).toEqual("danger runner".split(" "))
})
it("`danger ci --dangerfile myDangerfile.ts`", () => {
expect(dangerRunToRunnerCLI(["danger", "ci", "--dangerfile", "myDangerfile.ts"])).toEqual(
"danger runner --dangerfile myDangerfile.ts".split(" ")
)
})
it("`node distribution/commands/danger-ci.js`", () => {
expect(dangerRunToRunnerCLI(["node", "distribution/commands/danger-ci.js"])).toEqual(
"node distribution/commands/danger-runner.js".split(" ")
)
})
it("`node distribution/commands/danger-ci.js --dangerfile myDangerfile.ts`", () => {
expect(
dangerRunToRunnerCLI(["node", "distribution/commands/danger-ci.js", "--dangerfile", "myDangerfile.ts"])
).toEqual("node distribution/commands/danger-runner.js --dangerfile myDangerfile.ts".split(" "))
})
})
it("`node distribution/commands/danger-ci.js --dangerfile 'myDanger file.ts'`", () => {
expect(
dangerRunToRunnerCLI(["node", "distribution/commands/danger-ci.js", "--dangerfile", "myDanger file.ts"])
).toEqual(["node", "distribution/commands/danger-runner.js", "--dangerfile", "myDanger file.ts"])
})
it("`node distribution/commands/danger-pr.js --dangerfile 'myDanger file.ts'`", () => {
expect(
dangerRunToRunnerCLI(["node", "distribution/commands/danger-pr.js", "--dangerfile", "myDanger file.ts"])
).toEqual(["node", "distribution/commands/danger-runner.js", "--dangerfile", "myDanger file.ts"])
})
it("`danger pr --dangerfile 'myDanger file.ts'`", () => {
expect(dangerRunToRunnerCLI(["danger", "pr", "--dangerfile", "myDanger file.ts"])).toEqual([
"danger",
"runner",
"--dangerfile",
"myDanger file.ts",
])
})
it("Adds correct subprocess arguments", () => {
expect(
addSubprocessCallArguments(
["danger-swift"],
["danger", "danger-pr", "--process", "danger-swift", "--dangerfile", "File.swift"]
)
).toEqual(["danger-swift", "runner", "danger-pr", "--process", "danger-swift", "--dangerfile", "File.swift"])
})
describe("npx danger-ts", () => {
it("switches to the danger in the node_mods", () => {
expect.assertions(1)
// the code uses join which gives different results on windows, and I'm too lazy to add a specific test for that
const isWindows = process.platform === "win32"
if (!isWindows) {
// eslint-disable-next-line jest/no-conditional-expect
expect(
dangerRunToRunnerCLI([
"/Users/ortatherox/.nvm/versions/node/v14.5.0/bin/node",
"/Users/ortatherox/.npm/_npx/23085/bin/danger-ts",
])
).toEqual([
"/Users/ortatherox/.nvm/versions/node/v14.5.0/bin/node",
"/Users/ortatherox/.npm/_npx/23085/lib/node_modules/danger-ts/node_modules/danger/distribution/commands/danger-runner.js",
])
} else {
console.warn("Unimplemented test on windows")
// eslint-disable-next-line jest/no-conditional-expect
expect(true).toBe(true)
}
})
})
describe("it can handle the command when running from pkg", () => {
beforeAll(() => {
process.pkg = {
defaultEntrypoint: "Hello",
entrypoint: "World",
}
})
afterAll(() => {
process.pkg = undefined
})
it("`./brew-distribution/danger /snapshot/danger-js/distribution/commands/danger-pr.js --dangerfile myDangerfile.ts`", () => {
/**
* The example of argv
* [ '/Users/core/Documents/project/danger-js/brew-distribution/danger',
* '/snapshot/danger-js/distribution/commands/danger-pr.js',
* 'https://bitbucket.org/foo/bar/pull-requests/381' ]
*/
expect(
dangerRunToRunnerCLI([
"./brew-distribution/danger",
"/snapshot/danger-js/distribution/commands/danger-pr.js",
"--dangerfile",
"myDangerfile.ts",
])
).toEqual(
"./brew-distribution/danger /snapshot/danger-js/distribution/commands/danger-runner.js --dangerfile myDangerfile.ts".split(
" "
)
)
})
})