one
Version:
One is a new React Framework that makes Vite serve both native and web.
169 lines (167 loc) • 5.41 kB
JavaScript
"use strict";
var import_vitest = require("vitest"),
import_getServerManifest = require("./getServerManifest.native.js");
function makeRouteNode(overrides) {
return {
loadRoute: function () {
return {};
},
contextKey: "",
route: "",
children: [],
dynamic: null,
type: "ssg",
...overrides
};
}
(0, import_vitest.describe)("getServerManifest route specificity", function () {
(0, import_vitest.it)("static segment /blog/[slug] should come before fully dynamic /[a]/[b]", function () {
var root = makeRouteNode({
route: "",
children: [
// group (site) with blog/[slug]
makeRouteNode({
route: "(site)",
children: [makeRouteNode({
route: "blog/[slug]",
contextKey: "(site)/blog/[slug]+ssg.tsx",
type: "ssg",
dynamic: [{
name: "slug",
deep: !1
}],
children: []
})]
}),
// group (chat) with [serverId]/[channelId]
makeRouteNode({
route: "(chat)",
children: [makeRouteNode({
route: "[serverId]",
dynamic: [{
name: "serverId",
deep: !1
}],
children: [makeRouteNode({
route: "[channelId]",
dynamic: [{
name: "channelId",
deep: !1
}],
children: [makeRouteNode({
route: "index",
contextKey: "(chat)/[serverId]/[channelId]/index.tsx",
type: "spa",
children: []
})]
})]
})]
})]
}),
manifest = (0, import_getServerManifest.getServerManifest)(root),
pages = manifest.pageRoutes.map(function (r) {
return r.file;
}),
blogIdx = pages.indexOf("(site)/blog/[slug]+ssg.tsx"),
chatIdx = pages.indexOf("(chat)/[serverId]/[channelId]/index.tsx");
(0, import_vitest.expect)(blogIdx).toBeGreaterThanOrEqual(0), (0, import_vitest.expect)(chatIdx).toBeGreaterThanOrEqual(0), (0, import_vitest.expect)(blogIdx).toBeLessThan(chatIdx);
}), (0, import_vitest.it)("/blog should come before /[slug]", function () {
var root = makeRouteNode({
route: "",
children: [makeRouteNode({
route: "blog",
contextKey: "blog.tsx",
type: "ssg",
children: []
}), makeRouteNode({
route: "[slug]",
contextKey: "[slug].tsx",
type: "ssr",
dynamic: [{
name: "slug",
deep: !1
}],
children: []
})]
}),
manifest = (0, import_getServerManifest.getServerManifest)(root),
pages = manifest.pageRoutes.map(function (r) {
return r.file;
});
(0, import_vitest.expect)(pages.indexOf("blog.tsx")).toBeLessThan(pages.indexOf("[slug].tsx"));
}), (0, import_vitest.it)("/blog/hello-world should match blog route first, not [serverId]/[channelId]", function () {
var root = makeRouteNode({
route: "",
children: [makeRouteNode({
route: "(site)",
children: [makeRouteNode({
route: "blog/[slug]",
contextKey: "(site)/blog/[slug]+ssg.tsx",
type: "ssg",
dynamic: [{
name: "slug",
deep: !1
}],
children: []
})]
}), makeRouteNode({
route: "(chat)",
children: [makeRouteNode({
route: "[serverId]",
dynamic: [{
name: "serverId",
deep: !1
}],
children: [makeRouteNode({
route: "[channelId]",
dynamic: [{
name: "channelId",
deep: !1
}],
children: [makeRouteNode({
route: "index",
contextKey: "(chat)/[serverId]/[channelId]/index.tsx",
type: "spa",
children: []
})]
})]
})]
})]
}),
manifest = (0, import_getServerManifest.getServerManifest)(root),
pathname = "/blog/hello-world",
matched = manifest.pageRoutes.find(function (route) {
return new RegExp(route.namedRegex).test(pathname);
});
(0, import_vitest.expect)(matched?.file).toBe("(site)/blog/[slug]+ssg.tsx");
}), (0, import_vitest.it)("[slug] should come before [...catchAll]", function () {
var root = makeRouteNode({
route: "",
children: [makeRouteNode({
route: "[...catchAll]",
contextKey: "[...catchAll].tsx",
type: "ssr",
dynamic: [{
name: "catchAll",
deep: !0
}],
children: []
}), makeRouteNode({
route: "[slug]",
contextKey: "[slug].tsx",
type: "ssr",
dynamic: [{
name: "slug",
deep: !1
}],
children: []
})]
}),
manifest = (0, import_getServerManifest.getServerManifest)(root),
pages = manifest.pageRoutes.map(function (r) {
return r.file;
});
(0, import_vitest.expect)(pages.indexOf("[slug].tsx")).toBeLessThan(pages.indexOf("[...catchAll].tsx"));
});
});
//# sourceMappingURL=getServerManifest.test.native.js.map