-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
100 lines (96 loc) · 3.07 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
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
const { test, expect } = require('@jest/globals');
const lint = require('@commitlint/lint').default;
const { rules } = require('.');
const tests = [
{
name: 'a valid oneline commit message',
message: 'Great commit summaries contain fewer than 50 chars',
valid: true,
errors: [],
},
{
name: 'a detailed commit',
message: 'Great commit summaries contain fewer than 50 chars'
+ '\n\n'
+ 'More detailed explanatory text, if necessary. Wrap it to about 72\n'
+ 'characters or so. In some contexts, the first line is treated as the\n'
+ 'subject of the commit and the rest of the text as the body\n'
+ '\n\n'
+ 'Fixes #1',
valid: true,
errors: [],
},
{
name: 'message should be sentence cased',
message: 'fix error with something',
valid: false,
errors: ['header-case'],
},
{
name: 'message should not exceed 50 chars',
message: 'This is a long commit message which is not accepted by given rules',
valid: false,
errors: ['header-max-length'],
},
{
name: 'message should contain at least 10 chars',
message: 'Invalid',
valid: false,
errors: ['header-min-length'],
},
{
name: 'should not allow conventional commit type',
message: 'fix: error with something',
valid: false,
errors: ['type-empty', 'subject-empty', 'header-case'],
},
{
name: 'should not allow conventional commit with scope',
message: 'fix(scope): error message with type and scope',
valid: false,
errors: ['header-case', 'type-empty', 'scope-empty', 'subject-empty'],
},
{
name: 'body should have a leading blank line',
message: `Great commit summaries contain fewer than 50 chars
Body should have leading blank line to seperate from the subject
`,
valid: false,
errors: ['body-leading-blank'],
},
{
name: 'body should have a leading blank line',
message: 'Great commit summaries contain fewer than 50 chars'
+ '\n\n'
+ 'A detailed explanatory decscription on the change, should be wrapped within 72 characters',
valid: false,
errors: ['body-max-line-length'],
},
{
name: 'footer should have a leading blankline',
message: 'Great commit summaries contain fewer than 50 chars'
+ '\n\n'
+ 'A detailed explanatory decscription on the change'
+ '\n'
+ 'Fixes #1',
valid: false,
errors: ['footer-leading-blank'],
},
{
name: 'footer should have a leading blankline',
message: 'Great commit summaries contain fewer than 50 chars'
+ '\n\n'
+ 'A detailed explanatory decscription on the change'
+ '\n\n'
+ 'BREAKING CHANGE: Footer comesFooter sentence should not exceed 72 characters',
valid: false,
errors: ['footer-max-line-length'],
},
];
test.each(tests)('$name', async ({ message, ...t }) => {
const result = await lint(message, rules);
expect(result.valid).toBe(t.valid);
expect(t.errors.length).toEqual(result.errors.length);
const resultErrors = result.errors.map((err) => err.name);
expect(t.errors).toEqual(expect.arrayContaining(resultErrors));
});