Move the tests from scripts/ to tests/ by feature
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.
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
import { test } from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { DEFAULT_WORKBENCH_LAYOUT, WORKBENCH_LAYOUT_KEY, parseWorkbenchLayout, saveWorkbenchLayout } from "../../../src/lib/workspace/workbenchLayout.ts";
|
||||
|
||||
test("missing and damaged layouts use defaults", () => {
|
||||
for (const raw of [null, "{broken", "null", "[]", "42", '"text"']) {
|
||||
assert.deepEqual(parseWorkbenchLayout(raw), DEFAULT_WORKBENCH_LAYOUT);
|
||||
}
|
||||
});
|
||||
|
||||
test("invalid layout fields do not discard valid collapsed states", () => {
|
||||
for (const leftWidth of [0, -1, 159, 481, "260", null]) {
|
||||
assert.deepEqual(parseWorkbenchLayout(JSON.stringify({ leftOpen: false, rightOpen: false, leftWidth, rightWidth: 320, leftView: "unknown" })), {
|
||||
...DEFAULT_WORKBENCH_LAYOUT, leftOpen: false, rightOpen: false, rightWidth: 320,
|
||||
});
|
||||
}
|
||||
assert.deepEqual(parseWorkbenchLayout('{"leftOpen":"false","rightOpen":0}'), DEFAULT_WORKBENCH_LAYOUT);
|
||||
});
|
||||
|
||||
test("layout survives storage round trips with hidden panels and all navigation views", () => {
|
||||
const store = new Map<string, string>();
|
||||
for (const leftView of ["files", "search", "bookmarks"] as const) {
|
||||
for (const leftWidth of [160, 321.5, 480]) {
|
||||
const layout = { leftOpen: false, rightOpen: false, leftWidth, rightWidth: 400, leftView };
|
||||
saveWorkbenchLayout({ setItem: (key, value) => { store.set(key, value); } }, layout);
|
||||
assert.deepEqual(parseWorkbenchLayout(store.get(WORKBENCH_LAYOUT_KEY)!), layout);
|
||||
}
|
||||
}
|
||||
assert.throws(() => saveWorkbenchLayout({ setItem: () => { throw new Error("Storage unavailable"); } }, { ...DEFAULT_WORKBENCH_LAYOUT }), /Storage unavailable/);
|
||||
});
|
||||
Reference in New Issue
Block a user