one
Version:
One is a new React Framework that makes Vite serve both native and web.
75 lines (74 loc) • 7.45 kB
JavaScript
import { describe, expect, it } from "vitest";
import { getNameFromFilePath, matchArrayGroupName, matchDeepDynamicRouteName, matchDirectoryRenderMode, matchDynamicName, matchGroupName, stripGroupSegmentsFromPath } from "./matchers.native.js";
describe(stripGroupSegmentsFromPath, function () {
it("strips group segments, preserving initial slash", function () {
expect(stripGroupSegmentsFromPath("/[[...foobar]]/(foo)/bar/[bax]/(other)")).toBe("/[[...foobar]]/bar/[bax]"), expect(stripGroupSegmentsFromPath("(foo)/(bar)")).toBe("");
});
});
describe(matchGroupName, function () {
it("matches", function () {
expect(matchGroupName("[[...foobar]]")).toEqual(void 0), expect(matchGroupName("[[foobar]]")).toEqual(void 0), expect(matchGroupName("[...foobar]")).toEqual(void 0), expect(matchGroupName("[foobar]")).toEqual(void 0), expect(matchGroupName("(foobar)")).toEqual("foobar"), expect(matchGroupName("(foo,bar)")).toEqual("foo,bar"), expect(matchGroupName("((foobar))")).toEqual("(foobar)"), expect(matchGroupName("(...foobar)")).toEqual("...foobar"), expect(matchGroupName("foobar")).toEqual(void 0), expect(matchGroupName("leading/foobar")).toEqual(void 0), expect(matchGroupName("leading/(foobar)")).toEqual("foobar"), expect(matchGroupName("leading/((foobar))")).toEqual("(foobar)"), expect(matchGroupName("leading/(...foobar)")).toEqual("...foobar"), expect(matchGroupName("leading/(foo,bar)")).toEqual("foo,bar"), expect(matchGroupName("leading/foobar/trailing")).toEqual(void 0), expect(matchGroupName("leading/(foobar)/trailing")).toEqual("foobar"), expect(matchGroupName("leading/((foobar))/trailing")).toEqual("(foobar)"), expect(matchGroupName("leading/(...foobar)/trailing")).toEqual("...foobar"), expect(matchGroupName("leading/(foo,bar)/trailing)")).toEqual("foo,bar"), expect(matchGroupName("leading/(foo,bar)/(fruit,apple)")).toEqual("foo,bar");
});
});
describe(matchDynamicName, function () {
it("matches", function () {
expect(matchDynamicName("[[...foobar]]")).toEqual(void 0), expect(matchDynamicName("[[foobar]]")).toEqual(void 0), expect(matchDynamicName("[...foobar]")).toEqual({
name: "foobar",
deep: !0
}), expect(matchDynamicName("[foobar]")).toEqual({
name: "foobar",
deep: !1
}), expect(matchDynamicName("foobar")).toEqual(void 0);
});
});
describe(matchDeepDynamicRouteName, function () {
it("matches", function () {
expect(matchDeepDynamicRouteName("[[...foobar]]")).toEqual(void 0), expect(matchDeepDynamicRouteName("[[foobar]]")).toEqual(void 0), expect(matchDeepDynamicRouteName("[...foobar]")).toEqual("foobar"), expect(matchDeepDynamicRouteName("[foobar]")).toEqual(void 0), expect(matchDeepDynamicRouteName("foobar")).toEqual(void 0);
});
});
describe(getNameFromFilePath, function () {
it("should return the name of the file", function () {
expect(getNameFromFilePath("./pages/home.tsx")).toBe("pages/home"), expect(getNameFromFilePath("../pages/home.js")).toBe("pages/home"), expect(getNameFromFilePath("./(home).jsx")).toBe("(home)"), expect(getNameFromFilePath("../../../(pages)/[any]/[...home].ts")).toBe("(pages)/[any]/[...home]");
});
});
describe(matchArrayGroupName, function () {
it("should not match routes without groups", function () {
expect(matchArrayGroupName("[[...foobar]]")).toEqual(void 0), expect(matchArrayGroupName("[[foobar]]")).toEqual(void 0), expect(matchArrayGroupName("[...foobar]")).toEqual(void 0), expect(matchArrayGroupName("[foobar]")).toEqual(void 0), expect(matchArrayGroupName("foobar")).toEqual(void 0), expect(matchArrayGroupName("leading/foobar")).toEqual(void 0), expect(matchArrayGroupName("leading/foobar/trailing")).toEqual(void 0);
}), it("should not match routes with a single group", function () {
expect(matchArrayGroupName("(foobar)")).toEqual(void 0), expect(matchArrayGroupName("((foobar))")).toEqual(void 0), expect(matchArrayGroupName("(...foobar)")).toEqual(void 0), expect(matchArrayGroupName("leading/(foobar)")).toEqual(void 0), expect(matchArrayGroupName("leading/((foobar))")).toEqual(void 0), expect(matchArrayGroupName("leading/(...foobar)")).toEqual(void 0), expect(matchArrayGroupName("leading/(foobar)/trailing")).toEqual(void 0), expect(matchArrayGroupName("leading/((foobar))/trailing")).toEqual(void 0), expect(matchArrayGroupName("leading/(...foobar)/trailing")).toEqual(void 0), expect(matchArrayGroupName("(leading)/foobar")).toEqual(void 0), expect(matchArrayGroupName("(leading)/(foobar)")).toEqual(void 0), expect(matchArrayGroupName("(leading)/((foobar))")).toEqual(void 0), expect(matchArrayGroupName("(leading)/(...foobar)")).toEqual(void 0), expect(matchArrayGroupName("(leading)/foobar/trailing")).toEqual(void 0), expect(matchArrayGroupName("(leading)/(foobar)/trailing")).toEqual(void 0), expect(matchArrayGroupName("(leading)/((foobar))/trailing")).toEqual(void 0), expect(matchArrayGroupName("(leading)/(...foobar)/trailing")).toEqual(void 0);
}), it.skip("should match routes with array group syntax", function () {
expect(matchArrayGroupName("(foo,bar)")).toEqual("foo,bar"), expect(matchArrayGroupName("leading/(foo,bar)")).toEqual("foo,bar"), expect(matchArrayGroupName("leading/(foo,bar)/trailing)")).toEqual("foo,bar"), expect(matchArrayGroupName("leading/((foo),(bar))/trailing)")).toEqual("(foo),(bar)"), expect(matchArrayGroupName("leading/(foo,bar)/(fruit,apple)")).toEqual("foo,bar"), expect(matchArrayGroupName("(leading)/(foo,bar)")).toEqual("foo,bar"), expect(matchArrayGroupName("(leading)/(foo,bar)/trailing)")).toEqual("foo,bar"), expect(matchArrayGroupName("(leading)/((foo),(bar))/trailing)")).toEqual("(foo),(bar)");
}), it.skip("should only match the first group with array group syntax", function () {
expect(matchArrayGroupName("(leading)/(foo,bar)/(fruit,apple)")).toEqual("foo,bar"), expect(matchArrayGroupName("(leading)/((foo),bar)/(fruit,apple)")).toEqual("(foo),bar"), expect(matchArrayGroupName("(leading)/(foo,bar)/((fruit),apple)")).toEqual("foo,bar");
});
});
describe(matchDirectoryRenderMode, function () {
it("should match directory names with render mode suffixes", function () {
expect(matchDirectoryRenderMode("dashboard+ssr")).toEqual({
name: "dashboard",
renderMode: "ssr"
}), expect(matchDirectoryRenderMode("blog+ssg")).toEqual({
name: "blog",
renderMode: "ssg"
}), expect(matchDirectoryRenderMode("admin+spa")).toEqual({
name: "admin",
renderMode: "spa"
}), expect(matchDirectoryRenderMode("api-routes+api")).toEqual({
name: "api-routes",
renderMode: "api"
});
}), it("should not match directory names without render mode suffixes", function () {
expect(matchDirectoryRenderMode("dashboard")).toEqual(void 0), expect(matchDirectoryRenderMode("blog")).toEqual(void 0), expect(matchDirectoryRenderMode("admin")).toEqual(void 0);
}), it("should not match invalid render modes", function () {
expect(matchDirectoryRenderMode("dashboard+invalid")).toEqual(void 0), expect(matchDirectoryRenderMode("blog+csr")).toEqual(void 0);
}), it("should handle directory names with hyphens and underscores", function () {
expect(matchDirectoryRenderMode("my-dashboard+ssr")).toEqual({
name: "my-dashboard",
renderMode: "ssr"
}), expect(matchDirectoryRenderMode("my_blog+ssg")).toEqual({
name: "my_blog",
renderMode: "ssg"
});
});
});
//# sourceMappingURL=matchers.test.native.js.map