-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.test.js
84 lines (70 loc) · 2.65 KB
/
index.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import lint from '@commitlint/lint';
import {rules, parserPreset} from '.';
import {gitmojis} from 'gitmojis'
const allGitmojiCodes = gitmojis.map(gitmoji => gitmoji.code);
const lintMessage = async (message) => {
const parserOpts = parserPreset.parserOpts;
const m = message.replace(/^\s+/, '').trim();
const result = await lint(m, rules, {parserOpts});
if (result.errors.length > 1) {
throw new Error(
'Commit test should only have one error message to validate against'
);
}
if (result.warnings.length > 1) {
throw new Error(
'Commit test should only have one warning message to validate against'
);
}
return result;
};
test('a valid commit message', async () => {
const result = await lintMessage(':white_check_mark: a valid angular commit');
expect(result.valid).toBe(true);
expect(result.errors).toStrictEqual([]);
expect(result.warnings).toStrictEqual([]);
});
test('a valid message with a scope', async () => {
const result = await lintMessage(
':white_check_mark: (scope) a valid angular commit with a scope'
);
expect(result.valid).toBe(true);
expect(result.errors).toStrictEqual([]);
expect(result.warnings).toStrictEqual([]);
});
test('a valid multi line commit', async () => {
const result = await lintMessage(
`:white_check_mark: (scope) a valid angular commit with a scope
Some content in the body`
);
expect(result.valid).toBe(true);
expect(result.errors).toStrictEqual([]);
expect(result.warnings).toStrictEqual([]);
});
test('a leading blank line after header', async () => {
const result = await lintMessage(
`:white_check_mark: (scope) a valid angular commit with a scope
Some content in the body`
);
expect(result.valid).toBe(false);
expect(result.errors[0].message).toBe('body must have leading blank line');
expect(result.warnings).toStrictEqual([]);
});
test('an invalid scope', async () => {
const result = await lintMessage(`:no: no is not not an invalid commit type`);
expect(result.valid).toBe(false);
expect(result.errors[0].message).toBe(
`type must be one of [${allGitmojiCodes.join(', ')}]`
);
expect(result.warnings).toStrictEqual([]);
});
test('a long header', async () => {
const result = await lintMessage(
`:white_check_mark: that its an error when there is ia realllllllllllllllllllllly long header`
);
expect(result.valid).toBe(false);
expect(result.errors[0].message).toBe(
'header must not be longer than 72 characters, current length is 92'
);
expect(result.warnings).toStrictEqual([]);
});