UNPKG

one

Version:

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

66 lines 4.21 kB
var import_node_path = require("node:path"); var import_node_url = require("node:url"); var import_vitest = require("vitest"); var import_vite = require("vite"); var import_toServerOutputPath = require("./toServerOutputPath.cjs"); (0, import_vitest.describe)("path.posix.join \u2014 forward-slash output on every platform", () => { (0, import_vitest.it)("joins server-output paths", () => { (0, import_vitest.expect)(import_node_path.posix.join("dist", "server", "foo.js")).toBe("dist/server/foo.js"); }); (0, import_vitest.it)("joins middleware-output paths", () => { (0, import_vitest.expect)(import_node_path.posix.join("dist", "middlewares", "mw-hash.js")).toBe("dist/middlewares/mw-hash.js"); }); (0, import_vitest.it)("strips redundant `./` segments", () => { (0, import_vitest.expect)(import_node_path.posix.join("./app", "./_layout.tsx")).toBe("app/_layout.tsx"); }); (0, import_vitest.it)("produces a bare filename for a `.` directory component", () => { (0, import_vitest.expect)(import_node_path.posix.join(".", "foo-[hash].cjs")).toBe("foo-[hash].cjs"); }); (0, import_vitest.it)("preserves nested-chunk subdirectories", () => { (0, import_vitest.expect)(import_node_path.posix.join("subdir", "foo-[hash].cjs")).toBe("subdir/foo-[hash].cjs"); }); }); (0, import_vitest.describe)("pathToFileURL \u2014 canonical file:// URL specifier", () => { (0, import_vitest.it)("produces a forward-slash href on every platform", () => { const href = (0, import_node_url.pathToFileURL)("/proj/src/setup.ts").href; (0, import_vitest.expect)(href.startsWith("file://")).toBe(true); (0, import_vitest.expect)(href.includes("\\")).toBe(false); }); (0, import_vitest.it)("round-trips through JSON.stringify without backslashes leaking in", () => { const href = (0, import_node_url.pathToFileURL)("/proj/src/setup.ts").href; const stringified = JSON.stringify(href); (0, import_vitest.expect)(stringified.includes("\\\\")).toBe(false); }); }); (0, import_vitest.describe)("Vite normalizePath \u2014 converts on Windows, no-op on POSIX", () => { (0, import_vitest.it)("preserves a forward-slash path unchanged", () => { (0, import_vitest.expect)((0, import_vite.normalizePath)("/proj/src/foo.tsx")).toBe("/proj/src/foo.tsx"); }); (0, import_vitest.it)("converts backslashes (Windows-shaped input)", () => { const input = String.raw`C:\proj\src\foo.tsx`; const out = (0, import_vite.normalizePath)(input); if (process.platform === "win32") { (0, import_vitest.expect)(out).toBe("C:/proj/src/foo.tsx"); } else { (0, import_vitest.expect)(out).toBe(input); } }); }); (0, import_vitest.describe)("toServerOutputPath \u2014 cross-platform parity", () => { const cases = [["foo.js", "dist", "dist/server/foo.js"], ["subdir/bar.js", "dist", "dist/server/subdir/bar.js"], ["dist/server/foo.js", "dist", "dist/server/foo.js"], [String.raw`dist\server\foo.js`, "dist", "dist/server/foo.js"], [String.raw`subdir\bar.js`, "dist", "dist/server/subdir/bar.js"], ["foo/dist/server/bar.js", "dist", "dist/server/foo/dist/server/bar.js"], ["dist/server", "dist", "dist/server"], ["baz.js", "build", "build/server/baz.js"]]; for (const [input, outDir, expected] of cases) { (0, import_vitest.it)(`("${input}", "${outDir}") \u2192 "${expected}"`, () => { (0, import_vitest.expect)((0, import_toServerOutputPath.toServerOutputPath)(input, outDir)).toBe(expected); }); } }); (0, import_vitest.describe)("seed bug regression \u2014 SSR loader path doubling on Windows", () => { (0, import_vitest.it)("does not double-prefix backslash-shaped server-output input", () => { const windowsShapedInput = String.raw`dist\server\assets\time_ssr-COqAsxju.js`; (0, import_vitest.expect)((0, import_toServerOutputPath.toServerOutputPath)(windowsShapedInput, "dist")).toBe("dist/server/assets/time_ssr-COqAsxju.js"); }); (0, import_vitest.it)("does not double-prefix already-forward-slashed input", () => { const posixInput = "dist/server/assets/time_ssr-COqAsxju.js"; (0, import_vitest.expect)((0, import_toServerOutputPath.toServerOutputPath)(posixInput, "dist")).toBe(posixInput); }); });