testShownPath
tcmts.cli.ui.testShownPath · #ure5ovqn · term
import { shownPath } from "#codebase/tcmts/cli/ui";
import fs from "node:fs";
import os from "node:os";
import path from "node:path";
export const testShownPath = () => {
const dir = fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), "tcm shown ")));
try {
fs.mkdirSync(path.join(dir, "real", "sessions"), { recursive: true });
fs.symlinkSync(path.join(dir, "real"), path.join(dir, "link"));
const here = path.join(dir, "real");
// in it through the link: from here
if (
shownPath(path.join(dir, "link", "sessions", "scratch.ts"), here) !==
path.join("sessions", "scratch.ts")
)
throw new Error(shownPath(path.join(dir, "link", "sessions", "scratch.ts"), here));
if (shownPath("scratch.ts", here) !== "scratch.ts") throw new Error("relative");
// outside it: whole
const out = path.join(dir, "elsewhere", "scratch.ts");
if (shownPath(out, here) !== out) throw new Error(shownPath(out, here));
} finally {
fs.rmSync(dir, { recursive: true, force: true });
}
}
uses