|
| 1 | +import { describe, expect, it } from "vitest"; |
| 2 | +import { applyBasePath, joinPath } from "./path"; |
| 3 | + |
| 4 | +describe("joinPath", () => { |
| 5 | + it("should join base and path with single slash", () => { |
| 6 | + expect(joinPath("/base/", "/foo")).toBe("/base/foo"); |
| 7 | + expect(joinPath("/base", "foo")).toBe("/base/foo"); |
| 8 | + expect(joinPath("/base", "/foo/bar")).toBe("/base/foo/bar"); |
| 9 | + expect(joinPath("/foo/bar/", "/baz/qux")).toBe("/foo/bar/baz/qux"); |
| 10 | + expect(joinPath("/foo/bar", "baz/qux")).toBe("/foo/bar/baz/qux"); |
| 11 | + }); |
| 12 | + |
| 13 | + it("should handle root base path correctly", () => { |
| 14 | + expect(joinPath("/", "/foo")).toBe("/foo"); |
| 15 | + expect(joinPath("/", "foo")).toBe("/foo"); |
| 16 | + }); |
| 17 | + |
| 18 | + it("should handle empty path", () => { |
| 19 | + expect(joinPath("/base", "")).toBe("/base/"); |
| 20 | + expect(joinPath("/base/", "")).toBe("/base/"); |
| 21 | + }); |
| 22 | + |
| 23 | + it("should handle empty base", () => { |
| 24 | + expect(joinPath("", "/foo")).toBe("/foo"); |
| 25 | + expect(joinPath("", "foo")).toBe("/foo"); |
| 26 | + }); |
| 27 | +}); |
| 28 | + |
| 29 | +describe("applyBasePath", () => { |
| 30 | + it("should apply basePath to absolute path", () => { |
| 31 | + expect(applyBasePath("/base", "/foo")).toBe("/base/foo"); |
| 32 | + expect(applyBasePath("/foo", "/bar/baz")).toBe("/foo/bar/baz"); |
| 33 | + }); |
| 34 | + |
| 35 | + it("should not apply basePath to relative path", () => { |
| 36 | + expect(applyBasePath("/base", "./index.html")).toBe("./index.html"); |
| 37 | + expect(applyBasePath("/foo/bar", "baz/qux")).toBe("baz/qux"); |
| 38 | + }); |
| 39 | + |
| 40 | + it("should handle root basePath", () => { |
| 41 | + expect(applyBasePath("/", "/foo")).toBe("/foo"); |
| 42 | + }); |
| 43 | + |
| 44 | + it("should handle empty basePath", () => { |
| 45 | + expect(applyBasePath("", "/foo")).toBe("/foo"); |
| 46 | + }); |
| 47 | +}); |
0 commit comments