-
-
Notifications
You must be signed in to change notification settings - Fork 412
/
validateOptions.spec.js
65 lines (44 loc) Β· 1.82 KB
/
validateOptions.spec.js
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
import makeConsoleMock from 'consolemock'
import { promises as fs, constants } from 'fs'
import validateOptions from '../lib/validateOptions'
import { InvalidOptionsError } from '../lib/symbols'
describe('validateOptions', () => {
const mockAccess = jest.spyOn(fs, 'access')
mockAccess.mockImplementation(async () => {})
beforeEach(() => {
mockAccess.mockClear()
})
it('should resolve empty and missing config', async () => {
expect.assertions(3)
const logger = makeConsoleMock()
await expect(validateOptions({}, logger)).resolves.toBeUndefined()
await expect(validateOptions(undefined, logger)).resolves.toBeUndefined()
expect(logger.history()).toHaveLength(0)
})
it('should resolve with valid string-valued shell option', async () => {
expect.assertions(4)
const logger = makeConsoleMock()
await expect(validateOptions({ shell: '/bin/sh' }, logger)).resolves.toBeUndefined()
expect(mockAccess).toHaveBeenCalledTimes(1)
expect(mockAccess).toHaveBeenCalledWith('/bin/sh', constants.X_OK)
expect(logger.history()).toHaveLength(0)
})
it('should reject with invalid string-valued shell option', async () => {
expect.assertions(5)
const logger = makeConsoleMock()
mockAccess.mockImplementationOnce(() => Promise.reject(new Error('Failed')))
await expect(validateOptions({ shell: '/bin/sh' }, logger)).rejects.toThrowError(
InvalidOptionsError
)
expect(mockAccess).toHaveBeenCalledTimes(1)
expect(mockAccess).toHaveBeenCalledWith('/bin/sh', constants.X_OK)
expect(logger.history()).toHaveLength(1)
expect(logger.printHistory()).toMatchInlineSnapshot(`
"
ERROR β Validation Error:
Invalid value for option 'shell': /bin/sh
Failed
See https://github.com/okonet/lint-staged#command-line-flags"
`)
})
})