OXYGENHUB
# aeb4e32ee7a0 oxygen-vscode / test / oxy.test.mjs
2.0 KiB · last changed Milestone 0.1: source control view, diffs over the oxy: scheme, quick diff, decorations, status bar, commit, quick-pick log; process wrapper with a Node test; packaging 1 month ago source blame history raw
1
// The process wrapper against the real oxy binary on a scratch repository.
2
// Runs with `npm test`; needs oxy on PATH, at ~/.local/bin/oxy, or in OXY_BIN.
3
4
import { test } from "node:test";
5
import assert from "node:assert/strict";
6
import { mkdtempSync, writeFileSync, mkdirSync } from "node:fs";
7
import { tmpdir } from "node:os";
8
import { join } from "node:path";
9
import { Oxy, findBinary } from "../out/oxy.mjs";
10
11
const binary = process.env.OXY_BIN ?? findBinary(undefined);
12
const oxy = new Oxy(binary);
13
14
test("root, status, cat, log and commit round trip", async () => {
15
  const dir = mkdtempSync(join(tmpdir(), "oxy-vscode-"));
16
  const home = join(dir, "home");
17
  mkdirSync(home);
18
  process.env.OXY_HOME = home;
19
  await oxy.check(dir, ["init", "repo"]);
20
  const root = join(dir, "repo");
21
  await oxy.check(root, ["identity", "create", "--name", "Test", "--email", "[email protected]"]);
22
23
  const version = await oxy.version();
24
  assert.equal(version.protocol, 1);
25
  assert.equal(await oxy.root(dir), null, "outside a repository");
26
  const info = await oxy.root(root);
27
  assert.equal(info?.bookmark, "main");
28
  assert.ok(info?.root.endsWith("repo"));
29
30
  writeFileSync(join(root, "a.txt"), "one\n");
31
  let status = await oxy.status(root);
32
  assert.deepEqual(status.paths, [{ path: "a.txt", status: "Added" }]);
33
  assert.equal(status.clean, false);
34
  await oxy.commit(root, "first");
35
  status = await oxy.status(root);
36
  assert.equal(status.clean, true);
37
38
  writeFileSync(join(root, "a.txt"), "one\ntwo\n");
39
  assert.equal((await oxy.cat(root, "a.txt")).toString(), "one\n", "the base version");
40
  const log = await oxy.log(root, 10);
41
  assert.equal(log.changes.filter((c) => !c.working_copy).length, 1);
42
  assert.equal(log.changes.find((c) => !c.working_copy)?.signature?.status, "unsigned");
43
  assert.ok((await oxy.prompt(root)).includes("main"));
44
  const bookmarks = await oxy.bookmarks(root);
45
  assert.deepEqual(bookmarks.map((b) => [b.name, b.current]), [["main", true]]);
46
  await assert.rejects(oxy.cat(root, "missing.txt"), /not in that state/);
47
});