testPatchSeveralInDependencyOrder

tcmts.cli.test.e2e.editing.testPatchSeveralInDependencyOrder · #ge2xzpoa · term

tcm patch --patches of a constant and another whose value uses it, the user given first: written in the order that typechecks, rather than refused as "used before its declaration".

import { okIn, tempDir } from "#codebase/tcmts/cli/test/e2e/harness";
import assert from "node:assert/strict";
import fs from "node:fs";
import path from "node:path";

export const testPatchSeveralInDependencyOrder = () => {
  const dir = tempDir("patch in dependency order");
  const ok = (...args: string[]) => okIn(dir, ...args);
  ok("init");
  fs.writeFileSync(
    path.join(dir, "m.ts"),
    `// tcm: namespace m\nexport const GUIDE = "guide";\nexport const TOOLS = [{ d: GUIDE }];\n`,
  );
  ok("add", "m.ts");
  const out = ok(
    "patch",
    "--patches",
    JSON.stringify([
      { name: "m.TOOLS", edits: [{ old: "d: GUIDE", new: "d: GUIDE, e: 1" }] },
      { name: "m.GUIDE", edits: [{ old: '"guide"', new: '"guide!"' }] },
    ]),
  );
  assert.match(out, /~ update +m\.TOOLS/, out);
  assert.match(out, /~ update +m\.GUIDE/, out);
  assert.match(ok("view", "m.TOOLS"), /d: GUIDE, e: 1/);
}

uses