-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest.js
54 lines (43 loc) · 1.46 KB
/
test.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
import fs from 'node:fs'
import test from 'ava'
import fetchRepository from './scripts/fetch-repository.js'
import fetchWebsite from './scripts/fetch-website.js'
const SAMPLE_EXTENSION = '.sample'
const hooks = JSON.parse(fs.readFileSync('./index.json'))
test('main', (t) => {
t.true(Array.isArray(hooks), 'Git hooks should be an array.')
t.true(hooks.length !== 0, 'Git hooks should not be empty.')
t.true(hooks.includes('commit-msg'), 'Git hooks should has `commit-msg`.')
})
test('.git/hooks', (t) => {
const files = fs.readdirSync('.git/hooks')
const hooksInRepository = new Set([
...files.filter((file) => !file.includes('.')),
...files
.filter((file) => file.endsWith(SAMPLE_EXTENSION))
.map((file) => file.slice(0, -SAMPLE_EXTENSION.length)),
])
const set = new Set(hooks)
t.true(hooksInRepository.length !== 0)
for (const hook of hooksInRepository) {
t.true(set.has(hook), `Git hooks should has ${hook}.`)
}
})
test('git/git repository', async (t) => {
const dataFromRepository = await fetchRepository()
t.deepEqual(
hooks,
dataFromRepository,
'Git hooks should has be same as data from git/git repository.',
)
})
test('git-scm.com', async (t) => {
const dataFromWebsite = await fetchWebsite()
t.true(hooks.length >= dataFromWebsite.length)
for (const hook of dataFromWebsite) {
t.true(
hooks.includes(hook),
`Git hooks should has documented ${hook} hook from git-scm.com.`,
)
}
})