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.
30 lines
1.7 KiB
TypeScript
30 lines
1.7 KiB
TypeScript
import { test } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { documentSessionKey, parseDocumentSession, restoreDocumentSession } from "../../../src/lib/workspace/documentSession.ts";
|
|
|
|
test("document sessions isolate workspaces and discard unsafe or duplicate paths", () => {
|
|
assert.notEqual(documentSessionKey("C:\\one"), documentSessionKey("C:\\two"));
|
|
assert.equal(parseDocumentSession("invalid"), null);
|
|
assert.equal(parseDocumentSession('{"version":2,"documents":[]}'), null);
|
|
assert.deepEqual(parseDocumentSession(JSON.stringify({ version: 1, activePath: "b.md", documents: [
|
|
{ path: "b.md", pinned: true, contents: "unsaved" }, { path: "a.md" }, { path: "b.md" },
|
|
{ path: "../outside.md" }, { path: "C:\\outside.md" }, { path: "empty:test" }, null,
|
|
] })), { version: 1, activePath: "b.md", documents: [{ path: "b.md", pinned: true }, { path: "a.md", pinned: false }] });
|
|
});
|
|
|
|
test("restoration keeps order and active tab when a missing file fails", async () => {
|
|
const opened: string[] = [];
|
|
const session = parseDocumentSession(JSON.stringify({ version: 1, activePath: "c.md",
|
|
documents: ["b.md", "missing.md", "c.md", "a.md"].map(path => ({ path })) }))!;
|
|
const active = await restoreDocumentSession(session, async item => {
|
|
if (item.path === "missing.md") throw new Error("Not found");
|
|
opened.push(item.path);
|
|
});
|
|
assert.deepEqual(opened, ["b.md", "c.md", "a.md"]);
|
|
assert.equal(active, "c.md");
|
|
assert.equal(await restoreDocumentSession({ ...session, activePath: "missing.md" }, async item => {
|
|
if (item.path === "missing.md") throw new Error("Not found");
|
|
}), "b.md");
|
|
assert.equal(await restoreDocumentSession(session, async () => { throw new Error("Unavailable"); }), null);
|
|
});
|