testMigrateKeepsEverything

tcmts.cli.test.e2e.migrate.testMigrateKeepsEverything · #ghmjhosu · term

A codebase in an older hash format (and table layout) isn't opened, and says to migrate; tcm migrate moves it, history and all: its names, both branches, its history entries, its release and its test results, the old database kept beside it.

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

export const testMigrateKeepsEverything = () => {
  const dir = v1Codebase("migrate");
  const refused = tcmIn(dir, "ls");
  assert.notEqual(refused.status, 0);
  assert.match(refused.out, /`tcm migrate` moves it/);
  assert.match(
    okIn(dir, "migrate"),
    /migrated 15 definition\(s\) and 5 history entries from hash format v1 to v2 \(1 read differently; 12 checked\), and its tables from layout 8f648138cf12612e to /,
  );
  assert.ok(fs.existsSync(path.join(dir, ".tcm", "codebase.v1.sqlite")), "the codebase as it was");
  assert.match(okIn(dir, "ls", "geo"), /geo\.distance[\s\S]*geo\.initial[\s\S]*geo\.origin/);
  assert.equal(
    okIn(dir, "history")
      .split("\n")
      .filter((l) => l.startsWith("#")).length,
    4,
  );
  assert.match(okIn(dir, "releases"), /0\.1\.0 .* First release\./);
  // results by hash, carried over: the tests didn't change, so they needn't run again
  assert.match(okIn(dir, "test"), /2 passed, 0 failed \(2 cached\)/);
  okIn(dir, "switch", "feature");
  assert.doesNotMatch(okIn(dir, "ls", "geo"), /geo\.origin/);
  assert.match(
    okIn(dir, "migrate"),
    /in hash format v2 and this tcm's layout already: nothing to do/,
  );
  assert.equal(okIn(dir, "migrate", "--if-needed"), "");
}

uses