|
1 | 1 | import { describe, expect, it } from "vite-plus/test"; |
2 | 2 |
|
3 | 3 | import { |
| 4 | + expandHomeFilePath, |
4 | 5 | fileRoutePathSegments, |
5 | 6 | isSvgImagePreviewFile, |
6 | 7 | resolveWorkspaceRelativeFilePath, |
7 | 8 | fileHeaderSubtitle, |
8 | 9 | } from "./filePath"; |
9 | 10 |
|
| 11 | +describe("expandHomeFilePath", () => { |
| 12 | + it.each([ |
| 13 | + ["/Users/tommy/repo", "/Users/tommy/.zshrc"], |
| 14 | + ["/home/tommy/repo", "/home/tommy/.zshrc"], |
| 15 | + ["C:\\Users\\tommy\\repo", "C:\\Users\\tommy\\.zshrc"], |
| 16 | + ])("expands host-home paths inferred from %s", (workspaceRoot, expected) => { |
| 17 | + expect(expandHomeFilePath("~/.zshrc", workspaceRoot)).toBe(expected); |
| 18 | + }); |
| 19 | + |
| 20 | + it.each([null, undefined, "/repo"])( |
| 21 | + "keeps home paths when home cannot be inferred from %s", |
| 22 | + (root) => { |
| 23 | + expect(expandHomeFilePath("~/.zshrc", root)).toBe("~/.zshrc"); |
| 24 | + }, |
| 25 | + ); |
| 26 | + |
| 27 | + it.each(["src/app.ts", "/tmp/report.md"])("preserves existing file paths: %s", (path) => { |
| 28 | + expect(expandHomeFilePath(path, "/Users/tommy/repo")).toBe(path); |
| 29 | + }); |
| 30 | + |
| 31 | + it("routes a home path inside the workspace as a workspace file", () => { |
| 32 | + const root = "/Users/tommy/repo"; |
| 33 | + expect( |
| 34 | + resolveWorkspaceRelativeFilePath(root, expandHomeFilePath("~/repo/src/app.ts", root)), |
| 35 | + ).toBe("src/app.ts"); |
| 36 | + }); |
| 37 | +}); |
| 38 | + |
10 | 39 | describe("fileRoutePathSegments", () => { |
11 | 40 | it("round-trips workspace-relative and host paths through the route", () => { |
12 | 41 | expect(fileRoutePathSegments("src/main.ts")).toEqual(["src", "main.ts"]); |
|
0 commit comments