Skip to content

Commit d8c37f2

Browse files
committed
tests of snapshots
1 parent f9f27a7 commit d8c37f2

File tree

3 files changed

+62
-1
lines changed

3 files changed

+62
-1
lines changed

__tests__/__mocks__/examplePlugin.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,25 @@ module.exports = context => {
3636
message: 'Boooo failed check',
3737
}
3838
},
39+
snapshot: async (rule, context) => [
40+
{
41+
prop: 'semver',
42+
value: '12.0.0',
43+
},
44+
{
45+
prop: 'nachos',
46+
value: true
47+
}
48+
]
49+
},
50+
checkThirdThing: {
51+
check: async (rule, context) => {
52+
return {
53+
pass: true,
54+
message: 'PAZZZZZ',
55+
}
56+
},
57+
snapshot: async (rule, context) => []
3958
},
4059
},
4160
})

__tests__/command_helpers/__snapshots__/updateRequirement.ts.snap

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,12 @@
22

33
exports[`updateRequirement exists 1`] = `[Function]`;
44

5+
exports[`updateRequirement given a rule rule is custom custom combo - play nicely with others 1`] = `
6+
Array [
7+
"Setting checkThing 'semver' to '12.0.0'",
8+
"Setting checkSecondThing 'semver' to '12.0.0', 'nachos' to 'true'",
9+
Array [],
10+
]
11+
`;
12+
513
exports[`updateRequirement updateRequirement empty still spins 1`] = `Array []`;

__tests__/command_helpers/updateRequirement.ts

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ describe('updateRequirement', () => {
127127
})
128128

129129
describe('rule is custom', () => {
130-
it('returns stuff', async () => {
130+
it('reports on custom updates', async () => {
131131
const requirement = toPairs({
132132
TestRequirement: [{ rule: 'custom', plugin: 'Example Plugin', name: 'checkThing' }],
133133
})[0]
@@ -136,6 +136,40 @@ describe('updateRequirement', () => {
136136
expect(result).toEqual(["Setting checkThing 'semver' to '12.0.0'"])
137137
expect(spinner.stop.mock.calls.length).toEqual(1)
138138
})
139+
140+
it('reports correctly on multiple updates', async () => {
141+
const requirement = toPairs({
142+
TestRequirement: [{ rule: 'custom', plugin: 'Example Plugin', name: 'checkSecondThing' }],
143+
})[0]
144+
145+
const result = await updateRequirement(requirement, settings, context)
146+
expect(result).toEqual(["Setting checkSecondThing 'semver' to '12.0.0', 'nachos' to 'true'"])
147+
expect(spinner.stop.mock.calls.length).toEqual(1)
148+
})
149+
150+
it('reports correctly on NO updates', async () => {
151+
const requirement = toPairs({
152+
TestRequirement: [{ rule: 'custom', plugin: 'Example Plugin', name: 'checkThirdThing' }],
153+
})[0]
154+
155+
const result = await updateRequirement(requirement, settings, context)
156+
expect(result).toEqual([[]])
157+
expect(spinner.stop.mock.calls.length).toEqual(1)
158+
})
159+
160+
it('custom combo - play nicely with others', async () => {
161+
const requirement = toPairs({
162+
TestRequirement: [
163+
{ rule: 'custom', plugin: 'Example Plugin', name: 'checkThing' },
164+
{ rule: 'custom', plugin: 'Example Plugin', name: 'checkSecondThing' },
165+
{ rule: 'custom', plugin: 'Example Plugin', name: 'checkThirdThing' }
166+
],
167+
})[0]
168+
169+
const result = await updateRequirement(requirement, settings, context)
170+
expect(result).toMatchSnapshot()
171+
expect(spinner.stop.mock.calls.length).toEqual(1)
172+
})
139173
})
140174

141175
describe('rule: !== cli || custom', () => {

0 commit comments

Comments
 (0)