forked from conventional-changelog/commitlint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.test.js
104 lines (86 loc) · 3.04 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import lint from '@commitlint/lint';
import {rules, parserPreset} from '.';
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('test: 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(
'test(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(
`test(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(
`test(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[0].message).toBe('body must have leading blank line');
});
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 [build, ci, docs, feat, fix, perf, refactor, revert, style, test]'
);
expect(result.warnings).toStrictEqual([]);
});
test('a long header', async () => {
const result = await lintMessage(
`test: 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 79'
);
expect(result.warnings).toStrictEqual([]);
});
test('message header with ! in it', async () => {
const result = await lintMessage(`test!: with a breaking change in the type`);
expect(result.valid).toBe(false);
expect(result.errors[0].message).toBe(
'subject must not have an exclamation mark in the subject to identify a breaking change'
);
expect(result.warnings).toStrictEqual([]);
});
test('message header with ! in it and a scope', async () => {
const result = await lintMessage(
`test(scope)!: with a breaking change in the type`
);
expect(result.valid).toBe(false);
expect(result.errors[0].message).toBe(
'subject must not have an exclamation mark in the subject to identify a breaking change'
);
expect(result.warnings).toStrictEqual([]);
});