summaryrefslogtreecommitdiffhomepage
path: root/packages/lsp/src/root.test.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/lsp/src/root.test.ts')
-rw-r--r--packages/lsp/src/root.test.ts51
1 files changed, 51 insertions, 0 deletions
diff --git a/packages/lsp/src/root.test.ts b/packages/lsp/src/root.test.ts
new file mode 100644
index 0000000..ffe2e31
--- /dev/null
+++ b/packages/lsp/src/root.test.ts
@@ -0,0 +1,51 @@
+import { describe, expect, it } from "vitest";
+import { findRoot } from "./root.js";
+
+describe("root", () => {
+ it("findRoot returns nearest marker ancestor bounded by cwd", async () => {
+ const existingFiles = new Set([
+ "/project/src/components/tsconfig.json",
+ "/project/tsconfig.json",
+ ]);
+
+ const result = await findRoot(
+ "/project/src/components/widgets",
+ "/project",
+ ["tsconfig.json"],
+ async (path) => existingFiles.has(path),
+ );
+
+ expect(result).toBe("/project/src/components");
+ });
+
+ it("falls back to cwd", async () => {
+ const result = await findRoot(
+ "/project/src/deep/nested",
+ "/project",
+ ["tsconfig.json"],
+ async () => false,
+ );
+
+ expect(result).toBe("/project");
+ });
+
+ it("finds marker at start directory", async () => {
+ const existingFiles = new Set(["/project/tsconfig.json"]);
+
+ const result = await findRoot("/project", "/project", ["tsconfig.json"], async (path) =>
+ existingFiles.has(path),
+ );
+
+ expect(result).toBe("/project");
+ });
+
+ it("respects cwd boundary", async () => {
+ const existingFiles = new Set(["/tsconfig.json"]);
+
+ const result = await findRoot("/project/src", "/project", ["tsconfig.json"], async (path) =>
+ existingFiles.has(path),
+ );
+
+ expect(result).toBe("/project");
+ });
+});