testPageConflictMarkers

tcmts.cli.test.e2e.merge.testPageConflictMarkers · #xohatzcc · term

A conflicted page is edited the same way: its Markdown merged, with conflict markers, and saved to resolve it.

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

export const testPageConflictMarkers = () => {
  const dir = tempDir("merge page markers");
  const tcm = (...args: string[]) => okIn(dir, ...args);
  const page = (text: string) => {
    fs.writeFileSync(path.join(dir, "notes.md"), text);
    tcm("update", "notes.md", "--into", "docs");
  };
  tcm("init");
  fs.writeFileSync(path.join(dir, "notes.md"), "# Notes\n\n- one\n- two\n- three\n");
  tcm("add", "notes.md", "--into", "docs");
  tcm("branch", "s");
  tcm("switch", "s");
  page("# Notes\n\n- one\n- two, from s\n- three\n");
  tcm("switch", "main");
  page("# Notes\n\n- one\n- two, from main\n- three\n");
  tcm("switch", "s");
  assert.equal(tcmIn(dir, "merge", "main").status, 1);
  fs.rmSync(path.join(dir, "notes.md"));
  assert.match(tcm("edit", "docs.notes"), /1 conflict marked/);
  const text = fs.readFileSync(path.join(dir, "notes.md"), "utf8");
  assert.match(text, /^<!-- tcm: path docs\.notes -->\n/);
  assert.match(
    text,
    /<<<<<<< ours \(s\)\n- two, from s\n\|\|\|\|\|\|\| base\n- two\n=======\n- two, from main\n>>>>>>> theirs \(main\)\n/,
  );
  assert.notEqual(tcmIn(dir, "update", "notes.md").status, 0, "not with the markers in");
  fs.writeFileSync(
    path.join(dir, "notes.md"),
    text.replace(/<<<<<<< [\s\S]*>>>>>>> theirs \(main\)\n/, "- two, from both\n"),
  );
  tcm("update", "notes.md");
  assert.match(tcm("todo"), /nothing to do/);
  assert.match(tcm("view", "docs.notes"), /two, from both/);
}

uses