one
Version:
One is a new React Framework that makes Vite serve both native and web.
70 lines • 2.33 kB
JavaScript
var import_vitest = require("vitest");
var import_getRoutes = require("./getRoutes.cjs");
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;
}
(0, import_vitest.describe)("getRoutes", () => {
(0, import_vitest.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 = (0, import_getRoutes.getRoutes)(ctx, {
ignoreEntryPoints: true,
ignoreRequireErrors: true
});
(0, import_vitest.expect)(root).not.toBeNull();
const allRoutes = collectRoutes(root);
const notFoundRoutes = allRoutes.filter(r => r.route === "+not-found" || r.route?.endsWith("+not-found"));
(0, import_vitest.expect)(notFoundRoutes).toHaveLength(1);
(0, import_vitest.expect)(notFoundRoutes[0].contextKey).toBe("./(site)/+not-found.tsx");
});
(0, import_vitest.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 = (0, import_getRoutes.getRoutes)(ctx, {
ignoreEntryPoints: true,
ignoreRequireErrors: true
});
(0, import_vitest.expect)(root).not.toBeNull();
const allRoutes = collectRoutes(root);
const notFoundRoutes = allRoutes.filter(r => r.route === "+not-found" || r.route?.endsWith("+not-found"));
(0, import_vitest.expect)(notFoundRoutes).toHaveLength(1);
(0, import_vitest.expect)(notFoundRoutes[0].generated).toBe(true);
});
});