-
Notifications
You must be signed in to change notification settings - Fork 934
/
Copy pathparse.test.js
122 lines (110 loc) · 2.89 KB
/
parse.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
import importFrom from 'import-from';
import test from 'ava';
import parse from './parse';
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('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('ignores comments', async t => {
const message = 'type(some/scope): subject\n# some comment';
const actual = await parse(message);
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 actual = await parse(message);
t.is(actual.subject, 'subject #reference');
t.is(actual.body, 'things #reference');
});