import { describe, expect, it } from "vitest"; // The shim is always invoked as `node scripts/vitest-cli-compat.mjs ...` (never executed directly), // so it carries no shebang and imports cleanly here; its `isCliEntrypoint` guard keeps the CLI body // inert when imported. A previous `new Function(...import...)` wrapper dodged Vite's shebang parse // but broke under Node 22 + vitest 3 ("A dynamic import callback was not specified"). import { appendNodeOption, normalizeVitestArgs } from "./vitest-cli-compat.mjs"; describe("normalizeVitestArgs", () => { it("rejects shell-expanded tenant dashboard route paths", () => { expect(() => normalizeVitestArgs(["run", "routes/app./dashboard.test.tsx"])).toThrow("Refusing to repair shell-expanded tenant route path"); }); it("leaves intact tenant route paths unchanged", () => { expect(normalizeVitestArgs(["run", "routes/app.$tenant/dashboard.test.tsx"])).toEqual(["run", "routes/app.$tenant/dashboard.test.tsx"]); }); it("keeps pnpm test scoped when an explicit app test path is provided after the default app root", () => { expect(normalizeVitestArgs(["run", "apps/web/app/", "apps/web/app/routes/app.$tenant/settings.workspace-shell.test.tsx", "--run"])).toEqual([ "run", "apps/web/app/routes/app.$tenant/settings.workspace-shell.test.tsx", "--run", ]); }); it("removes the pnpm separator when pruning the default app root", () => { expect(normalizeVitestArgs(["run", "apps/web/app/", "--", "apps/web/app/routes/app.$tenant/settings.workspace-shell.test.tsx", "--run"])).toEqual([ "run", "apps/web/app/routes/app.$tenant/settings.workspace-shell.test.tsx", "--run", ]); }); it("keeps the default app root for broad test runs", () => { expect(normalizeVitestArgs(["run", "apps/web/app/"])).toEqual(["run", "apps/web/app/"]); }); }); describe("appendNodeOption", () => { it("adds the local storage option without dropping existing node options", () => { expect(appendNodeOption("--trace-warnings", "--localstorage-file=/tmp/vitest-localstorage.json")).toBe( "--trace-warnings --localstorage-file=/tmp/vitest-localstorage.json", ); }); it("does not add leading whitespace when no node options exist", () => { expect(appendNodeOption(undefined, "--localstorage-file=/tmp/vitest-localstorage.json")).toBe("--localstorage-file=/tmp/vitest-localstorage.json"); }); });