withConflicts

tcmts.cli.test.e2e.merge.withConflicts · #nugz4nwp · term · runs on the server

uses node:fs

A codebase whose branch s has just merged main with two conflicts: lib.k, both sides changing the same line (main another too, apart), and lib.m, which uses it, both changing it too. lib.user uses both.

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 function withConflicts(name: string) {
  const dir = tempDir(name);
  const tcm = (...args: string[]) => okIn(dir, ...args);
  const update = (code: string) => {
    fs.writeFileSync(path.join(dir, "scratch.ts"), `// tcm: namespace lib\n${code}\n`);
    tcm("update");
  };
  const k = (a: number, c: number) =>
    `export const k = (): number => {\n  const a = ${a};\n  const b = 2;\n  const c = ${c};\n  return a + b + c;\n};`;
  tcm("init");
  update(
    `${k(1, 3)}\nexport const m = (): number => k() + 1;\nexport const user = (): number => m() * 10;`,
  );
  tcm("branch", "s");
  tcm("switch", "s");
  update(`${k(10, 3)}\nexport const m = (): number => k() + 2;`);
  tcm("switch", "main");
  update(`${k(100, 30)}\nexport const m = (): number => k() + 3;`);
  tcm("switch", "s");
  const merged = tcmIn(dir, "merge", "main");
  assert.equal(merged.status, 1, merged.out);
  const sides = (name: string, out = tcm("todo")) => {
    const line = new RegExp(
      `conflict ${name.replace(".", "\\.")}: (\\S+) \\(ours: s\\) vs (\\S+) \\(theirs: main\\)`,
    ).exec(out);
    assert.ok(line, out);
    return { ours: line[1]!, theirs: line[2]! };
  };
  return { dir, tcm, merged, sides };
}

uses

used by