46 lines
1.5 KiB
TypeScript
46 lines
1.5 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import { defineDeployableAppModule } from "../../src/apps/deployable-app-module.ts";
|
|
import { defineBoundedContextModule } from "../../src/contexts/bounded-context-module.ts";
|
|
import { createAppRouteModules } from "../../src/platform/routing/context-route-module.ts";
|
|
|
|
const MAX_CONTEXTS_PER_APP = 20;
|
|
|
|
describe("context executable lazy loading", () => {
|
|
it("does no context route composition at boot and loads only the entered context", async () => {
|
|
const loadCounts = Array.from({ length: MAX_CONTEXTS_PER_APP }, () => 0);
|
|
const contexts = loadCounts.map((_, index) =>
|
|
defineBoundedContextModule({
|
|
id: `context-${index}`,
|
|
features: [],
|
|
budget: { maxFeatures: 200 },
|
|
route: {
|
|
path: `context-${index}/*`,
|
|
loadRoutes: async () => {
|
|
loadCounts[index] += 1;
|
|
return Object.freeze([]);
|
|
},
|
|
},
|
|
}),
|
|
);
|
|
const app = defineDeployableAppModule({
|
|
id: "scale-app",
|
|
contexts,
|
|
budget: { maxContexts: MAX_CONTEXTS_PER_APP },
|
|
});
|
|
|
|
const routeModules = createAppRouteModules(app);
|
|
|
|
expect(routeModules).toHaveLength(MAX_CONTEXTS_PER_APP);
|
|
expect(loadCounts.every((count) => count === 0)).toBe(true);
|
|
|
|
await routeModules[7]!.loadRoutes();
|
|
|
|
expect(loadCounts[7]).toBe(1);
|
|
expect(loadCounts.filter((count) => count !== 0)).toEqual([1]);
|
|
|
|
await routeModules[7]!.loadRoutes();
|
|
expect(loadCounts[7]).toBe(1);
|
|
});
|
|
});
|