/
DangerResults.test.ts
129 lines (98 loc) · 3.68 KB
/
DangerResults.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
import {
resultsIntoInlineResults,
inlineResultsIntoResults,
mergeResults,
emptyDangerResults,
inlineResults,
regularResults,
sortInlineResults,
validateResults,
isEmptyResults,
} from "../DangerResults"
import {
singleViolationSingleFileResults,
multipleViolationSingleFileResults,
multipleViolationsMultipleFilesResults,
singleViolationsInlineResults,
multipleViolationsInlineResults,
regularAndInlineViolationsResults,
emptyDangerInlineResults,
unsortedInlineResults,
} from "./fixtures/ExampleDangerResults"
describe("DangerResults into DangerInlineResults", () => {
it("transforms empty results into empty inlineResults", () => {
const results = resultsIntoInlineResults(emptyDangerResults)
expect(results).toMatchSnapshot()
})
it("transforms single-violation results into one inlineResults", () => {
const results = resultsIntoInlineResults(singleViolationSingleFileResults)
expect(results).toMatchSnapshot()
})
it("transforms multiple-violation results into one inlineResults", () => {
const results = resultsIntoInlineResults(multipleViolationSingleFileResults)
expect(results).toMatchSnapshot()
})
it("transforms multiple-violation results into multiple inlineResults within one file", () => {
const results = resultsIntoInlineResults(multipleViolationsMultipleFilesResults)
expect(results).toMatchSnapshot()
})
})
describe("DangerInlineResults into DangerResults", () => {
it("transforms empty inlineResults into results", () => {
const results = inlineResultsIntoResults(emptyDangerInlineResults)
expect(results).toMatchSnapshot()
})
it("transforms single-violation inlineResults into results", () => {
const results = inlineResultsIntoResults(singleViolationsInlineResults)
expect(results).toMatchSnapshot()
})
it("transforms multiple-violation inlineResults into results", () => {
const results = inlineResultsIntoResults(multipleViolationsInlineResults)
expect(results).toMatchSnapshot()
})
})
describe("DangerResults operations", () => {
it("merges two results correctly", () => {
const results = mergeResults(singleViolationSingleFileResults, multipleViolationSingleFileResults)
expect(results).toMatchSnapshot()
})
it("filters results to get only inline violations", () => {
const results = inlineResults(regularAndInlineViolationsResults)
expect(results).toMatchSnapshot()
})
it("filters results to get only regular violations", () => {
const results = regularResults(regularAndInlineViolationsResults)
expect(results).toMatchSnapshot()
})
it("sorts inline results", () => {
const results = sortInlineResults(unsortedInlineResults)
expect(results).toMatchSnapshot()
})
it("find empty results", () => {
const result = isEmptyResults(emptyDangerResults)
expect(result).toEqual(true)
})
it("find empty results - multiple violations in a single file", () => {
const result = isEmptyResults(multipleViolationSingleFileResults)
expect(result).toEqual(false)
})
})
describe("validation", () => {
it("validates the presence of all result types", () => {
const badResults = { fails: [], markdowns: [], other: [] }
expect(() => {
validateResults(badResults as any)
}).toThrowErrorMatchingSnapshot()
})
it("validates the presence of message in a violation result types", () => {
const badResults = { fails: [{}], markdowns: [], warnings: [], messages: [] }
expect(() => {
validateResults(badResults as any)
}).toThrowErrorMatchingSnapshot()
})
it("does not throw for correct results", () => {
expect(() => {
validateResults(singleViolationSingleFileResults)
}).not.toThrow()
})
})