forked from conventional-changelog/commitlint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.test.js
84 lines (71 loc) 路 2.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
import lint from '@commitlint/lint';
import {rules, parserPreset} from '.';
export const testCommit = async ({message, valid, error, warning}) => {
const m = message.replace(/^\s+/, '').trim();
test(m.split('\n')[0], async () => {
const parserOpts = parserPreset.parserOpts;
const result = await lint(m, rules, {parserOpts});
expect(result.valid).toBe(valid);
if (result.errors.length > 1) {
console.log(errors);
fail(
'Commit test should only have one error message to validate against'
);
} else if (result.errors.length) {
expect(result.errors[0].message).toBe(error);
}
if (result.warnings.length > 1) {
fail(
'Commit test should only have one warning message to validate against'
);
} else if (result.warnings.length) {
expect(result.warnings[0].message).toBe(warning);
}
});
};
testCommit({
message: `test: a valid angular commit`,
valid: true,
});
testCommit({
message: `test(scope): a valid angular commit with a scope`,
valid: true,
});
testCommit({
message: `
test(scope): a valid angular commit with a scope
Some content in the body
`,
valid: true,
});
testCommit({
message: `
test(scope): a valid angular commit with a scope
Some content in the body
`,
valid: true,
warning: 'body must have leading blank line',
});
testCommit({
message: `no: no is not not an invalid commit type`,
valid: false,
error:
'type must be one of [build, ci, docs, feat, fix, perf, refactor, revert, style, test]',
});
testCommit({
message: `test: that its an error when there is ia realllllllllllllllllllllly long header`,
valid: false,
error: 'header must not be longer than 72 characters, current length is 79',
});
testCommit({
message: `test!: with a breaking change in the type`,
valid: false,
error:
'subject must not have an exclamation mark in the subject to identify a breaking change',
});
testCommit({
message: `test(scope)!: with a breaking change in the type with scope`,
valid: false,
error:
'subject must not have an exclamation mark in the subject to identify a breaking change',
});