UNPKG

one

Version:

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

64 lines (63 loc) 3 kB
import { afterEach, describe, expect, it } from "vitest"; import { getPathWithRecoveredDynamicSegment, getPathnameWithRecoveredDynamicSegment, hasLostDynamicSegment, normalizeRoutePathname } from "./path.native.js"; var originalBaseUrl = process.env.EXPO_BASE_URL; var originalNodeEnv = process.env.NODE_ENV; afterEach(function () { if (originalBaseUrl === void 0) { delete process.env.EXPO_BASE_URL; } else { process.env.EXPO_BASE_URL = originalBaseUrl; } if (originalNodeEnv === void 0) { delete process.env.NODE_ENV; } else { process.env.NODE_ENV = originalNodeEnv; } }); describe("hasLostDynamicSegment", function () { it('detects a literal "undefined" segment', function () { expect(hasLostDynamicSegment("/p/undefined")).toBe(true); expect(hasLostDynamicSegment("/users/undefined/posts")).toBe(true); expect(hasLostDynamicSegment("/undefined")).toBe(true); }); it('does not match "undefined" inside another segment', function () { expect(hasLostDynamicSegment("/p/undefined-things")).toBe(false); expect(hasLostDynamicSegment("/p/notundefined")).toBe(false); expect(hasLostDynamicSegment("/p/foo-undefined-bar")).toBe(false); }); it("ignores search and hash values", function () { expect(hasLostDynamicSegment("/p/undefined?tab=profile")).toBe(true); expect(hasLostDynamicSegment("/p/mai1015?x=undefined")).toBe(false); expect(hasLostDynamicSegment("/p/mai1015#undefined")).toBe(false); }); }); describe("normalizeRoutePathname", function () { it("strips search, hash, and trailing slash", function () { expect(normalizeRoutePathname("/p/mai1015/?tab=profile#top")).toBe("/p/mai1015"); expect(normalizeRoutePathname("/")).toBe("/"); }); it("strips the production base url", function () { process.env.NODE_ENV = "production"; process.env.EXPO_BASE_URL = "/expo/prefix"; expect(normalizeRoutePathname("/expo/prefix/p/mai1015?tab=profile")).toBe("/p/mai1015"); }); }); describe("getPathWithRecoveredDynamicSegment", function () { it("uses the first uncorrupted candidate path", function () { expect(getPathWithRecoveredDynamicSegment(["/p/undefined", "/p/mai1015?tab=profile"], "/p/browser?tab=profile")).toBe("/p/mai1015?tab=profile"); }); it("keeps an empty uncorrupted candidate path", function () { expect(getPathWithRecoveredDynamicSegment([""], "/browser")).toBe(""); }); it("falls back when every candidate path is corrupted", function () { expect(getPathWithRecoveredDynamicSegment(["/p/undefined"], "/p/browser?tab=profile")).toBe("/p/browser?tab=profile"); }); }); describe("getPathnameWithRecoveredDynamicSegment", function () { it("normalizes the recovered browser pathname", function () { process.env.NODE_ENV = "production"; process.env.EXPO_BASE_URL = "/expo/prefix"; expect(getPathnameWithRecoveredDynamicSegment("/p/undefined", "/expo/prefix/p/mai1015?tab=profile")).toBe("/p/mai1015"); }); }); //# sourceMappingURL=path.test.native.js.map