testLocationRewriterTakesPathsWithSpaces

tcmts.cli.main.testLocationRewriterTakesPathsWithSpaces · #qz7t4sa5 · term

import { locationRewriter } from "#codebase/tcmts/cli/main";
import fs from "node:fs";
import path from "node:path";

export const testLocationRewriterTakesPathsWithSpaces = () => {
  const dir = fs.mkdtempSync(
    path.join(fs.realpathSync(process.env.TMPDIR ?? "/tmp"), "Application Support "),
  );
  try {
    const file = path.join(dir, "patch-1.ts");
    const at = locationRewriter(file, [{ name: "lib.f", line: 3, end: 9, viewAt: 2 }], ["lib.f"]);
    const eq = (a: string, b: string) => {
      if (a !== b) throw new Error(`${JSON.stringify(a)} isn't ${JSON.stringify(b)}`);
    };
    eq(at(`${file}:5:7 - error TS2322`), "lib.f:4:7 - error TS2322");
    eq(at(`${path.relative(process.cwd(), file)}:5:7 warning`), "lib.f:4:7 warning");
    eq(at(`saving ${file}`), "saving lib.f");
    eq(at("patch-1.ts:4:1"), "lib.f:3:1");
    // a line outside the definitions is the file's, named as what it holds
    eq(at(`${file}:1:1`), "lib.f:1:1");
  } finally {
    fs.rmSync(dir, { recursive: true, force: true });
  }
}

uses