testHashFormatIsPinned

tcmts.core.test.golden.testHashFormatIsPinned · #lmfifacy · term

The hash format is pinned.

import { analyzeProject } from "#codebase/tcmts/core/analyze";
import { IR_VERSION } from "#codebase/tcmts/core/hash";
import { CORPUS, PINNED } from "#codebase/tcmts/core/test/golden";
import assert from "node:assert/strict";
import fs from "node:fs";
import os from "node:os";
import path from "node:path";

export const testHashFormatIsPinned = () => {
  assert.equal(IR_VERSION, 2);
  const dir = fs.mkdtempSync(path.join(os.tmpdir(), "tcm-golden-"));
  const corpus = path.join(dir, "corpus.ts");
  fs.writeFileSync(path.join(dir, "package.json"), JSON.stringify({ type: "module" }));
  fs.writeFileSync(corpus, CORPUS + "\n");
  // salted the way the CLI salts a fresh definition: by the path it is first added at
  const a = analyzeProject([corpus], {
    cacheDir: fs.mkdtempSync(path.join(os.tmpdir(), "tcm-golden-")),
    resolveName: () => "",
    saltFor: (_file, name) => `golden.${name}`,
  });
  assert.deepEqual([...a.errors, ...a.diagnostics.map((d) => d.message)], []);
  assert.deepEqual(Object.fromEntries(a.defs.map((d) => [d.nameHint, d.hash])), PINNED);
}

uses