UNPKG

one

Version:

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

88 lines (87 loc) 4.12 kB
import { posix } from "path"; import { pathToFileURL } from "url.native.js"; import { describe, expect, it } from "vitest"; import { normalizePath } from "vite"; import { toServerOutputPath } from "./toServerOutputPath.native.js"; describe("path.posix.join \u2014 forward-slash output on every platform", function () { it("joins server-output paths", function () { expect(posix.join("dist", "server", "foo.js")).toBe("dist/server/foo.js"); }); it("joins middleware-output paths", function () { expect(posix.join("dist", "middlewares", "mw-hash.js")).toBe("dist/middlewares/mw-hash.js"); }); it("strips redundant `./` segments", function () { expect(posix.join("./app", "./_layout.tsx")).toBe("app/_layout.tsx"); }); it("produces a bare filename for a `.` directory component", function () { expect(posix.join(".", "foo-[hash].cjs")).toBe("foo-[hash].cjs"); }); it("preserves nested-chunk subdirectories", function () { expect(posix.join("subdir", "foo-[hash].cjs")).toBe("subdir/foo-[hash].cjs"); }); }); describe("pathToFileURL \u2014 canonical file:// URL specifier", function () { it("produces a forward-slash href on every platform", function () { var href = pathToFileURL("/proj/src/setup.ts").href; expect(href.startsWith("file://")).toBe(true); expect(href.includes("\\")).toBe(false); }); it("round-trips through JSON.stringify without backslashes leaking in", function () { var href = pathToFileURL("/proj/src/setup.ts").href; var stringified = JSON.stringify(href); expect(stringified.includes("\\\\")).toBe(false); }); }); describe("Vite normalizePath \u2014 converts on Windows, no-op on POSIX", function () { it("preserves a forward-slash path unchanged", function () { expect(normalizePath("/proj/src/foo.tsx")).toBe("/proj/src/foo.tsx"); }); it("converts backslashes (Windows-shaped input)", function () { var input = String.raw`C:\proj\src\foo.tsx`; var out = normalizePath(input); if (process.platform === "win32") { expect(out).toBe("C:/proj/src/foo.tsx"); } else { expect(out).toBe(input); } }); }); describe("toServerOutputPath \u2014 cross-platform parity", function () { var 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"]]; var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0; try { var _loop = function () { var [input, outDir, expected] = _step.value; it(`("${input}", "${outDir}") \u2192 "${expected}"`, function () { expect(toServerOutputPath(input, outDir)).toBe(expected); }); }; for (var _iterator = cases[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) _loop(); } catch (err) { _didIteratorError = true; _iteratorError = err; } finally { try { if (!_iteratorNormalCompletion && _iterator.return != null) { _iterator.return(); } } finally { if (_didIteratorError) { throw _iteratorError; } } } }); describe("seed bug regression \u2014 SSR loader path doubling on Windows", function () { it("does not double-prefix backslash-shaped server-output input", function () { var windowsShapedInput = String.raw`dist\server\assets\time_ssr-COqAsxju.js`; expect(toServerOutputPath(windowsShapedInput, "dist")).toBe("dist/server/assets/time_ssr-COqAsxju.js"); }); it("does not double-prefix already-forward-slashed input", function () { var posixInput = "dist/server/assets/time_ssr-COqAsxju.js"; expect(toServerOutputPath(posixInput, "dist")).toBe(posixInput); }); }); //# sourceMappingURL=posixPathContract.test.native.js.map