Open History to see the last commit
1import { describe, expect, it } from "vite-plus/test";
2
3import { buildTurnDiffTree } from "./turnDiffTree";
4
5describe("buildTurnDiffTree", () => {
6 it("builds nested directory nodes with aggregated stats", () => {
7 const tree = buildTurnDiffTree([
8 { path: "src/index.ts", kind: "modified", additions: 2, deletions: 1 },
9 { path: "src/components/Button.tsx", kind: "modified", additions: 4, deletions: 2 },
10 { path: "README.md", kind: "modified", additions: 1, deletions: 0 },
11 ]);
12
13 expect(tree).toEqual([
14 {
15 kind: "directory",
16 name: "src",
17 path: "src",
18 stat: { additions: 6, deletions: 3 },
19 children: [
20 {
21 kind: "directory",
22 name: "components",
23 path: "src/components",
24 stat: { additions: 4, deletions: 2 },
25 children: [
26 {
27 kind: "file",
28 name: "Button.tsx",
29 path: "src/components/Button.tsx",
30 stat: { additions: 4, deletions: 2 },
31 },
32 ],
33 },
34 {
35 kind: "file",
36 name: "index.ts",
37 path: "src/index.ts",
38 stat: { additions: 2, deletions: 1 },
39 },
40 ],
41 },
42 {
43 kind: "file",
44 name: "README.md",
45 path: "README.md",
46 stat: { additions: 1, deletions: 0 },
47 },
48 ]);
49 });
50
51 it("compacts only single-directory chains and stops at branch points", () => {
52 const tree = buildTurnDiffTree([
53 { path: "apps/server/src/index.ts", kind: "modified", additions: 2, deletions: 1 },
54 { path: "apps/server/main.ts", kind: "modified", additions: 4, deletions: 0 },
55 ]);
56
57 expect(tree).toEqual([
58 {
59 kind: "directory",
60 name: "apps/server",
61 path: "apps/server",
62 stat: { additions: 6, deletions: 1 },
63 children: [
64 {
65 kind: "directory",
66 name: "src",
67 path: "apps/server/src",
68 stat: { additions: 2, deletions: 1 },
69 children: [
70 {
71 kind: "file",
72 name: "index.ts",
73 path: "apps/server/src/index.ts",
74 stat: { additions: 2, deletions: 1 },
75 },
76 ],
77 },
78 {
79 kind: "file",
80 name: "main.ts",
81 path: "apps/server/main.ts",
82 stat: { additions: 4, deletions: 0 },
83 },
84 ],
85 },
86 ]);
87 });
88});