-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathconvCommit.test.ts
More file actions
350 lines (309 loc) · 9.23 KB
/
convCommit.test.ts
File metadata and controls
350 lines (309 loc) · 9.23 KB
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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
/**
* Conventional commit test module.
*
* Test the categorization of changed files as conventional commit types.
*/
import * as assert from "assert";
import {
ConventionalCommit,
getConventionType,
} from "../../generate/convCommit";
import { ACTION, CONVENTIONAL_TYPE } from "../../lib/constants";
test("Test #ConventionalCommit class for path-based conventional commit logic", function () {
test("#isDocsRelated", function () {
test("determines that a README file is a doc", function () {
assert.strictEqual(
new ConventionalCommit("README.md").isDocsRelated(),
true
);
assert.strictEqual(
new ConventionalCommit("README.rst").isDocsRelated(),
true
);
assert.strictEqual(
new ConventionalCommit("Readme.txt").isDocsRelated(),
true
);
assert.strictEqual(
new ConventionalCommit("readme").isDocsRelated(),
true
);
assert.strictEqual(
new ConventionalCommit("FEEDME.md").isDocsRelated(),
false
);
});
test("determines that a CONTRIBUTING file is a doc", function () {
assert.strictEqual(
new ConventionalCommit("CONTRIBUTING.md").isDocsRelated(),
true
);
assert.strictEqual(
new ConventionalCommit("contributing.md").isDocsRelated(),
true
);
});
test("determines that a `.rst` file is a doc", function () {
assert.strictEqual(
new ConventionalCommit("README.rst").isDocsRelated(),
true
);
assert.strictEqual(
new ConventionalCommit("foo.rst").isDocsRelated(),
true
);
});
test("determines a file in the docs directory is a doc", function () {
assert.strictEqual(
new ConventionalCommit("docs/fizz.md").isDocsRelated(),
true
);
assert.strictEqual(
new ConventionalCommit("docs/foo.img").isDocsRelated(),
true
);
assert.strictEqual(
new ConventionalCommit("docs/fizz/foo.img").isDocsRelated(),
true
);
assert.strictEqual(
new ConventionalCommit("fuzz/fizz.md").isDocsRelated(),
false
);
});
});
test("#isBuildRelated", function () {
test("can recognize a build change for a build-related filename", function () {
assert.strictEqual(
new ConventionalCommit("Dockerfile").isBuildRelated(),
true
);
assert.strictEqual(
new ConventionalCommit("foo/Dockerfile").isBuildRelated(),
true
);
assert.strictEqual(
new ConventionalCommit("foo.txt").isBuildRelated(),
false
);
assert.strictEqual(
new ConventionalCommit("fizz/foo.txt").isBuildRelated(),
false
);
});
});
test("#isCIRelated", function () {
test("can tell a CI change is in a CircleCI directory", function () {
assert.strictEqual(
new ConventionalCommit(".circleci/foo.txt").isCIRelated(),
true
);
assert.strictEqual(
new ConventionalCommit("foo.txt").isCIRelated(),
false
);
assert.strictEqual(
new ConventionalCommit("fizz/foo.txt").isCIRelated(),
false
);
});
test("can tell a CI change is in a workflows directory", function () {
assert.strictEqual(
new ConventionalCommit(".github/workflows/foo.txt").isCIRelated(),
true
);
assert.strictEqual(
new ConventionalCommit("foo.txt").isCIRelated(),
false
);
assert.strictEqual(
new ConventionalCommit(".github/foo.txt").isCIRelated(),
false
);
});
test("can tell a CI change for a CI filename", function () {
assert.strictEqual(
new ConventionalCommit("netlify.toml").isCIRelated(),
true
);
assert.strictEqual(
new ConventionalCommit("foo/netlify.toml").isCIRelated(),
true
);
assert.strictEqual(
new ConventionalCommit("foo.txt").isCIRelated(),
false
);
});
});
test("#isTestRelated", function () {
test("can tell a test directory is for tests", function () {
assert.strictEqual(
new ConventionalCommit("test/foo.js").isTestRelated(),
true
);
assert.strictEqual(
new ConventionalCommit("tests/foo.js").isTestRelated(),
true
);
assert.strictEqual(
new ConventionalCommit("spec/foo.js").isTestRelated(),
true
);
assert.strictEqual(
new ConventionalCommit("unit_tests/foo.js").isTestRelated(),
true
);
});
test("can tell a test file is for tests", function () {
assert.strictEqual(
new ConventionalCommit("foo/bar.test.js").isTestRelated(),
true
);
assert.strictEqual(
new ConventionalCommit("foo/test_bar.js").isTestRelated(),
true
);
});
});
test("#getType", function () {
// Rather than true and false like in above tests this actually categorizes
// and also it closer to the real world as it through a hierarchy (for
// example .yml is config-related unless it is for a CI file). But, this
// doesn't care what the action is like create or delete or modify, so it
// won't impose meaning based on that.
test("sees a build file as build", function () {
assert.strictEqual(
new ConventionalCommit("Makefile").getType(),
CONVENTIONAL_TYPE.BUILD
);
assert.strictEqual(
new ConventionalCommit("Dockerfile").getType(),
CONVENTIONAL_TYPE.BUILD
);
assert.strictEqual(
new ConventionalCommit("foo.gemspec").getType(),
CONVENTIONAL_TYPE.BUILD
);
assert.strictEqual(
new ConventionalCommit("package.json").getType(),
CONVENTIONAL_TYPE.BUILD
);
});
test("sees a dependency-related file as 'build' and with dependency scope", function () {
assert.strictEqual(
new ConventionalCommit("Gemfile").getType(),
CONVENTIONAL_TYPE.BUILD_DEPENDENCIES
);
assert.strictEqual(
new ConventionalCommit("package-lock.json").getType(),
CONVENTIONAL_TYPE.BUILD_DEPENDENCIES
);
assert.strictEqual(
new ConventionalCommit("requirements.txt").getType(),
CONVENTIONAL_TYPE.BUILD_DEPENDENCIES
);
assert.strictEqual(
new ConventionalCommit("requirements-dev.txt").getType(),
CONVENTIONAL_TYPE.BUILD_DEPENDENCIES
);
});
// TODO: Break into categories
test("can tell a type for other types", function () {
assert.strictEqual(
new ConventionalCommit("foo").getType(),
CONVENTIONAL_TYPE.UNKNOWN
);
assert.strictEqual(
new ConventionalCommit("test/foo.js").getType(),
CONVENTIONAL_TYPE.TEST
);
assert.strictEqual(
new ConventionalCommit(".github/workflows/foo.yml").getType(),
CONVENTIONAL_TYPE.CI
);
assert.strictEqual(
new ConventionalCommit("README.md").getType(),
CONVENTIONAL_TYPE.DOCS
);
assert.strictEqual(
new ConventionalCommit("LICENSE").getType(),
CONVENTIONAL_TYPE.CHORE
);
});
});
});
test("#getConventionType", function () {
test("uses feat for a new file if no other match is found", function () {
const add = ACTION.A;
assert.strictEqual(
getConventionType(add, "README.md"),
CONVENTIONAL_TYPE.DOCS
);
assert.strictEqual(
getConventionType(add, "tests/foo.js"),
CONVENTIONAL_TYPE.TEST
);
assert.strictEqual(
getConventionType(add, "foo.txt"),
CONVENTIONAL_TYPE.FEAT
);
});
test("knows a deleted file is always a chore", function () {
const del = ACTION.D;
assert.strictEqual(
getConventionType(del, "foo.txt"),
CONVENTIONAL_TYPE.CHORE
);
assert.strictEqual(
getConventionType(del, "README.md"),
CONVENTIONAL_TYPE.CHORE
);
assert.strictEqual(
getConventionType(del, "tests/foo.js"),
CONVENTIONAL_TYPE.CHORE
);
});
test("knows a renamed or moved file is always chore", function () {
const renameOrMove = ACTION.R;
assert.strictEqual(
getConventionType(renameOrMove, "foo.txt"),
CONVENTIONAL_TYPE.CHORE
);
assert.strictEqual(
getConventionType(renameOrMove, "fuzz/foo.txt"),
CONVENTIONAL_TYPE.CHORE
);
assert.strictEqual(
getConventionType(renameOrMove, "README.md"),
CONVENTIONAL_TYPE.CHORE
);
assert.strictEqual(
getConventionType(renameOrMove, "docs/foo.txt"),
CONVENTIONAL_TYPE.CHORE
);
assert.strictEqual(
getConventionType(renameOrMove, "tests/foo.js"),
CONVENTIONAL_TYPE.CHORE
);
});
test("uses conventional commit type from path for a modified file, or leaves unset", function () {
const modified = ACTION.M;
assert.strictEqual(
getConventionType(modified, "foo.txt"),
CONVENTIONAL_TYPE.UNKNOWN
);
assert.strictEqual(
getConventionType(modified, "fizz/foo.txt"),
CONVENTIONAL_TYPE.UNKNOWN
);
assert.strictEqual(
getConventionType(modified, "README.md"),
CONVENTIONAL_TYPE.DOCS
);
assert.strictEqual(
getConventionType(modified, "tests/foo.js"),
CONVENTIONAL_TYPE.TEST
);
});
});