UNPKG

one

Version:

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

66 lines (65 loc) 3.22 kB
import { describe, expect, it } from "vitest"; import { getLoaderPath, getPathFromLoaderPath } from "./cleanUrl.native.js"; function roundtrip(path) { var loaderPath = getLoaderPath(path, !1); return getPathFromLoaderPath(loaderPath); } describe("cleanUrl roundtrip", function () { it("simple path", function () { expect(roundtrip("/docs/getting-started")).toBe("/docs/getting-started"); }), it("path with underscore prefix (/_/docs)", function () { expect(roundtrip("/_/docs/getting-started")).toBe("/_/docs/getting-started"); }), it("path with underscore prefix (/_/terms)", function () { expect(roundtrip("/_/terms")).toBe("/_/terms"); }), it("path with underscore in segment name", function () { expect(roundtrip("/my_page/test")).toBe("/my_page/test"); }), it("deeply nested path", function () { expect(roundtrip("/deep/nested/path/here")).toBe("/deep/nested/path/here"); }), it("root path", function () { expect(roundtrip("/")).toBe("/"); }), it("single segment", function () { expect(roundtrip("/about")).toBe("/about"); }), it("path with query string is stripped", function () { var loaderPath = getLoaderPath("/docs/intro?foo=bar", !1); expect(getPathFromLoaderPath(loaderPath)).toBe("/docs/intro"); }), it("path with hash is stripped", function () { var loaderPath = getLoaderPath("/docs/intro#section", !1); expect(getPathFromLoaderPath(loaderPath)).toBe("/docs/intro"); }), it("path with trailing slash", function () { var loaderPath = getLoaderPath("/docs/intro/", !1); expect(getPathFromLoaderPath(loaderPath)).toBe("/docs/intro"); }); }); describe("getLoaderPath format", function () { it("includes /assets/ prefix", function () { var result = getLoaderPath("/docs/intro", !1); expect(result).toMatch(/^\/assets\//); }), it("ends with loader postfix", function () { var result = getLoaderPath("/docs/intro", !1); expect(result).toMatch(/_\d+_vxrn_loader\.js$/); }), it("includes /_one prefix in dev mode", function () { var originalEnv = process.env.NODE_ENV; process.env.NODE_ENV = "development"; try { var result = getLoaderPath("/docs/intro", !1); expect(result).toMatch(/^\/_one\/assets\//); } finally { process.env.NODE_ENV = originalEnv; } }), it("includes cache bust segment", function () { var result = getLoaderPath("/docs/intro", !1, "12345"); expect(result).toContain("_refetch_12345_"); }); }); describe("getPathFromLoaderPath", function () { it("strips /_one/assets prefix", function () { expect(getPathFromLoaderPath("/_one/assets/docs_intro_999_vxrn_loader.js")).toBe("/docs/intro"); }), it("strips /assets prefix", function () { expect(getPathFromLoaderPath("/assets/docs_intro_999_vxrn_loader.js")).toBe("/docs/intro"); }), it("strips refetch cache bust", function () { expect(getPathFromLoaderPath("/assets/docs_intro_refetch_12345__999_vxrn_loader.js")).toBe("/docs/intro"); }), it("decodes escaped underscores back to literal underscores", function () { expect(getPathFromLoaderPath("/assets/___docs_intro_999_vxrn_loader.js")).toBe("/_/docs/intro"); }); }); //# sourceMappingURL=cleanUrl.test.native.js.map