Files
RuneStone/tests/unit/release/featureChunks.spec.ts
T
Knotty Wyvern d3218b2501 Make Git a native feature with an off switch
- Add the native feature runtime in src/lib/features/: the catalog, the switches, the first-start migration, the loader, and the feature sessions.
- Add Settings → Features and the features settings section.
- Add features_legacy. It reads the old plugin packages and changes nothing.
- Move Git from the plugin into src/lib/features/git/, on host internals.
- Remove api.git, the git contribution key, and the SDK Git types.
- Add pnpm check:features. It fails when a feature module loads at start.
- Update the tests, the menu inventory, the docs, and UI-055.
2026-10-29 15:51:21 -07:00

42 lines
2.4 KiB
TypeScript

import { test } from "node:test";
import assert from "node:assert/strict";
import { checkChunks, featureModule, staticClosure } from "../../../scripts/featureChunks.mjs";
const root = "D:/RuneStone/";
const chunk = (fileName: string, fields: Record<string, unknown> = {}) => ({ fileName, isEntry: false, isDynamicEntry: false, facadeModuleId: null, imports: [], moduleIds: [], size: 10, ...fields });
test("the static closure follows imports from each entry, and not dynamic imports", () => {
const chunks = [
chunk("app.js", { isEntry: true, imports: ["shared.js"] }),
chunk("node.js", { isEntry: true }),
chunk("shared.js", { imports: ["deep.js"] }),
chunk("deep.js"),
chunk("git.js", { isDynamicEntry: true, imports: ["shared.js"] }),
];
assert.deepEqual([...staticClosure(chunks)].sort(), ["app.js", "deep.js", "node.js", "shared.js"]);
});
test("feature folders and feature libraries count as feature modules, and the runtime does not", () => {
assert.equal(featureModule(`${root}src/lib/features/git/index.ts`), true);
assert.equal(featureModule("D:\\RuneStone\\src\\lib\\features\\git\\model.ts"), true);
assert.equal(featureModule(`${root}src/lib/features/catalog.ts`), false);
assert.equal(featureModule(`${root}node_modules/.pnpm/@[email protected]/node_modules/@xterm/xterm/lib/xterm.mjs`), true);
assert.equal(featureModule(`${root}node_modules/pdfjs-dist/build/pdf.mjs`), true);
assert.equal(featureModule(`${root}node_modules/svelte/src/index.js`), false);
});
test("a feature module in a start chunk fails, and a separate dynamic chunk passes", () => {
const good = [
chunk("app.js", { isEntry: true, moduleIds: [`${root}src/lib/features/catalog.ts`] }),
chunk("git.js", { isDynamicEntry: true, facadeModuleId: `${root}src/lib/features/git/index.ts`, moduleIds: [`${root}src/lib/features/git/index.ts`], size: 2048 }),
];
assert.deepEqual(checkChunks(good), { problems: [], sizes: { git: 2048 } });
const bad = [
chunk("app.js", { isEntry: true, imports: ["shared.js"] }),
chunk("shared.js", { moduleIds: [`${root}src/lib/features/git/model.ts`] }),
chunk("git.js", { isDynamicEntry: true, facadeModuleId: `${root}src/lib/features/git/index.ts` }),
];
assert.deepEqual(checkChunks(bad).problems, ["shared.js loads at start and contains src/lib/features/git/model.ts"]);
assert.deepEqual(checkChunks([chunk("app.js", { isEntry: true })]).problems, ["No chunk starts at src/lib/features/git/index.ts."]);
});