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.
45 lines
2.4 KiB
TypeScript
45 lines
2.4 KiB
TypeScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { ContributionRegistry } from "../../../src/lib/plugins/registry.ts";
|
|
import { ExternalSession } from "../../../src/lib/plugins/externalSession.ts";
|
|
import type { PluginApi } from "../../../src/lib/plugins/sdk.ts";
|
|
|
|
test("browser contributions and view updates are revoked when the plugin stops", async () => {
|
|
const registry = new ContributionRegistry();
|
|
let api!: PluginApi;
|
|
let disposed = false;
|
|
const received: string[] = [];
|
|
const session = new ExternalSession("runestone.browser", {
|
|
workspace: { list: async () => [], read: async () => "", write: async () => {} },
|
|
settings: { read: async () => null, write: async () => {} }, assets: { read: async () => new Uint8Array() },
|
|
}, () => {}, () => {}, registry);
|
|
await session.start({ activate(value) {
|
|
api = value;
|
|
api.registerView({ id: "tab-test", title: "Browser", placement: "editor", icon: "globe", mount: () => {} });
|
|
api.registerTabDrop!(data => { received.push(data); });
|
|
api.contribute("browser", { mountSettings: () => () => {}, mountBookmarks: () => () => {}, open: async () => true });
|
|
api.onDispose(() => { disposed = true; });
|
|
} });
|
|
assert.ok(registry.get("browser"));
|
|
await session.dropTab("live-tab");
|
|
assert.deepEqual(received, ["live-tab"]);
|
|
api.updateViewTitle!("tab-test", "Example · User");
|
|
assert.equal(session.views.get("tab-test")?.title, "Example · User");
|
|
const icon = "data:image/png;base64,aW1hZ2U=";
|
|
api.updateViewIcon!("tab-test", icon);
|
|
assert.equal(session.views.get("tab-test")?.iconImage, icon);
|
|
assert.throws(() => api.updateViewIcon!("tab-test", "https://example.com/icon.png"), /Invalid/);
|
|
assert.throws(() => api.updateViewIcon!("tab-test", "data:text/html;base64,aW1hZ2U="), /Invalid/);
|
|
assert.throws(() => api.updateViewIcon!("tab-test", "data:image/png;base64," + "a".repeat(90_000)), /Invalid/);
|
|
api.updateViewIcon!("tab-test", null);
|
|
assert.equal(session.views.get("tab-test")?.iconImage, null);
|
|
await session.stop();
|
|
assert.equal(registry.get("browser"), undefined);
|
|
assert.equal(disposed, true);
|
|
assert.throws(() => api.updateViewTitle!("tab-test", "Other"), /disabled/);
|
|
assert.throws(() => api.updateViewIcon!("tab-test", icon), /disabled/);
|
|
await assert.rejects(session.dropTab("closed-tab"), /disabled/);
|
|
assert.throws(() => api.registerTabDrop!(() => {}), /disabled/);
|
|
assert.deepEqual(received, ["live-tab"]);
|
|
});
|