testFilesTravel

tcmts.cli.test.e2e.sync.testFilesTravel · #7ukdsojk · term

files kept as written (a page linking to code, an image) are history like code: pushed and pulled with it, and with code that imports them

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

export const testFilesTravel = () => {
  const root = tempDir("sync files");
  const a = codebase(root, "a");
  a.scratch(`// tcm: namespace lib\nexport const square = (x: number) => x * x;\n`);
  a.tcm("add");
  fs.writeFileSync(path.join(a.dir, "getting-started.md"), "# Guide\n\nUse {@link lib.square}.\n");
  a.tcm("add", "getting-started.md", "--into", "docs");
  // and code that imports it, received with it
  a.scratch(
    `// tcm: namespace site\nimport { "getting-started" as guide } from "#codebase/docs";\nexport const title = (): string => guide.split("\\n")[0]!;\n`,
  );
  a.tcm("add");
  const b = codebase(root, "b");
  fs.rmSync(path.join(b.dir, "scratch.ts"));
  b.tcm("remote", "add", "origin", a.dir);
  b.tcm("pull");
  assert.match(b.tcm("view", "docs.getting-started"), /Use \{@link lib\.square\}\./);
  assert.match(b.tcm("run", "site.title"), /^# Guide$/m);
  // a change to a file alone is a change to the history
  fs.writeFileSync(
    path.join(a.dir, "getting-started.md"),
    "<!-- tcm: path docs.getting-started -->\n# The guide\n\nUse {@link lib.square}.\n",
  );
  assert.match(a.tcm("update", "getting-started.md"), /update +docs\.getting-started/);
  // what the pull changed reads as the page's text
  const pulled = b.tcm("pull");
  assert.match(pulled, /- # Guide\n\s+\+ # The guide/);
  assert.doesNotMatch(pulled, /export/);
  assert.match(b.tcm("view", "docs.getting-started"), /# The guide/);
}

uses