test.govlab/quality/core/predicates/location.predicate.test.ts

test.govlab/quality/core/predicates/location.predicate.test.ts is a file in Codebase Testing. 14 lines of code and 0 definitions.

import { expect, test } from "vitest";
import { isInsideRoot } from "@govlab/quality/core/predicates/location.predicate.ts";
import path from "node:path";

const ROOT = path.resolve("workspace-root");
const BESIDE = path.join(path.dirname(ROOT), "other", "a.ts");

test("isInsideRoot accepts the root and every path below it, relative or absolute", () => {
    expect(isInsideRoot(ROOT, ROOT)).toBe(true);
    expect(isInsideRoot(ROOT, "src/a.ts")).toBe(true);
    expect(isInsideRoot(ROOT, path.join(ROOT, "..x", "a.ts"))).toBe(true);
});

test("isInsideRoot refuses a path that climbs out of the root or sits beside it", () => {
    expect(isInsideRoot(ROOT, "../a.ts")).toBe(false);
    expect(isInsideRoot(ROOT, BESIDE)).toBe(false);
});