UNPKG

one

Version:

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

375 lines (374 loc) 10.3 kB
"use strict"; var import_vitest = require("vitest"), import_testing_utils = require("../testing-utils"), import_getPathFromState = require("./getPathFromState"), import_getStateFromPath = require("./getStateFromPath"), import_getStateFromPath_mods = require("./getStateFromPath-mods"); (0, import_vitest.describe)(import_getStateFromPath_mods.stripBaseUrl, function() { [ [ // Input "/", // Base Path "", // Result "/" ], [ "/one/two", "/one", "/two" ], [ "/one/two", "/one/two", "" ], [ "/one/two/", "/one/two", "/" ], [ "///one/", "/one", "/" ], [ "one/", "/one", "one/" ], [ "/a/b", "/one", "/a/b" ] ].forEach(function(param) { var [path, baseUrl, result] = param; (0, import_vitest.it)(`strips baseUrl "${path}"`, function() { (0, import_vitest.expect)((0, import_getStateFromPath_mods.stripBaseUrl)(path, baseUrl)).toBe(result); }); }); }); (0, import_vitest.describe)("baseUrl", function() { (0, import_vitest.beforeEach)(function() { process.env.ONE_DEFAULT_RENDER_MODE = "spa"; }), (0, import_vitest.it)("accounts for baseUrl", function() { process.env.EXPO_BASE_URL = "/expo/prefix"; var path = "/expo/prefix/bar", config = (0, import_testing_utils.getMockConfig)([ "_layout.tsx", "bar.tsx", "index.tsx" ]); (0, import_vitest.expect)((0, import_getStateFromPath.getStateFromPath)(path, config)).toEqual({ routes: [ { name: "bar", path: "/bar" } ] }), (0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)((0, import_getStateFromPath.getStateFromPath)(path, config), config)).toBe("/expo/prefix/bar"); }), (0, import_vitest.it)("has baseUrl and state that does not match", function() { process.env.EXPO_BASE_URL = "/expo"; var path = "/bar", config = (0, import_testing_utils.getMockConfig)([ "_layout.tsx", "bar.tsx", "index.tsx" ]); (0, import_vitest.expect)((0, import_getStateFromPath.getStateFromPath)(path, config)).toEqual({ routes: [ { name: "bar", path: "/bar" } ] }), (0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)((0, import_getStateFromPath.getStateFromPath)(path, config), config)).toBe("/expo/bar"); }); }); (0, import_vitest.describe)(import_getStateFromPath_mods.getUrlWithReactNavigationConcessions, function() { (0, import_vitest.beforeEach)(function() { delete process.env.EXPO_BASE_URL; }), [ "/", "foo/", "foo/bar/", "foo/bar/baz/" ].forEach(function(path) { (0, import_vitest.it)(`returns the pathname for ${path}`, function() { (0, import_vitest.expect)((0, import_getStateFromPath_mods.getUrlWithReactNavigationConcessions)(path).nonstandardPathname).toBe(path); }); }), [ [ "", "/" ], [ "https://acme.com/hello/world?foo=bar#123", "hello/world/" ], [ "https://acme.com/hello/world/?foo=bar#123", "hello/world/" ] ].forEach(function(param) { var [url, expected] = param; (0, import_vitest.it)(`returns the pathname for ${url}`, function() { (0, import_vitest.expect)((0, import_getStateFromPath_mods.getUrlWithReactNavigationConcessions)(url).nonstandardPathname).toBe(expected); }); }), [ [ "/gh-pages/", "/" ], [ "https://acme.com/gh-pages/hello/world?foo=bar#123", "hello/world/" ], [ "https://acme.com/gh-pages/hello/world/?foo=bar#123", "hello/world/" ] ].forEach(function(param) { var [url, expected] = param; (0, import_vitest.it)(`returns the pathname for ${url}`, function() { (0, import_vitest.expect)((0, import_getStateFromPath_mods.getUrlWithReactNavigationConcessions)(url, "gh-pages").nonstandardPathname).toBe(expected); }); }); }); (0, import_vitest.describe)("hash", function() { (0, import_vitest.it)("parses hashes", function() { (0, import_vitest.expect)((0, import_getStateFromPath.getStateFromPath)("/hello#123", { screens: { hello: "hello" } })).toEqual({ routes: [ { name: "hello", path: "/hello#123", params: { "#": "123" } } ] }); }), (0, import_vitest.it)("parses hashes with dynamic routes", function() { (0, import_vitest.expect)((0, import_getStateFromPath.getStateFromPath)("/hello#123", (0, import_testing_utils.getMockConfig)([ "[hello]" ]))).toEqual({ routes: [ { name: "[hello]", params: { hello: "hello", "#": "123" }, path: "/hello#123" } ] }); }), (0, import_vitest.it)("parses hashes with query params", function() { (0, import_vitest.expect)((0, import_getStateFromPath.getStateFromPath)("/?#123", (0, import_testing_utils.getMockConfig)([ "index" ]))).toEqual({ routes: [ { name: "index", path: "/?#123", params: { "#": "123" } } ] }); }); }); (0, import_vitest.it)("supports spaces", function() { (0, import_vitest.expect)((0, import_getStateFromPath.getStateFromPath)("/hello%20world", { screens: { "hello world": "hello world" } })).toEqual({ routes: [ { name: "hello world", path: "/hello%20world" } ] }), (0, import_vitest.expect)((0, import_getStateFromPath.getStateFromPath)("/hello%20world", (0, import_testing_utils.getMockConfig)([ "[hello world]" ]))).toEqual({ routes: [ { name: "[hello world]", params: { "hello world": "hello world" }, path: "/hello%20world" } ] }); }); import_vitest.it.skip("matches against dynamic groups", function() { (0, import_vitest.expect)((0, import_getStateFromPath.getStateFromPath)("/(app)/(explore)", (0, import_testing_utils.getMockConfig)([ "+not-found", "(app)/_layout", "(app)/(explore)/_layout", "(app)/(explore)/[user]/index", "(app)/(explore)/explore", "(app)/([user])/_layout", "(app)/([user])/[user]/index", "(app)/([user])/explore" ]))).toEqual({ routes: [ { name: "(app)", params: { user: "(explore)" }, state: { routes: [ { name: "([user])", params: { user: "(explore)" }, state: { routes: [ { name: "[user]/index", params: { user: "(explore)" }, path: "" } ] } } ] } } ] }); }); (0, import_vitest.it)("adds dynamic route params from all levels of the path", function() { (0, import_vitest.expect)((0, import_getStateFromPath.getStateFromPath)("/foo/bar/baz/other", (0, import_testing_utils.getMockConfig)([ "[foo]/_layout.tsx", "[foo]/bar/_layout.tsx", "[foo]/bar/[baz]/_layout.tsx", "[foo]/bar/[baz]/other.tsx" ]))).toEqual({ routes: [ { name: "[foo]", params: { baz: "baz", foo: "foo" }, state: { routes: [ { name: "bar", params: { baz: "baz", foo: "foo" }, state: { routes: [ { name: "[baz]", params: { baz: "baz", foo: "foo" }, state: { routes: [ { name: "other", params: { baz: "baz", foo: "foo" }, path: "/foo/bar/baz/other" } ] } } ] } } ] } } ] }); }); (0, import_vitest.it)("handles not-found routes", function() { (0, import_vitest.expect)((0, import_getStateFromPath.getStateFromPath)("/missing-page", (0, import_testing_utils.getMockConfig)([ "+not-found", "index" ]))).toEqual({ routes: [ { name: "+not-found", params: { "not-found": [ "missing-page" ] }, path: "/missing-page" } ] }); }); (0, import_vitest.it)("handles query params", function() { (0, import_vitest.expect)((0, import_getStateFromPath.getStateFromPath)("/?test=true&hello=world&array=1&array=2", (0, import_testing_utils.getMockConfig)([ "index.tsx" ]))).toEqual({ routes: [ { name: "index", params: { test: "true", hello: "world", array: [ "1", "2" ] }, path: "/?test=true&hello=world&array=1&array=2" } ] }); }); (0, import_vitest.it)("handles query params", function() { (0, import_vitest.expect)((0, import_getStateFromPath.getStateFromPath)("/?test=true&hello=world&array=1&array=2", (0, import_testing_utils.getMockConfig)([ "index.tsx" ]))).toEqual({ routes: [ { name: "index", params: { test: "true", hello: "world", array: [ "1", "2" ] }, path: "/?test=true&hello=world&array=1&array=2" } ] }); }); import_vitest.it.skip("prioritizes hoisted index routes over dynamic groups", function() { (0, import_vitest.expect)((0, import_getStateFromPath.getStateFromPath)("/(one)", (0, import_testing_utils.getMockConfig)([ "(one,two)/index.tsx", "(one,two)/[slug].tsx" ]))).toEqual({ routes: [ { name: "(one)/index", path: "" } ] }); }); //# sourceMappingURL=getStateFromPath.test.js.map