Skip to content

Commit 5a29b84

Browse files
committed
test: update prepareCommitMsg.test.ts
1 parent 5bec64b commit 5a29b84

1 file changed

Lines changed: 66 additions & 29 deletions

File tree

src/test/prepareCommitMsg.test.ts

Lines changed: 66 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
_msgFromChanges,
1919
_msgNamed,
2020
_newMsg,
21-
_prefixFromChange,
21+
_prefixFromChange
2222
} from "../prepareCommitMsg";
2323
import { ConvCommitMsg } from "../prepareCommitMsg.d";
2424

@@ -54,9 +54,14 @@ describe("Find prefix from Git output", function () {
5454
_prefixFromChange("A\tfoo.txt"),
5555
CONVENTIONAL_TYPE.FEAT
5656
);
57+
58+
assert.strictEqual(
59+
_prefixFromChange("A\tfoo bar.txt"),
60+
CONVENTIONAL_TYPE.FEAT
61+
);
5762
});
5863

59-
it("recognizes a modified generic file as a unknown", function () {
64+
it("recognizes a modified generic file as an unknown", function () {
6065
assert.strictEqual(
6166
_prefixFromChange("M\tfoo.txt"),
6267
CONVENTIONAL_TYPE.UNKNOWN
@@ -86,7 +91,7 @@ describe("Find prefix from Git output", function () {
8691
});
8792

8893
describe("categorized file change", function () {
89-
/// Don't need to cover every type here - just docs should be fine.
94+
// Don't need to cover every type here - just docs should be fine.
9095

9196
it("recognizes a new docs file change as docs", function () {
9297
const expected = CONVENTIONAL_TYPE.DOCS;
@@ -112,21 +117,22 @@ describe("Find prefix from Git output", function () {
112117
it("recognizes a renamed docs file change as chore", function () {
113118
const expected = CONVENTIONAL_TYPE.CHORE;
114119

115-
assert.strictEqual(_prefixFromChange("R\tREADME.md bar.md"), expected);
120+
assert.strictEqual(_prefixFromChange("R\tREADME.md\tbar.md"), expected);
121+
116122
assert.strictEqual(
117-
_prefixFromChange("R\tdocs/foo.md docs/bar.md"),
123+
_prefixFromChange("R\tdocs/foo.md\tdocs/bar.md"),
118124
expected
119125
);
120126
});
121127
it("recognizes a moved docs file change as chore", function () {
122128
const expected = CONVENTIONAL_TYPE.CHORE;
123129

124130
assert.strictEqual(
125-
_prefixFromChange("R\tREADME.md bar/README.md"),
131+
_prefixFromChange("R\tREADME.md\tbar/README.md"),
126132
expected
127133
);
128134
assert.strictEqual(
129-
_prefixFromChange("R\tdocs/foo.md bar/foo.md"),
135+
_prefixFromChange("R\tdocs/foo.md\tbar/foo.md"),
130136
expected
131137
);
132138
});
@@ -149,7 +155,7 @@ describe("Find prefix from Git output", function () {
149155
const expected = CONVENTIONAL_TYPE.CHORE;
150156

151157
assert.strictEqual(
152-
_prefixFromChange("R\tpackage-lock.json foo.json"),
158+
_prefixFromChange("R\tpackage-lock.json\tfoo.json"),
153159
expected
154160
);
155161
});
@@ -158,7 +164,7 @@ describe("Find prefix from Git output", function () {
158164
const expected = CONVENTIONAL_TYPE.CHORE;
159165

160166
assert.strictEqual(
161-
_prefixFromChange("R\tpackage-lock.json foo/package-lock.json"),
167+
_prefixFromChange("R\tpackage-lock.json\tfoo/package-lock.json"),
162168
expected
163169
);
164170
});
@@ -314,17 +320,33 @@ describe("Prepare commit message", function () {
314320
});
315321

316322
it("handles 3 README.md files in different locations as full paths", function () {
317-
const lines = [
318-
"M\tdocs/README.md",
319-
"M\tbar/README.md",
320-
"M\tREADME.md",
321-
];
322-
const expected = {
323-
typePrefix: CONVENTIONAL_TYPE.DOCS,
324-
description: "update docs/README.md, bar/README.md and README.md",
325-
};
323+
{
324+
const lines = [
325+
"M\tdocs/README.md",
326+
"M\tbar/README.md",
327+
"M\tREADME.md",
328+
];
329+
const expected = {
330+
typePrefix: CONVENTIONAL_TYPE.DOCS,
331+
description: "update docs/README.md, bar/README.md and README.md",
332+
};
326333

327-
assert.deepStrictEqual(_msgNamed(lines), expected);
334+
assert.deepStrictEqual(_msgNamed(lines), expected);
335+
}
336+
337+
{
338+
const lines = [
339+
"M\tdocs/README.md",
340+
"M\tbar buzz/README.md",
341+
"M\tREADME.md",
342+
];
343+
const expected = {
344+
typePrefix: CONVENTIONAL_TYPE.DOCS,
345+
description: "update docs/README.md, 'bar buzz/README.md' and README.md",
346+
};
347+
348+
assert.deepStrictEqual(_msgNamed(lines), expected);
349+
}
328350
});
329351
});
330352

@@ -369,8 +391,8 @@ describe("Prepare commit message", function () {
369391

370392
describe("multiple files", function () {
371393
describe("multiple files with the same action", function () {
372-
// Don't need to distinguish between a few or many files as as it supposed to work the
373-
// same.
394+
// Don't need to distinguish between a few or many files as as it
395+
// supposed to work the same.
374396

375397
it("handles 2 created files created correctly", function () {
376398
const lines = [
@@ -708,14 +730,29 @@ describe("Prepare commit message", function () {
708730
});
709731

710732
it("handles 3 created docs", function () {
711-
const lines = [
712-
"M\tdocs/README.md",
713-
"M\tbar/README.md",
714-
"M\tREADME.md",
715-
];
716-
const expected =
717-
"docs: update docs/README.md, bar/README.md and README.md";
718-
assert.strictEqual(_newMsg(lines), expected);
733+
{
734+
const lines = [
735+
"M\tdocs/README.md",
736+
"M\tbar/README.md",
737+
"M\tREADME.md",
738+
];
739+
const expected =
740+
"docs: update docs/README.md, bar/README.md and README.md";
741+
742+
assert.strictEqual(_newMsg(lines), expected);
743+
}
744+
745+
{
746+
const lines = [
747+
"M\tdocs/fizz buzz.md",
748+
"M\tbar/README.md",
749+
"M\tREADME.md",
750+
];
751+
const expected =
752+
"docs: update 'fizz buzz.md', bar/README.md and README.md";
753+
754+
assert.strictEqual(_newMsg(lines), expected);
755+
}
719756
});
720757
});
721758
});

0 commit comments

Comments
 (0)