forked from conventional-changelog/commitlint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.test.js
236 lines (209 loc) · 5.9 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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
import importFrom from 'import-from';
import test from 'ava';
import parse from '.';
test('throws when called without params', async t => {
const error = await t.throws(parse());
t.is(error.message, 'Expected a raw commit');
});
test('throws when called with empty message', async t => {
const error = await t.throws(parse());
t.is(error.message, 'Expected a raw commit');
});
test('returns object with raw message', async t => {
const message = 'type(scope): subject';
const actual = await parse(message);
t.is(actual.raw, message);
});
test('calls parser with message and passed options', async t => {
const message = 'message';
await parse(message, m => {
t.is(message, m);
return {};
});
});
test('passes object up from parser function', async t => {
const message = 'message';
const result = {};
const actual = await parse(message, () => result);
t.is(actual, result);
});
test('returns object with expected keys', async t => {
const message = 'message';
const actual = await parse(message);
const expected = {
body: null,
footer: null,
header: 'message',
mentions: [],
merge: null,
notes: [],
raw: 'message',
references: [],
revert: null,
scope: null,
subject: null,
type: null
};
t.deepEqual(actual, expected);
});
test('uses angular grammar', async t => {
const message = 'type(scope): subject';
const actual = await parse(message);
const expected = {
body: null,
footer: null,
header: 'type(scope): subject',
mentions: [],
merge: null,
notes: [],
raw: 'type(scope): subject',
references: [],
revert: null,
scope: 'scope',
subject: 'subject',
type: 'type'
};
t.deepEqual(actual, expected);
});
test('uses custom opts parser', async t => {
const message = 'type(scope)-subject';
const changelogOpts = await importFrom(
process.cwd(),
'./fixtures/parser-preset/conventional-changelog-custom'
);
const actual = await parse(message, undefined, changelogOpts.parserOpts);
const expected = {
body: null,
footer: null,
header: 'type(scope)-subject',
mentions: [],
merge: null,
notes: [],
raw: 'type(scope)-subject',
references: [],
revert: null,
scope: 'scope',
subject: 'subject',
type: 'type'
};
t.deepEqual(actual, expected);
});
test('does not merge array properties with custom opts', async t => {
const message = 'type: subject';
const actual = await parse(message, undefined, {
headerPattern: /^(.*):\s(.*)$/,
headerCorrespondence: ['type', 'subject']
});
const expected = {
body: null,
footer: null,
header: 'type: subject',
mentions: [],
merge: null,
notes: [],
raw: 'type: subject',
references: [],
revert: null,
subject: 'subject',
type: 'type'
};
t.deepEqual(actual, expected);
});
test('supports scopes with /', async t => {
const message = 'type(some/scope): subject';
const actual = await parse(message);
t.is(actual.scope, 'some/scope');
t.is(actual.subject, 'subject');
});
test('supports scopes with / and empty parserOpts', async t => {
const message = 'type(some/scope): subject';
const actual = await parse(message, undefined, {});
t.is(actual.scope, 'some/scope');
t.is(actual.subject, 'subject');
});
test('ignores comments', async t => {
const message = 'type(some/scope): subject\n# some comment';
const changelogOpts = await importFrom(
process.cwd(),
'conventional-changelog-angular'
);
const opts = Object.assign({}, changelogOpts.parserOpts, {
commentChar: '#'
});
const actual = await parse(message, undefined, opts);
t.is(actual.body, null);
t.is(actual.footer, null);
t.is(actual.subject, 'subject');
});
test('registers inline #', async t => {
const message =
'type(some/scope): subject #reference\n# some comment\nthings #reference';
const changelogOpts = await importFrom(
process.cwd(),
'conventional-changelog-angular'
);
const opts = Object.assign({}, changelogOpts.parserOpts, {
commentChar: '#'
});
const actual = await parse(message, undefined, opts);
t.is(actual.subject, 'subject #reference');
t.is(actual.body, 'things #reference');
});
test('parses references leading subject', async t => {
const message = '#1 some subject';
const opts = await importFrom(
process.cwd(),
'conventional-changelog-angular'
);
const {
references: [actual]
} = await parse(message, undefined, opts);
t.is(actual.issue, '1');
});
test('parses custom references', async t => {
const message = '#1 some subject PREFIX-2';
const {references} = await parse(message, undefined, {
issuePrefixes: ['PREFIX-']
});
t.falsy(references.find(ref => ref.issue === '1'));
t.deepEqual(references.find(ref => ref.issue === '2'), {
action: null,
issue: '2',
owner: null,
prefix: 'PREFIX-',
raw: '#1 some subject PREFIX-2',
repository: null
});
});
test('uses permissive default regex without parser opts', async t => {
const message = 'chore(component,demo): bump';
const actual = await parse(message);
t.is(actual.scope, 'component,demo');
});
test('uses permissive default regex with other parser opts', async t => {
const message = 'chore(component,demo): bump';
const actual = await parse(message, undefined, {commentChar: '#'});
t.is(actual.scope, 'component,demo');
});
test('uses restrictive default regex in passed parser opts', async t => {
const message = 'chore(component,demo): bump';
const actual = await parse(message, undefined, {
headerPattern: /^(\w*)(?:\(([a-z]*)\))?: (.*)$/
});
t.is(actual.subject, null);
t.is(actual.scope, null);
});
test('works with chinese scope by default', async t => {
const message = 'fix(面试评价): 测试';
const actual = await parse(message, undefined, {commentChar: '#'});
t.not(actual.subject, null);
t.not(actual.scope, null);
});
test('does not work with chinese scopes with incompatible pattern', async t => {
const message = 'fix(面试评价): 测试';
const actual = await parse(message, undefined, {
headerPattern: /^(\w*)(?:\(([a-z]*)\))?: (.*)$/
});
t.is(actual.subject, null);
t.is(actual.scope, null);
});