testManifestStringsLinkToWhatTheyName

tcmts.share.test.testManifestStringsLinkToWhatTheyName · #rikzogo5 · function

a manifest's strings link to what they name: its commands, exports, apps, tests and files (as it writes them, relative to its namespace) and its libraries (their packages' manifests); a string naming nothing stays text

import { linkStrings, manifestTargets } from "#codebase/tcmts/share";
import type { PackageInfo } from "#codebase/tcmts/share";
import type { NameRow } from "#codebase/tcmts/store";
import assert from "node:assert/strict";

export const testManifestStringsLinkToWhatTheyName = () => {
  const row = (path: string, kind: NameRow["kind"] = "term"): NameRow => ({
    path,
    hash: path,
    kind,
  });
  const rows = [
    row("app.cli.main"),
    row("app.web.App"),
    row("app.test.e2e.testIt"),
    row("app.README", "file"),
    row("app.manifest"),
    row("app.lib.manifest"),
  ];
  const pkg = (name: string, namespace: string, more: Partial<PackageInfo> = {}): PackageInfo => ({
    name,
    namespace,
    manifestPath: `${namespace}.manifest`,
    bins: [],
    bin: {},
    exports: {},
    apps: {},
    suites: {},
    files: [],
    with: [],
    libraries: [],
    ...more,
  });
  const lib = pkg("toolkit", "app.lib");
  const app = pkg("app", "app", {
    bin: { app: "app.cli.main" },
    apps: { web: "app.web.App", gone: "app.nowhere.App" },
    suites: { app: ["app.test.e2e"] },
    files: ["README.md"],
    with: ["vitest"],
    libraries: ["toolkit", "elsewhere"],
  });
  const targets = manifestTargets(app, rows, [app, lib]);
  assert.deepEqual(
    Object.fromEntries(targets),
    {
      "cli.main": "app.cli.main",
      "web.App": "app.web.App",
      "test.e2e": "app.test.e2e",
      "README.md": "app.README",
      toolkit: "app.lib.manifest",
    },
    "what's named, by how the manifest writes it; nothing for what isn't in the codebase",
  );
  const html = `apps: { web: <span class="s">&quot;web.App&quot;</span> }, with: [<span class="s">&quot;vitest&quot;</span>]`;
  assert.equal(
    linkStrings(html, targets),
    `apps: { web: <a class="ref s" href="/code/app/web/App" title="app.web.App">&quot;web.App&quot;</a> }, with: [<span class="s">&quot;vitest&quot;</span>]`,
  );
}

uses