Files
edgeever/scripts/web-startup-graph.test.mjs
T
tianma-if 5eecc8df13 perf: reduce bundled fonts and defer startup dependencies
Keep shared offline defaults and download optional fonts into a validated cache with reliable export fallbacks. Prune stale Android DOM assets and refresh the smaller iOS editor bundles.

Preserve lazy startup boundaries through direct shared exports and dependency-aware splitting. Add ESM graph and Chrome startup checks to prevent eager editor and font loading.
2026-10-19 11:10:25 +08:00

27 lines
1.5 KiB
JavaScript

import { expect, test } from "bun:test";
import { mkdtempSync, writeFileSync, rmSync } from "node:fs";
import { join } from "node:path";
import { tmpdir } from "node:os";
import { readWebStartupGraph } from "./web-startup-graph.mjs";
test("counts eager imports and re-exports even without preload hints, while preserving lazy boundaries", () => {
const root = mkdtempSync(join(tmpdir(), "edgeever-startup-"));
try {
writeFileSync(join(root, "index.html"), '<script type="module" src="/app.js"></script>');
const files = {
"app.js": 'import "./shell.js"; const editor = () => import("./editor.js"); /* import "./fake.js" */',
"shell.js": 'export { value } from "./utility.js"; export * from "./utility.js";',
"utility.js": "export const value = 1;",
"editor.js": 'import "./large-diagram.js";',
"large-diagram.js": "export const big = 1;",
};
for (const [name, code] of Object.entries(files)) writeFileSync(join(root, name), code);
const graph = readWebStartupGraph(root);
expect(graph.initialJavaScriptFiles).toEqual(["app.js", "shell.js", "utility.js"]);
expect(graph.initialJavaScriptBytes).toBe(Buffer.byteLength(files["app.js"] + files["shell.js"] + files["utility.js"]));
// Making the editor eager must increase the measured graph regardless of HTML hints.
writeFileSync(join(root, "app.js"), 'import "./shell.js"; import "./editor.js";');
expect(readWebStartupGraph(root).initialJavaScriptFiles).toContain("large-diagram.js");
} finally { rmSync(root, { recursive: true, force: true }); }
});