-
Notifications
You must be signed in to change notification settings - Fork 399
/
Copy pathstringUtils.test.ts
52 lines (46 loc) · 1.39 KB
/
stringUtils.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
import { calculateNearestUniquePath } from "./stringUtils";
describe(calculateNearestUniquePath, () => {
it("strips the leading slash from the root path", () => {
expect(
calculateNearestUniquePath("/index.js", [
"/other/index.js",
"/test/index.js",
])
).toBe("index.js");
});
it("supports nested paths", () => {
expect(
calculateNearestUniquePath("/test/index.js", [
"/index.js",
"/other/index.js",
"/other/something/index.js",
])
).toBe("test/index.js");
expect(
calculateNearestUniquePath("/test/something/index.js", [
"/index.js",
"/other/index.js",
"/other/something/index.js",
])
).toBe("test/something/index.js");
});
it("keeps path when same level and same name", () => {
expect(
calculateNearestUniquePath("/other/index.js", ["/test/index.js"])
).toBe("other/index.js");
});
it("adds a leading `..` when other open paths have the same fileName, but different paths", () => {
expect(
calculateNearestUniquePath("/test/something/index.js", [
"/index.js",
"/example/index.js",
"/example/something/else/index.js",
])
).toBe("../something/index.js");
});
it("supports root paths", () => {
expect(
calculateNearestUniquePath("README.md", [".gitignore", ".eslintignore"])
).toBe("README.md");
});
});