forked from angular/angular
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparse.spec.ts
190 lines (160 loc) · 6.96 KB
/
parse.spec.ts
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
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import {parseCommitMessage} from './parse';
import {commitMessageBuilder, CommitMessageParts} from './test-util';
const commitValues: CommitMessageParts = {
prefix: '',
type: 'fix',
npmScope: '',
scope: 'changed-area',
summary: 'This is a short summary of the change',
body: 'This is a longer description of the change',
footer: 'Closes #1',
};
const buildCommitMessage = commitMessageBuilder(commitValues);
describe('commit message parsing:', () => {
describe('parses the scope', () => {
it('when only a scope is defined', () => {
const message = buildCommitMessage();
expect(parseCommitMessage(message).scope).toBe(commitValues.scope);
expect(parseCommitMessage(message).npmScope).toBe('');
});
it('when an npmScope and scope are defined', () => {
const message = buildCommitMessage({npmScope: 'myNpmPackage'});
expect(parseCommitMessage(message).scope).toBe(commitValues.scope);
expect(parseCommitMessage(message).npmScope).toBe('myNpmPackage');
});
});
it('parses the type', () => {
const message = buildCommitMessage();
expect(parseCommitMessage(message).type).toBe(commitValues.type);
});
it('parses the header', () => {
const message = buildCommitMessage();
expect(parseCommitMessage(message).header)
.toBe(`${commitValues.type}(${commitValues.scope}): ${commitValues.summary}`);
});
it('parses the body', () => {
const message = buildCommitMessage();
expect(parseCommitMessage(message).body).toBe(commitValues.body);
});
it('parses the subject', () => {
const message = buildCommitMessage();
expect(parseCommitMessage(message).subject).toBe(commitValues.summary);
});
it('identifies if a commit is a fixup', () => {
const message1 = buildCommitMessage();
expect(parseCommitMessage(message1).isFixup).toBe(false);
const message2 = buildCommitMessage({prefix: 'fixup! '});
expect(parseCommitMessage(message2).isFixup).toBe(true);
});
it('identifies if a commit is a revert', () => {
const message1 = buildCommitMessage();
expect(parseCommitMessage(message1).isRevert).toBe(false);
const message2 = buildCommitMessage({prefix: 'revert: '});
expect(parseCommitMessage(message2).isRevert).toBe(true);
const message3 = buildCommitMessage({prefix: 'revert '});
expect(parseCommitMessage(message3).isRevert).toBe(true);
});
it('identifies if a commit is a squash', () => {
const message1 = buildCommitMessage();
expect(parseCommitMessage(message1).isSquash).toBe(false);
const message2 = buildCommitMessage({prefix: 'squash! '});
expect(parseCommitMessage(message2).isSquash).toBe(true);
});
it('ignores comment lines', () => {
const message = buildCommitMessage({
prefix: '# This is a comment line before the header.\n' +
'## This is another comment line before the headers.\n',
body: '# This is a comment line befor the body.\n' +
'This is line 1 of the actual body.\n' +
'## This is another comment line inside the body.\n' +
'This is line 2 of the actual body (and it also contains a # but it not a comment).\n' +
'### This is yet another comment line after the body.\n',
});
const parsedMessage = parseCommitMessage(message);
expect(parsedMessage.header)
.toBe(`${commitValues.type}(${commitValues.scope}): ${commitValues.summary}`);
expect(parsedMessage.body)
.toBe(
'This is line 1 of the actual body.\n' +
'This is line 2 of the actual body (and it also contains a # but it not a comment).');
});
describe('parses breaking change notes', () => {
const summary = 'This breaks things';
const description = 'This is how it breaks things.';
it('when only a summary is provided', () => {
const message = buildCommitMessage({
footer: `BREAKING CHANGE: ${summary}`,
});
const parsedMessage = parseCommitMessage(message);
expect(parsedMessage.breakingChanges[0].text).toBe(summary);
expect(parsedMessage.breakingChanges.length).toBe(1);
});
it('when only a description is provided', () => {
const message = buildCommitMessage({
footer: `BREAKING CHANGE:\n\n${description}`,
});
const parsedMessage = parseCommitMessage(message);
expect(parsedMessage.breakingChanges[0].text).toBe(description);
expect(parsedMessage.breakingChanges.length).toBe(1);
});
it('when a summary and description are provied', () => {
const message = buildCommitMessage({
footer: `BREAKING CHANGE: ${summary}\n\n${description}`,
});
const parsedMessage = parseCommitMessage(message);
expect(parsedMessage.breakingChanges[0].text).toBe(`${summary}\n\n${description}`);
expect(parsedMessage.breakingChanges.length).toBe(1);
});
it('only when keyword is at the beginning of a line', () => {
const message = buildCommitMessage({
body: 'This changes how the `BREAKING CHANGE: ` commit message note\n' +
'keyword is detected for the changelog.',
});
const parsedMessage = parseCommitMessage(message);
expect(parsedMessage.breakingChanges.length).toBe(0);
});
});
describe('parses deprecation notes', () => {
const summary = 'This will break things later';
const description = 'This is a long winded explanation of why it \nwill break things later.';
it('when only a summary is provided', () => {
const message = buildCommitMessage({
footer: `DEPRECATED: ${summary}`,
});
const parsedMessage = parseCommitMessage(message);
expect(parsedMessage.deprecations[0].text).toBe(summary);
expect(parsedMessage.deprecations.length).toBe(1);
});
it('when only a description is provided', () => {
const message = buildCommitMessage({
footer: `DEPRECATED:\n\n${description}`,
});
const parsedMessage = parseCommitMessage(message);
expect(parsedMessage.deprecations[0].text).toBe(description);
expect(parsedMessage.deprecations.length).toBe(1);
});
it('when a summary and description are provied', () => {
const message = buildCommitMessage({
footer: `DEPRECATED: ${summary}\n\n${description}`,
});
const parsedMessage = parseCommitMessage(message);
expect(parsedMessage.deprecations[0].text).toBe(`${summary}\n\n${description}`);
expect(parsedMessage.deprecations.length).toBe(1);
});
it('only when keyword is at the beginning of a line', () => {
const message = buildCommitMessage({
body: 'This changes how the `DEPRECATED: ` commit message note\n' +
'keyword is detected for the changelog.',
});
const parsedMessage = parseCommitMessage(message);
expect(parsedMessage.deprecations.length).toBe(0);
});
});
});