Repository navigation
Expand file tree
/
Copy pathdiffFileTree.logic.test.ts
More file actions
66 lines (60 loc) · 2.09 KB
/
Copy pathdiffFileTree.logic.test.ts
File metadata and controls
66 lines (60 loc) · 2.09 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
import type { FileDiffMetadata } from "@pierre/diffs";
import { describe, expect, it } from "vite-plus/test";
import {
buildDiffFileTreeUpdates,
diffFileTreeEntries,
orderDiffFilesLikeTree,
} from "./diffFileTree.logic";
function file(type: FileDiffMetadata["type"], name: string, prevName = name): FileDiffMetadata {
return { type, name, prevName } as FileDiffMetadata;
}
describe("diffFileTreeEntries", () => {
it("folds a file-to-symlink type change into one modified entry", () => {
expect(
diffFileTreeEntries([
file("change", "CLAUDE.md"),
file("deleted", "AGENTS.md"),
file("new", "AGENTS.md"),
file("new", "docs/new.md"),
]),
).toEqual([
{ path: "CLAUDE.md", status: "modified" },
{ path: "AGENTS.md", status: "modified" },
{ path: "docs/new.md", status: "added" },
]);
});
});
describe("orderDiffFilesLikeTree", () => {
it("pulls a test listed last into its directory, keeping the first-seen order", () => {
expect(
orderDiffFilesLikeTree([
file("change", "server/device/Host.ts"),
file("change", "web/settings.ts"),
file("change", "server/ws.ts"),
file("change", "server/device/Host.test.ts"),
file("change", "web/settings.test.ts"),
]).map((entry) => entry.name),
).toEqual([
"server/device/Host.ts",
"server/device/Host.test.ts",
"server/ws.ts",
"web/settings.ts",
"web/settings.test.ts",
]);
});
});
describe("buildDiffFileTreeUpdates", () => {
it("adds a new file's directories before the file", () => {
expect(buildDiffFileTreeUpdates(["README.md"], ["README.md", "src/lib/a.ts"])).toEqual([
{ type: "add", path: "src/" },
{ type: "add", path: "src/lib/" },
{ type: "add", path: "src/lib/a.ts" },
]);
});
it("removes files before their now-empty directories, deepest first", () => {
expect(buildDiffFileTreeUpdates(["src/lib/a.ts", "src/b.ts"], ["src/b.ts"])).toEqual([
{ type: "remove", path: "src/lib/a.ts" },
{ type: "remove", path: "src/lib/", recursive: true },
]);
});
});