-
Notifications
You must be signed in to change notification settings - Fork 933
/
Copy pathis-ignored.test.ts
207 lines (174 loc) Β· 6.13 KB
/
is-ignored.test.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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
import {test, expect} from 'vitest';
import isIgnored from './is-ignored.js';
const VERSION_MESSAGES = [
'0.0.1',
'0.1.0',
'1.0.0',
'0.0.1-alpha',
'0.0.1-some-crazy-tag',
'0.0.1-0',
'0.0.1-999',
'0.0.1-alpha.0',
'0.0.1-alpha.999',
'0.0.1-some-crazy-tag.0',
'0.0.1-some-crazy-tag.999',
'0.0.1-1e69d54',
'v0.0.1',
' v3.0.0',
];
const AMENDMENTS = [
'Signed-off-by: Developer <[email protected]>',
'Change-Id: I895114872a515a269487a683124b63303818e19c',
'Signed-off-by: Developer <[email protected]>\nChange-Id: I895114872a515a269487a683124b63303818e19c',
];
const AMENDED_VERSION_MESSAGES = VERSION_MESSAGES.reduce<string[]>(
(results, message) => {
return [
...results,
...AMENDMENTS.map((amendment) => `${message}\n\n${amendment}`),
];
},
[]
);
test('should return false when called without arguments', () => {
expect(isIgnored()).toBe(false);
});
test('should return false when called with empty string', () => {
expect(isIgnored('')).toBe(false);
});
test('should return false for normal commit', () => {
expect(isIgnored('initial commit')).toBe(false);
});
test('should return true for branch merges', () => {
expect(isIgnored("Merge branch 'iss53'")).toBe(true);
});
test('should return true for branch merges with newline characters', () => {
expect(isIgnored("Merge branch 'ctrom-YarnBuild'\n")).toBe(true);
expect(isIgnored("Merge branch 'ctrom-YarnBuild'\r\n")).toBe(true);
});
test('should return true for branch merges with multiple newline characters', () => {
expect(isIgnored("Merge branch 'ctrom-YarnBuild'\n\n\n")).toBe(true);
expect(isIgnored("Merge branch 'ctrom-YarnBuild'\r\n\r\n\r\n")).toBe(true);
});
test('should return true for merged PRs', () => {
expect(isIgnored('Merge pull request #369')).toBe(true);
});
test('should return true for branch merges with newline characters and more characters after it', () => {
expect(isIgnored("Merge branch 'ctrom-YarnBuild'\n ")).toBe(true);
expect(isIgnored("Merge branch 'ctrom-YarnBuild'\r\n # some comment")).toBe(
true
);
});
test('should return true for tag merges', () => {
expect(isIgnored("Merge tag '1.1.1'")).toBe(true);
expect(isIgnored("Merge tag 'a tag'")).toBe(true);
});
test('should return true for tag merges with newline characters', () => {
expect(isIgnored("Merge tag '1.1.1'\n")).toBe(true);
expect(isIgnored("Merge tag '1.1.1'\r\n")).toBe(true);
});
test('should return true for tag merges with multiple newline characters', () => {
expect(isIgnored("Merge tag '1.1.1'\n\n\n")).toBe(true);
expect(isIgnored("Merge tag '1.1.1'\r\n\r\n\r\n")).toBe(true);
});
test('should return true for tag merges with newline characters and more characters after it', () => {
expect(isIgnored("Merge tag '1.1.1'\n ")).toBe(true);
expect(isIgnored("Merge tag '1.1.1'\r\n # some comment")).toBe(true);
});
test('should return true for revert commits', () => {
expect(
isIgnored(
`Revert "docs: add recipe for linting of all commits in a PR (#36)"\n\nThis reverts commit 1e69d542c16c2a32acfd139e32efa07a45f19111.`
)
).toBe(true);
expect(
isIgnored(
`revert "docs: add recipe for linting of all commits in a PR (#36)"\n\nThis reverts commit 1e69d542c16c2a32acfd139e32efa07a45f19111.`
)
).toBe(true);
});
test('should ignore npm semver commits', () => {
VERSION_MESSAGES.forEach((message) => expect(isIgnored(message)).toBe(true));
});
test('should ignore npm semver commits with chore', () => {
VERSION_MESSAGES.forEach((message) =>
expect(isIgnored(`chore: ${message}`)).toBe(true)
);
VERSION_MESSAGES.forEach((message) =>
expect(isIgnored(`chore(release): ${message}`)).toBe(true)
);
});
test('should ignore npm semver commits with footers', () => {
AMENDED_VERSION_MESSAGES.forEach((message) =>
expect(isIgnored(message)).toBe(true)
);
});
test('should return true amend commits', () => {
expect(isIgnored('amend! initial commit')).toBe(true);
});
test('should return true fixup commits', () => {
expect(isIgnored('fixup! initial commit')).toBe(true);
});
test('should return true squash commits', () => {
expect(isIgnored('squash! initial commit')).toBe(true);
});
test('should return true for bitbucket merge commits', () => {
expect(
isIgnored('Merged in feature/facebook-friends-sync (pull request #8)')
).toBe(true);
expect(
isIgnored('Merged develop into feature/component-form-select-card')
).toBe(true);
expect(isIgnored('Automatic merge')).toBe(true);
});
test('should return true for automatic merge commits', () => {
expect(isIgnored('Auto-merged develop into master')).toBe(true);
expect(isIgnored('Merge remote-tracking branch')).toBe(true);
});
test('should return true for azure devops merge commits', () => {
expect(isIgnored('Merged PR 123: Description here')).toBe(true);
});
test('should return false for commits containing, but not starting, with merge branch', () => {
expect(isIgnored('foo bar Merge branch xxx')).toBe(false);
});
test('should return false for commits containing, but not starting, with merge tag', () => {
expect(isIgnored("foo bar Merge tag '1.1.1'")).toBe(false);
});
test('should return false for ignored message if defaults is false', () => {
expect(
isIgnored('Auto-merged develop into master', {
defaults: false,
})
).toBe(false);
});
test('should return false for ignored message if custom ignores and defaults is false', () => {
expect(
isIgnored('Auto-merged develop into master', {
defaults: false,
})
).toBe(false);
});
test('should throw error if ignores is not an array', () => {
const ignoredString = 'this should be ignored';
expect(() => {
isIgnored(ignoredString, {
ignores: 'throws error',
} as any);
}).toThrow('ignores must be of type array, received ');
});
test('should return true for custom ignores as function', () => {
const ignoredString = 'this should be ignored';
expect(
isIgnored(ignoredString, {
ignores: [(c) => c === ignoredString],
})
).toBe(true);
});
test('should throw error if any element of ignores is not a function', () => {
const ignoredString = 'this should be ignored';
expect(() => {
isIgnored(ignoredString, {
ignores: ['throws error'],
} as any);
}).toThrow('ignores must be array of type function, received items of type:');
});