Open History to see the last commit
1import { PROJECT_TRACKED_FOLDERS_MAX, type WorkspaceScannedFolder } from "@t3tools/contracts";
2import { describe, expect, it } from "vite-plus/test";
3
4import { appendTrackedFolders, suggestedTrackedFolders } from "./projectTrackedFolders.ts";
5
6const scanned = (name: string, path = `/work/${name}`): WorkspaceScannedFolder => ({
7 path,
8 name,
9 isGitRepository: true,
10 source: "child",
11});
12
13describe("suggestedTrackedFolders", () => {
14 it("offers what a workspace file lists and the project does not cover, once each", () => {
15 const listed = (name: string) => ({ ...scanned(name), source: "code-workspace" as const });
16 expect(
17 suggestedTrackedFolders(
18 [{ path: "/work/api", name: "API", discovered: true }],
19 [listed("api"), listed("lib"), listed("lib"), scanned("web"), listed("x".repeat(200))],
20 ),
21 ).toEqual([
22 { path: "/work/lib", name: "lib" },
23 { path: `/work/${"x".repeat(200)}`, name: "x".repeat(128) },
24 ]);
25 });
26});
27
28describe("appendTrackedFolders", () => {
29 it("keeps tracked folders a scan did not return and skips ones already tracked", () => {
30 expect(
31 appendTrackedFolders(
32 [
33 { path: "/elsewhere/tools", name: "tools" },
34 { path: "/work/api", name: "API" },
35 ],
36 [
37 { path: "/work/api", name: "api" },
38 { path: "/work/web", name: "web" },
39 ],
40 ),
41 ).toEqual([
42 { path: "/elsewhere/tools", name: "tools" },
43 { path: "/work/api", name: "API" },
44 { path: "/work/web", name: "web" },
45 ]);
46 });
47
48 it("refuses a list longer than the server accepts", () => {
49 const tracked = Array.from({ length: PROJECT_TRACKED_FOLDERS_MAX }, (_, index) => ({
50 path: `/work/${index}`,
51 name: `${index}`,
52 }));
53 expect(appendTrackedFolders(tracked, [{ path: "/work/0", name: "0" }])).toEqual(tracked);
54 expect(appendTrackedFolders(tracked, [{ path: "/work/extra", name: "extra" }])).toBeNull();
55 });
56});