UNPKG

one

Version:

One is a new React Framework that makes Vite serve both native and web.

72 lines (71 loc) 2.16 kB
import { describe, expect, it } from "vitest"; import { getRoutes } from "./getRoutes.mjs"; function createMockContext(files) { const keys = Object.keys(files); const ctx = function (id) { return files[id] || {}; }; ctx.keys = () => keys; ctx.resolve = id => id; ctx.id = "test"; return ctx; } function collectRoutes(node, routes = []) { if (node.children?.length === 0 && node.route) { routes.push(node); } for (const child of node.children || []) { collectRoutes(child, routes); } return routes; } describe("getRoutes", () => { it("should not create duplicate +not-found when one exists in a group subdirectory", () => { const ctx = createMockContext({ "./_layout.tsx": { default: () => null }, "./(site)/_layout.tsx": { default: () => null }, "./(site)/index.tsx": { default: () => null }, "./(site)/+not-found.tsx": { default: () => null } }); const root = getRoutes(ctx, { ignoreEntryPoints: true, ignoreRequireErrors: true }); expect(root).not.toBeNull(); const allRoutes = collectRoutes(root); const notFoundRoutes = allRoutes.filter(r => r.route === "+not-found" || r.route?.endsWith("+not-found")); expect(notFoundRoutes).toHaveLength(1); expect(notFoundRoutes[0].contextKey).toBe("./(site)/+not-found.tsx"); }); it("should still append generated +not-found when none exists in any group", () => { const ctx = createMockContext({ "./_layout.tsx": { default: () => null }, "./(site)/_layout.tsx": { default: () => null }, "./(site)/index.tsx": { default: () => null } }); const root = getRoutes(ctx, { ignoreEntryPoints: true, ignoreRequireErrors: true }); expect(root).not.toBeNull(); const allRoutes = collectRoutes(root); const notFoundRoutes = allRoutes.filter(r => r.route === "+not-found" || r.route?.endsWith("+not-found")); expect(notFoundRoutes).toHaveLength(1); expect(notFoundRoutes[0].generated).toBe(true); }); }); //# sourceMappingURL=getRoutes.test.mjs.map