36 lines
1.6 KiB
TypeScript
36 lines
1.6 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import { existsSync, readFileSync } from "node:fs";
|
|
import { describe, it } from "node:test";
|
|
|
|
const appSource = readFileSync(new URL("../App.tsx", import.meta.url), "utf8");
|
|
const routesSourcePath = new URL("../routes/appRoutes.tsx", import.meta.url);
|
|
const readRoutesSource = () => {
|
|
assert.equal(existsSync(routesSourcePath), true, "expected src/routes/appRoutes.tsx to exist");
|
|
return readFileSync(routesSourcePath, "utf8");
|
|
};
|
|
|
|
describe("App route splitting", () => {
|
|
it("loads route pages lazily instead of statically importing every page into the first bundle", () => {
|
|
const routesSource = readRoutesSource();
|
|
|
|
assert.doesNotMatch(appSource, /^import\s+\w+\s+from\s+["']\.\/pages\//m);
|
|
assert.doesNotMatch(appSource, /lazy\(\s*\(\)\s*=>\s*import\(["']\.\/pages\//);
|
|
assert.match(routesSource, /lazy\(\s*\(\)\s*=>\s*import\(["']\.\.\/pages\//);
|
|
});
|
|
|
|
it("wraps lazy routes in Suspense with an operator-friendly loading state", () => {
|
|
assert.match(appSource, /Suspense/);
|
|
assert.match(appSource, /Routes laden/);
|
|
});
|
|
|
|
it("keeps route definitions in a dedicated manifest instead of the app shell", () => {
|
|
const routesSource = readRoutesSource();
|
|
|
|
assert.match(appSource, /import\s+\{\s*appRoutes\s*\}\s+from\s+["']\.\/routes\/appRoutes["']/);
|
|
assert.doesNotMatch(appSource, /<Route\s+path=/);
|
|
assert.match(routesSource, /export\s+const\s+appRoutes/);
|
|
assert.match(routesSource, /path:\s*["']\/ai\/security-reviewer["']/);
|
|
assert.match(routesSource, /path:\s*["']\*["']/);
|
|
});
|
|
});
|