-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.test.js
217 lines (187 loc) · 5.91 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
import lint from '@commitlint/lint';
import {rules, parserPreset, ignores} from '.';
const commitLint = async (message) => {
const preset = await require(parserPreset)();
return lint(message, rules, {...preset, ignores });
};
const messages = {
invalidTypeEnum: 'foo: some message',
invalidTypeCase: 'FIX: some message',
invalidTypeEmpty: ': some message',
invalidSubjectCases: [
'fix(scope): Some message',
'fix(scope): Some Message',
'fix(scope): SomeMessage',
'fix(scope): SOMEMESSAGE',
],
invalidSubjectEmpty: 'fix:',
invalidSubjectFullStop: 'fix: some message.',
invalidHeaderMaxLength:
'fix: some message that is way too long and breaks the line max-length by several characters since the max is 100',
warningFooterLeadingBlank:
'fix: some message\n\nbody\nBREAKING CHANGE: It will be significant',
invalidFooterMaxLineLength:
'fix: some message\n\nbody\n\nBREAKING CHANGE: footer with multiple lines\nhas a message that is way too long and will break the line rule "line-max-length" by several characters',
warningBodyLeadingBlank: 'fix: some message\nbody',
invalidBodyMaxLineLength:
'fix: some message\n\nbody with multiple lines\nhas a message that is way too long and will break the line rule "line-max-length" by several characters',
invalidWipMessage: 'wip: some message',
validMessages: [
'fix: some message',
'fix(scope): some message',
'fix(scope): some Message',
'fix(scope): some message\n\nBREAKING CHANGE: it will be significant!',
'fix(scope): some message\n\nbody',
'fix(scope)!: some message\n\nbody',
'wip',
'WIP'
],
};
const errors = {
typeEnum: {
level: 2,
message:
'type must be one of [build, chore, ci, docs, feat, fix, perf, refactor, revert, style, test]',
name: 'type-enum',
valid: false,
},
typeCase: {
level: 2,
message: 'type must be lower-case',
name: 'type-case',
valid: false,
},
typeEmpty: {
level: 2,
message: 'type may not be empty',
name: 'type-empty',
valid: false,
},
subjectCase: {
level: 2,
message:
'subject must not be sentence-case, start-case, pascal-case, upper-case',
name: 'subject-case',
valid: false,
},
subjectEmpty: {
level: 2,
message: 'subject may not be empty',
name: 'subject-empty',
valid: false,
},
subjectFullStop: {
level: 2,
message: 'subject may not end with full stop',
name: 'subject-full-stop',
valid: false,
},
headerMaxLength: {
level: 2,
message:
'header must not be longer than 100 characters, current length is 112',
name: 'header-max-length',
valid: false,
},
footerMaxLineLength: {
level: 2,
message: "footer's lines must not be longer than 100 characters",
name: 'footer-max-line-length',
valid: false,
},
bodyMaxLineLength: {
level: 2,
message: "body's lines must not be longer than 100 characters",
name: 'body-max-line-length',
valid: false,
},
};
const warnings = {
footerLeadingBlank: {
level: 1,
message: 'footer must have leading blank line',
name: 'footer-leading-blank',
valid: false,
},
bodyLeadingBlank: {
level: 1,
message: 'body must have leading blank line',
name: 'body-leading-blank',
valid: false,
},
};
test('type-enum', async () => {
const result = await commitLint(messages.invalidTypeEnum);
expect(result.valid).toBe(false);
expect(result.errors).toEqual([errors.typeEnum]);
});
test('type-case', async () => {
const result = await commitLint(messages.invalidTypeCase);
expect(result.valid).toBe(false);
expect(result.errors).toEqual([errors.typeCase, errors.typeEnum]);
});
test('type-empty', async () => {
const result = await commitLint(messages.invalidTypeEmpty);
expect(result.valid).toBe(false);
expect(result.errors).toEqual([errors.typeEmpty]);
});
test('subject-case', async () => {
const invalidInputs = await Promise.all(
messages.invalidSubjectCases.map((invalidInput) => commitLint(invalidInput))
);
invalidInputs.forEach((result) => {
expect(result.valid).toBe(false);
expect(result.errors).toEqual([errors.subjectCase]);
});
});
test('subject-empty', async () => {
const result = await commitLint(messages.invalidSubjectEmpty);
expect(result.valid).toBe(false);
expect(result.errors).toEqual([errors.subjectEmpty, errors.typeEmpty]);
});
test('subject-full-stop', async () => {
const result = await commitLint(messages.invalidSubjectFullStop);
expect(result.valid).toBe(false);
expect(result.errors).toEqual([errors.subjectFullStop]);
});
test('header-max-length', async () => {
const result = await commitLint(messages.invalidHeaderMaxLength);
expect(result.valid).toBe(false);
expect(result.errors).toEqual([errors.headerMaxLength]);
});
test('footer-leading-blank', async () => {
const result = await commitLint(messages.warningFooterLeadingBlank, rules);
expect(result.valid).toBe(true);
expect(result.warnings).toEqual([warnings.footerLeadingBlank]);
});
test('footer-max-line-length', async () => {
const result = await commitLint(messages.invalidFooterMaxLineLength);
expect(result.valid).toBe(false);
expect(result.errors).toEqual([errors.footerMaxLineLength]);
});
test('body-leading-blank', async () => {
const result = await commitLint(messages.warningBodyLeadingBlank);
expect(result.valid).toBe(true);
expect(result.warnings).toEqual([warnings.bodyLeadingBlank]);
});
test('body-max-line-length', async () => {
const result = await commitLint(messages.invalidBodyMaxLineLength);
expect(result.valid).toBe(false);
expect(result.errors).toEqual([errors.bodyMaxLineLength]);
});
test('invalid wip message', async () => {
const result = await commitLint(messages.invalidWipMessage);
expect(result.valid).toBe(false);
expect(result.errors).toEqual([errors.typeEnum]);
});
test('valid messages', async () => {
const validInputs = await Promise.all(
messages.validMessages.map((input) => commitLint(input))
);
validInputs.forEach((result) => {
console.log(result)
expect(result.valid).toBe(true);
expect(result.errors).toEqual([]);
expect(result.warnings).toEqual([]);
});
});