testClassesKeepIdentityThroughRenames

tcmts.cli.test.e2e.e2e.testClassesKeepIdentityThroughRenames · #hf6uvoig · term

classes keep their identity and runtime name through renames

import { setUp } from "#codebase/tcmts/cli/test/e2e/e2e";
import assert from "node:assert/strict";

export const testClassesKeepIdentityThroughRenames = () => {
  const { tcm, scratch } = setUp();
  scratch(`// tcm: namespace errors
export class UsageError extends Error {}
export class ConflictError extends Error {}
export const probe = () => [new UsageError("u") instanceof ConflictError, new ConflictError("c").constructor.name].join(" ");
`);
  tcm("add");
  assert.equal(tcm("run", "errors.probe").trim(), "false ConflictError");
  assert.match(tcm("mv", "errors.ConflictError", "errors.Clash"), /still named `ConflictError` at runtime/);
  assert.equal(tcm("run", "errors.probe").trim(), "false ConflictError");
  assert.match(tcm("view", "errors.Clash"), /class ConflictError extends Error/);
  // editing it binds it back to errors.Clash, not to a fresh errors.ConflictError
  tcm("edit", "errors.Clash", "--file", "clash.ts");
  assert.match(tcm("check", "clash.ts"), /= identical\s+errors\.Clash/);
}

uses