testCommentChangesTravel

tcmts.cli.test.e2e.sync.testCommentChangesTravel · #snpumiys · term

A change to only a definition's doc and comments travels like any: pushed, the remote reads it so; pulled, by a codebase that lacks the code and by one that has it already. Each text received is checked to be the same code.

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 testCommentChangesTravel = () => {
  const root = tempDir("sync texts");
  const a = codebase(root, "a");
  a.scratch(
    `// tcm: namespace lib\n/** Squares a number. */\nexport const square = (x: number): number => x * x;\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");

  b.scratch(
    `// tcm: namespace lib\n/** The square of a number. */\nexport const square = (x: number): number =>\n  // x²\n  x * x;\n`,
  );
  b.tcm("update");
  assert.match(b.tcm("push"), /pushed origin\/main/);
  assert.match(a.tcm("view", "lib.square"), /The square of a number[\s\S]*x²/);

  const c = codebase(root, "c");
  fs.rmSync(path.join(c.dir, "scratch.ts"));
  c.tcm("remote", "add", "origin", a.dir);
  c.tcm("pull");
  assert.match(c.tcm("view", "lib.square"), /The square of a number[\s\S]*x²/);

  a.scratch(
    `// tcm: namespace lib\n/** Squared. */\nexport const square = (x: number): number => x * x;\n`,
  );
  a.tcm("update");
  assert.match(b.tcm("pull"), /fast-forwarded main/);
  const view = b.tcm("view", "lib.square");
  assert.match(view, /Squared\./);
  assert.doesNotMatch(view, /x²/);
}

uses