-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathmessage.test.ts
More file actions
249 lines (215 loc) · 8.02 KB
/
message.test.ts
File metadata and controls
249 lines (215 loc) · 8.02 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
/**
* Message test module.
*
* High-level test of the message shown to the user, based on changes to one or more files. This
* includes the action verb in a sentence, along with named files, but not the conventional commit
* prefix.
*/
import * as assert from "assert";
import { namedFilesDesc, oneChange } from "../../generate/message";
describe("Generate commit message for a single changed file", function () {
// Notes:
// - The command `git status --short` expects `XY` format but this is for
// `git diff-index` which is only `X`. Also there is just spaces between -
// no '->' symbol.
// - Impossible cases are not covered here, like renaming a file and the
// name and path are unchanged, or including two file names for an add
// line. But validation on at least file name is done.
describe("#oneChange", function () {
it("returns the appropriate commit message for a new file", function () {
assert.strictEqual(oneChange("A\tfoo.txt"), "create foo.txt");
// TODO: Maybe 'create foo.txt in bar', if the dir is not too long?
assert.strictEqual(oneChange("A\tbar/foo.txt"), "create foo.txt");
assert.strictEqual(oneChange("A\tfoo bar.txt"), "create 'foo bar.txt'");
assert.strictEqual(
oneChange("A\tfizz buzz/foo bar.txt"),
"create 'foo bar.txt'",
);
});
it("throws an error if no file path can be no generated", function () {
assert.throws(() => oneChange("A "));
});
it("returns the appropriate commit message for a modified file", function () {
assert.strictEqual(oneChange("M\tfoo.txt"), "update foo.txt");
assert.strictEqual(oneChange("M\tbar/foo.txt"), "update foo.txt");
});
it("returns the appropriate commit message for a deleted file", function () {
assert.strictEqual(oneChange("D\tfoo.txt"), "delete foo.txt");
assert.strictEqual(oneChange("D\tbar/foo.txt"), "delete foo.txt");
});
it("describes a file renamed in the same directory", function () {
assert.strictEqual(
oneChange("R\tfoo.txt\tbar.txt"),
"rename foo.txt to bar.txt",
);
assert.strictEqual(
oneChange("R\tfizz/foo.txt\tfizz/bar.txt"),
"rename foo.txt to bar.txt",
);
});
it("ignores percentage change in a renamed file", function () {
// We don't care about getting the percentage out in this project. So just
// make sure it does get ignored.
assert.strictEqual(
oneChange("R97\tfoo.txt\tbar.txt"),
"rename foo.txt to bar.txt",
);
});
it("describes a file moved out of the repo root to another directory", function () {
assert.strictEqual(
oneChange("R\tfoo.txt\tfizz/foo.txt"),
"move foo.txt to fizz",
);
assert.strictEqual(
oneChange("R\tfoo.txt\tfizz/buzz/foo.txt"),
"move foo.txt to fizz/buzz",
);
assert.strictEqual(
oneChange("R\tfoo.txt\tfizz buzz/foo.txt"),
"move foo.txt to 'fizz buzz'",
);
assert.strictEqual(
oneChange("R\tfoo bar.txt\tfizz/foo bar.txt"),
"move 'foo bar.txt' to fizz",
);
});
it("describes a file moved out of a subdirectory", function () {
assert.strictEqual(
oneChange("R\tfizz/buzz/foo.txt\tfoo.txt"),
"move foo.txt to repo root",
);
assert.strictEqual(
oneChange("R\tfizz/buzz/foo.txt\tfizz/foo.txt"),
"move foo.txt to fizz",
);
assert.strictEqual(
oneChange("R\tfizz/foo.txt\tfizz/buzz/foo.txt"),
"move foo.txt to fizz/buzz",
);
assert.strictEqual(
oneChange("R\tfizz/foo bar.txt\tfizz/buzz baz/foo bar.txt"),
"move 'foo bar.txt' to 'fizz/buzz baz'",
);
});
it("describes a file that was both moved and renamed", function () {
assert.strictEqual(
oneChange("R\tfoo.txt\tfizz/fuzz.txt"),
"move and rename foo.txt to fizz/fuzz.txt",
);
assert.strictEqual(
oneChange("R\tbar/foo.txt\tfuzz.txt"),
"move and rename foo.txt to fuzz.txt at repo root",
);
assert.strictEqual(
oneChange("R\tbar/foo.txt\tfizz/fuzz.txt"),
"move and rename foo.txt to fizz/fuzz.txt",
);
assert.strictEqual(
oneChange("R\tbar/foo.txt\tfizz/baz fuzz.txt"),
"move and rename foo.txt to 'fizz/baz fuzz.txt'",
);
});
it("ignores percentage changed value for a file that was both moved and renamed", function () {
assert.strictEqual(
oneChange("R97\tfoo.txt\tfizz/fuzz.txt"),
"move and rename foo.txt to fizz/fuzz.txt",
);
});
it("uses the full path to describe index files", function () {
assert.strictEqual(oneChange("A\tREADME.md"), "create README.md");
assert.strictEqual(oneChange("M\tREADME.md"), "update README.md");
assert.strictEqual(oneChange("D\tREADME.md"), "delete README.md");
assert.strictEqual(oneChange("A\tfoo/README.md"), "create foo/README.md");
assert.strictEqual(
oneChange("M\tbar/baz/README.md"),
"update bar/baz/README.md",
);
assert.strictEqual(
oneChange("D\tbar/baz/buzz/README.md"),
"delete bar/baz/buzz/README.md",
);
assert.strictEqual(oneChange("A\tfoo/index.md"), "create foo/index.md");
assert.strictEqual(
oneChange("A\tfoo/index bazz.md"),
"create 'foo/index bazz.md'",
);
assert.strictEqual(oneChange("A\tfoo/index.js"), "create foo/index.js");
});
});
});
describe("Generate description for a few changed files which each get named", function () {
describe("#namedFilesDesc", function () {
it("return the appropriate commit message for two files", function () {
assert.strictEqual(
namedFilesDesc([
{ x: "A", from: "foo.txt", y: " ", to: "" },
{ x: "A", from: "bar.txt", y: " ", to: "" },
]),
"create foo.txt and bar.txt",
);
assert.strictEqual(
namedFilesDesc([
{ x: "A", from: "foo bar.txt", y: " ", to: "" },
{ x: "A", from: "fizz buzz.txt", y: " ", to: "" },
]),
"create 'foo bar.txt' and 'fizz buzz.txt'",
);
assert.strictEqual(
namedFilesDesc([
{ x: "M", from: "foo.txt", y: " ", to: "" },
{ x: "M", from: "bar.txt", y: " ", to: "" },
]),
"update foo.txt and bar.txt",
);
assert.strictEqual(
namedFilesDesc([
{ x: "M", from: "fizz.js", y: " ", to: "" },
{ x: "M", from: "buzz.ts", y: " ", to: "" },
]),
"update fizz.js and buzz.ts",
);
});
it("return a commit message for more than two files", function () {
assert.strictEqual(
namedFilesDesc([
{ x: "A", from: "foo.txt", y: " ", to: "" },
{ x: "A", from: "docs/bar.txt", y: " ", to: "" },
{ x: "A", from: "buzz.js", y: " ", to: "" },
]),
"create foo.txt, bar.txt and buzz.js",
);
assert.strictEqual(
namedFilesDesc([
{ x: "A", from: "foo.txt", y: " ", to: "" },
{ x: "A", from: "docs/bar fuzz.txt", y: " ", to: "" },
{ x: "A", from: "buzz.js", y: " ", to: "" },
]),
"create foo.txt, 'bar fuzz.txt' and buzz.js",
);
assert.strictEqual(
namedFilesDesc([
{ x: "D", from: "foo.txt", y: " ", to: "" },
{ x: "D", from: "docs/bar.txt", y: " ", to: "" },
{ x: "D", from: "buzz.js", y: " ", to: "" },
]),
"delete foo.txt, bar.txt and buzz.js",
);
});
it("handles differing actions", function () {
assert.strictEqual(
namedFilesDesc([
{ x: "A", from: "foo.txt", y: " ", to: "" },
{ x: "M", from: "bar.txt", y: " ", to: "" },
]),
"create 1 file and update 1 file",
);
assert.strictEqual(
namedFilesDesc([
{ x: "M", from: "foo.txt", y: " ", to: "" },
{ x: "D", from: "bar.txt", y: " ", to: "" },
]),
"update 1 file and delete 1 file",
);
});
});
});