one
Version:
One is a new React Framework that makes Vite serve both native and web.
119 lines (117 loc) • 3.68 kB
JavaScript
;
var import_vitest = require("vitest");
var import_getRoutes = require("./getRoutes.native.js");
function createMockContext(files) {
var keys = Object.keys(files);
var ctx = function ctx2(id) {
return files[id] || {};
};
ctx.keys = function () {
return keys;
};
ctx.resolve = function (id) {
return id;
};
ctx.id = "test";
return ctx;
}
function collectRoutes(node) {
var routes = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : [];
var _node_children;
if (((_node_children = node.children) === null || _node_children === void 0 ? void 0 : _node_children.length) === 0 && node.route) {
routes.push(node);
}
var _iteratorNormalCompletion = true,
_didIteratorError = false,
_iteratorError = void 0;
try {
for (var _iterator = (node.children || [])[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var child = _step.value;
collectRoutes(child, routes);
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return != null) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
return routes;
}
(0, import_vitest.describe)("getRoutes", function () {
(0, import_vitest.it)("should not create duplicate +not-found when one exists in a group subdirectory", function () {
var ctx = createMockContext({
"./_layout.tsx": {
default: function () {
return null;
}
},
"./(site)/_layout.tsx": {
default: function () {
return null;
}
},
"./(site)/index.tsx": {
default: function () {
return null;
}
},
"./(site)/+not-found.tsx": {
default: function () {
return null;
}
}
});
var root = (0, import_getRoutes.getRoutes)(ctx, {
ignoreEntryPoints: true,
ignoreRequireErrors: true
});
(0, import_vitest.expect)(root).not.toBeNull();
var allRoutes = collectRoutes(root);
var notFoundRoutes = allRoutes.filter(function (r) {
var _r_route;
return r.route === "+not-found" || ((_r_route = r.route) === null || _r_route === void 0 ? void 0 : _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", function () {
var ctx = createMockContext({
"./_layout.tsx": {
default: function () {
return null;
}
},
"./(site)/_layout.tsx": {
default: function () {
return null;
}
},
"./(site)/index.tsx": {
default: function () {
return null;
}
}
});
var root = (0, import_getRoutes.getRoutes)(ctx, {
ignoreEntryPoints: true,
ignoreRequireErrors: true
});
(0, import_vitest.expect)(root).not.toBeNull();
var allRoutes = collectRoutes(root);
var notFoundRoutes = allRoutes.filter(function (r) {
var _r_route;
return r.route === "+not-found" || ((_r_route = r.route) === null || _r_route === void 0 ? void 0 : _r_route.endsWith("+not-found"));
});
(0, import_vitest.expect)(notFoundRoutes).toHaveLength(1);
(0, import_vitest.expect)(notFoundRoutes[0].generated).toBe(true);
});
});
//# sourceMappingURL=getRoutes.test.native.js.map