Skip to content

Commit 5900185

Browse files
committed
test: update convCommit.test.ts, commonPath.test.ts and paths.test.ts
1 parent ed2aff5 commit 5900185

File tree

3 files changed

+143
-3
lines changed

3 files changed

+143
-3
lines changed

src/test/generate/convCommit.test.ts

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,6 @@ describe("Test #ConventionalCommit class for path-based conventional commit logi
166166
new ConventionalCommit("spec/foo.js").isTestRelated(),
167167
true,
168168
);
169-
170169
assert.strictEqual(
171170
new ConventionalCommit("unit_tests/foo.js").isTestRelated(),
172171
true,
@@ -182,6 +181,62 @@ describe("Test #ConventionalCommit class for path-based conventional commit logi
182181
new ConventionalCommit("foo/test_bar.js").isTestRelated(),
183182
true,
184183
);
184+
assert.strictEqual(
185+
new ConventionalCommit("foo/bar.spec.js").isTestRelated(),
186+
true,
187+
);
188+
assert.strictEqual(
189+
new ConventionalCommit("foo/spec_bar.js").isTestRelated(),
190+
true,
191+
);
192+
});
193+
194+
it("can identify test configuration files", function () {
195+
assert.strictEqual(
196+
new ConventionalCommit(".coveragerc").isTestRelated(),
197+
true,
198+
);
199+
assert.strictEqual(
200+
new ConventionalCommit("test/.coveragerc").isTestRelated(),
201+
true,
202+
);
203+
});
204+
205+
it("can identify mock directories", function () {
206+
assert.strictEqual(
207+
new ConventionalCommit("__mocks__/foo.js").isTestRelated(),
208+
true,
209+
);
210+
assert.strictEqual(
211+
new ConventionalCommit("src/__mocks__/foo.js").isTestRelated(),
212+
true,
213+
);
214+
});
215+
216+
it("can identify unit test directories", function () {
217+
assert.strictEqual(
218+
new ConventionalCommit("unit/foo.js").isTestRelated(),
219+
true,
220+
);
221+
assert.strictEqual(
222+
new ConventionalCommit("unit_tests/foo.js").isTestRelated(),
223+
true,
224+
);
225+
assert.strictEqual(
226+
new ConventionalCommit("test_foo.js").isTestRelated(),
227+
true,
228+
);
229+
});
230+
231+
it("returns false for non-test files", function () {
232+
assert.strictEqual(
233+
new ConventionalCommit("src/foo.js").isTestRelated(),
234+
false,
235+
);
236+
assert.strictEqual(
237+
new ConventionalCommit("lib/bar.js").isTestRelated(),
238+
false,
239+
);
185240
});
186241
});
187242

src/test/lib/commonPath.test.ts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44
* Check that a common path can be found for paths.
55
*/
66
import * as assert from "assert";
7-
import { commonPath, _splitStrings } from "../../lib/commonPath";
7+
import {
8+
_allElementsEqual,
9+
_splitStrings,
10+
commonPath,
11+
} from "../../lib/commonPath";
812

913
describe("Split an array of strings at a separator", function () {
1014
describe("#_splitStrings", function () {
@@ -22,6 +26,31 @@ describe("Split an array of strings at a separator", function () {
2226
});
2327
});
2428

29+
describe("Check if all elements in an array are equal", function () {
30+
describe("#_allElementsEqual", function () {
31+
it("should return true for array with all equal elements", function () {
32+
assert.strictEqual(_allElementsEqual([1, 1, 1]), true);
33+
assert.strictEqual(_allElementsEqual(["a", "a", "a"]), true);
34+
assert.strictEqual(_allElementsEqual([true, true, true]), true);
35+
});
36+
37+
it("should return false for array with different elements", function () {
38+
assert.strictEqual(_allElementsEqual([1, 2, 1]), false);
39+
assert.strictEqual(_allElementsEqual(["a", "b", "a"]), false);
40+
assert.strictEqual(_allElementsEqual([true, false, true]), false);
41+
});
42+
43+
it("should handle empty array", function () {
44+
assert.strictEqual(_allElementsEqual([]), true);
45+
});
46+
47+
it("should handle array with single element", function () {
48+
assert.strictEqual(_allElementsEqual([1]), true);
49+
assert.strictEqual(_allElementsEqual(["a"]), true);
50+
});
51+
});
52+
});
53+
2554
describe("Find the highest common parent directory for paths", function () {
2655
// This is useful when building a change message about multiple files and
2756
// seeing what the high common level is between them so this can be used in

src/test/lib/paths.test.ts

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
import * as assert from "assert";
77
import { ROOT } from "../../lib/constants";
88
import {
9+
_join,
910
friendlyFile,
1011
humanList,
1112
quoteForSpaces,
1213
splitPath,
13-
_join,
1414
} from "../../lib/paths";
1515

1616
describe("Path handling", function () {
@@ -30,6 +30,62 @@ describe("Path handling", function () {
3030
extension: ".txt",
3131
});
3232
});
33+
34+
it("handles file at root level", function () {
35+
const result = splitPath("foo.txt");
36+
assert.strictEqual(result.atRoot, true);
37+
assert.strictEqual(result.dirPath, ROOT);
38+
assert.strictEqual(result.name, "foo.txt");
39+
assert.strictEqual(result.extension, ".txt");
40+
});
41+
42+
it("handles file in subdirectory", function () {
43+
const result = splitPath("src/foo.txt");
44+
assert.strictEqual(result.atRoot, false);
45+
assert.strictEqual(result.dirPath, "src");
46+
assert.strictEqual(result.name, "foo.txt");
47+
assert.strictEqual(result.extension, ".txt");
48+
});
49+
50+
it("handles file in nested subdirectory", function () {
51+
const result = splitPath("src/lib/foo.txt");
52+
assert.strictEqual(result.atRoot, false);
53+
assert.strictEqual(result.dirPath, "src/lib");
54+
assert.strictEqual(result.name, "foo.txt");
55+
assert.strictEqual(result.extension, ".txt");
56+
});
57+
58+
it("handles file with no extension", function () {
59+
const result = splitPath("src/foo");
60+
assert.strictEqual(result.atRoot, false);
61+
assert.strictEqual(result.dirPath, "src");
62+
assert.strictEqual(result.name, "foo");
63+
assert.strictEqual(result.extension, "");
64+
});
65+
66+
it("handles file with multiple dots", function () {
67+
const result = splitPath("src/foo.bar.txt");
68+
assert.strictEqual(result.atRoot, false);
69+
assert.strictEqual(result.dirPath, "src");
70+
assert.strictEqual(result.name, "foo.bar.txt");
71+
assert.strictEqual(result.extension, ".txt");
72+
});
73+
74+
it("handles file starting with dot", function () {
75+
const result = splitPath("src/.env");
76+
assert.strictEqual(result.atRoot, false);
77+
assert.strictEqual(result.dirPath, "src");
78+
assert.strictEqual(result.name, ".env");
79+
assert.strictEqual(result.extension, "");
80+
});
81+
82+
it("handles file with spaces", function () {
83+
const result = splitPath("src/my file.txt");
84+
assert.strictEqual(result.atRoot, false);
85+
assert.strictEqual(result.dirPath, "src");
86+
assert.strictEqual(result.name, "my file.txt");
87+
assert.strictEqual(result.extension, ".txt");
88+
});
3389
});
3490

3591
describe("#quoteForSpaces", function () {

0 commit comments

Comments
 (0)