-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathindex.spec.js
74 lines (65 loc) · 2.26 KB
/
index.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
66
67
68
69
70
71
72
73
74
import lint from '@commitlint/lint'
import { rules } from '.'
const TOO_LONG = `It's an example of invalid sentence since it has more than 72 characters!`
describe('Commitlint Config Cozy', () => {
describe('Header', () => {
it('respect type', async () => {
const validType = [
'feat',
'fix',
'docs',
'style',
'refactor',
'test',
'chore'
]
const invalidType = ['funType', 'Feat', 'doCs']
for (const type of validType) {
expect((await lint(`${type}: Bar`, rules)).valid).toBeTruthy()
}
for (const type of invalidType) {
expect((await lint(`${type}: Bar`, rules)).valid).toBeFalsy()
}
})
it('respect scope', async () => {
const validScope = ['LineChart', 'balance history']
for (const scope of validScope) {
expect((await lint(`feat(${scope}): Bar`, rules)).valid).toBeTruthy()
}
})
it('respect max length', async () => {
const valideLength =
'fix: This line contains exactly 72 characters meaning it passes the test'
expect((await lint(valideLength, rules)).valid).toBeTruthy()
const invalidLength =
'refactor: This one contains more than 72 so it really should not pass the test because no one can read the end'
expect((await lint(invalidLength, rules)).valid).toBeFalsy()
})
it('can use emojis in your commit subject', async () => {
const validEmojis = [
'fix: 🔍 This is a valid commit',
'fix: This is a valid commit 🔍'
]
for (const emoji of validEmojis) {
expect((await lint(emoji, rules)).valid).toBeTruthy()
}
const invalidEmojis = '🔍 fix: This is an invalid commit'
expect((await lint(invalidEmojis, rules)).valid).toBeFalsy()
})
})
describe('Body', () => {
it('respect max length', async () => {
const validBody = [`fix: Bar\n\nWith a small body`]
for (const body of validBody) {
expect((await lint(body, rules)).valid).toBeTruthy()
}
const invalidBody = [
`fix: Bar\n\n${TOO_LONG}`,
`fix: Bar\n\nWith a small body\n${TOO_LONG}`
]
for (const body of invalidBody) {
expect((await lint(body, rules)).valid).toBeFalsy()
}
})
})
})