/
getAbsoluteHooksPath.spec.js
44 lines (34 loc) 路 1.19 KB
/
getAbsoluteHooksPath.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
import { execa } from 'execa'
import getAbsoluteHooksPath from '../../src/utils/getAbsoluteHooksPath'
import * as stubs from './stubs'
describe('getAbsoluteHooksPath', () => {
const hookName = 'pre-commit'
describe('when core.hooksPath is defined', () => {
beforeAll(() => {
execa.mockReturnValue({ stdout: stubs.absoluteCoreHooksPath })
})
it('should return core.hooksPath', async () => {
const path = await getAbsoluteHooksPath(hookName)
expect(execa).toHaveBeenCalledWith('git', [
'config',
'--get',
'core.hooksPath'
])
expect(path).toEqual(`${stubs.absoluteCoreHooksPath}/${hookName}`)
})
})
describe('when core.hooksPath is not defined', () => {
beforeAll(() => {
execa.mockReturnValueOnce(new Error('core.hooksPath is not defined'))
execa.mockReturnValueOnce({ stdout: stubs.gitAbsoluteDir })
})
it('should return the default hook path', async () => {
const path = await getAbsoluteHooksPath(hookName)
expect(execa).toHaveBeenCalledWith('git', [
'rev-parse',
'--absolute-git-dir'
])
expect(path).toEqual(`${stubs.gitAbsoluteDir}/hooks/${hookName}`)
})
})
})