1import { describe, expect, it } from "vite-plus/test";
2
3import { buildFileTreePathUpdates } from "./fileTreePathReconciliation";
4
5describe("buildFileTreePathUpdates", () => {
6 it("updates only paths that changed", () => {
7 expect(
8 buildFileTreePathUpdates(
9 ["src/", "src/kept.ts", "src/removed.ts"],
10 ["src/", "src/kept.ts", "src/added.ts"],
11 ),
12 ).toEqual([
13 { type: "remove", path: "src/removed.ts" },
14 { type: "add", path: "src/added.ts" },
15 ]);
16 });
17
18 it("removes a missing subtree with one recursive update", () => {
19 expect(
20 buildFileTreePathUpdates(
21 ["src/", "src/feature/", "src/feature/index.ts", "src/kept.ts"],
22 ["src/", "src/kept.ts"],
23 ),
24 ).toEqual([{ type: "remove", path: "src/feature/", recursive: true }]);
25 });
26
27 it("does nothing when a refresh returns the same tree", () => {
28 const paths = ["src/", "src/index.ts"];
29 expect(buildFileTreePathUpdates(paths, [...paths])).toEqual([]);
30 });
31});