Unit tests go to tests/unit/<area>/, browser smoke tests to tests/smoke/<area>/, and tests against a running desktop app to tests/native/. Files named after dates, work passes, or Kanban cards get feature names, for example editorOctober12 -> editor/footnotes. scripts/ keeps the build, release, and package tools. Plugin repositories import scripts/packagePlugin.mjs, and the Terminal smoke test imports scripts/pluginMocks.mjs, which now re-exports the harness copy. The unit tests get their own type check (tests/tsconfig.json) with Node types. pnpm check runs it after the app check. Add @types/node and fix the three test mocks that it reported.
61 lines
3.7 KiB
TypeScript
61 lines
3.7 KiB
TypeScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { ExternalSession } from "../../../src/lib/plugins/externalSession.ts";
|
|
import { ContributionRegistry } from "../../../src/lib/plugins/registry.ts";
|
|
import type { PluginApi } from "../../../src/lib/plugins/sdk.ts";
|
|
|
|
test("Git and file access stop before plugin cleanup", async () => {
|
|
const calls: unknown[] = [];
|
|
let api!: PluginApi;
|
|
const registry = new ContributionRegistry();
|
|
const session = new ExternalSession("test.git", {
|
|
workspace: { list: async () => [], read: async () => "", write: async () => {} },
|
|
settings: { read: async () => null, write: async () => {} }, assets: { read: async () => new Uint8Array() },
|
|
openFile: async path => { calls.push(path); },
|
|
git: {
|
|
status: async () => ({ available: true, repository: true, branch: "main", changes: [] }),
|
|
diff: async (path, staged) => { calls.push([path, staged]); return "diff"; },
|
|
stage: async paths => { calls.push(paths); }, unstage: async paths => { calls.push(paths); },
|
|
commit: async message => { calls.push(message); }, blame: async () => null,
|
|
push: async () => { calls.push('push'); }, pull: async () => { calls.push('pull'); }, graph: async () => ({ commits: [] }),
|
|
commitDetails: async () => { throw new Error("not used"); }, commitDiff: async () => "",
|
|
},
|
|
}, () => {}, () => {}, registry);
|
|
await session.start({ activate(value) { api = value; api.contribute("git", { blame: (path, line) => api.git!.blame(path, line) }); } });
|
|
await api.openFile!("notes.md");
|
|
assert.equal(await api.git!.diff("notes.md", true), "diff");
|
|
await api.git!.stage(["notes.md"]);
|
|
assert.deepEqual(calls, ["notes.md", ["notes.md", true], ["notes.md"]]);
|
|
await api.git!.push();
|
|
await api.git!.pull();
|
|
assert.deepEqual(await api.git!.graph(), { commits: [] });
|
|
assert.deepEqual(calls.slice(-2), ['push', 'pull']);
|
|
await session.stop();
|
|
assert.equal(registry.get("git"), undefined);
|
|
assert.throws(() => api.openFile!("notes.md"), /disabled/);
|
|
for (const action of [() => api.git!.push(), () => api.git!.pull(), () => api.git!.graph()]) assert.throws(action, /disabled/);
|
|
for (const action of [() => api.git!.status(), () => api.git!.diff("a", false), () => api.git!.stage(["a"]), () => api.git!.unstage(["a"]), () => api.git!.commit("a"), () => api.git!.blame("a", 1)]) assert.throws(action, /disabled/);
|
|
});
|
|
|
|
test("view replacement rejects unknown destinations and stops after disposal", async () => {
|
|
let api!: PluginApi;
|
|
const calls: unknown[] = [];
|
|
const session = new ExternalSession("test.boards", {
|
|
workspace: { list: async () => [], read: async () => "", write: async () => {} },
|
|
settings: { read: async () => null, write: async () => {} }, assets: { read: async () => new Uint8Array() },
|
|
}, () => {}, () => {}, new ContributionRegistry(), undefined, undefined, undefined,
|
|
(current, next) => calls.push([current, next]), (document, next) => calls.push([document, next]));
|
|
await session.start({ activate(value) {
|
|
api = value;
|
|
for (const id of ["a", "b"]) api.registerView({ id, title: id, placement: "editor", mount() {} });
|
|
api.registerView({ id: "sidebar", title: "Sidebar", placement: "sidebar", navigation: true, icon: "git", mount() {} });
|
|
} });
|
|
api.replaceView!("a", "b");
|
|
api.replaceDocumentWithView!({ id: "legacy", path: "Board.md" }, "b");
|
|
assert.deepEqual(calls, [["a", "b"], [{ id: "legacy", path: "Board.md" }, "b"]]);
|
|
assert.throws(() => api.replaceView!("missing", "b"), /Unknown/);
|
|
assert.throws(() => api.replaceDocumentWithView!({ id: "legacy", path: "Board.md" }, "missing"), /Unknown/);
|
|
await session.stop();
|
|
assert.throws(() => api.replaceView!("a", "b"), /disabled/);
|
|
});
|