Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

filePath.test.ts

43 lines1.6 KB

1import { describe, expect, it } from "vite-plus/test";
2​
3import {
4 isBrowserPreviewFile,
5 isImagePreviewFile,
6 isSvgImagePreviewFile,
7 resolveWorkspaceRelativeFilePath,
8} from "./filePath";
9​
10describe("resolveWorkspaceRelativeFilePath", () => {
11 it("keeps normalized workspace-relative paths", () => {
12 expect(resolveWorkspaceRelativeFilePath("/repo", "./src/../src/main.ts")).toBe("src/main.ts");
13 });
14​
15 it("converts absolute paths inside the workspace", () => {
16 expect(
17 resolveWorkspaceRelativeFilePath("/Users/julius/repo", "/Users/julius/repo/src/main.ts"),
18 ).toBe("src/main.ts");
19 expect(resolveWorkspaceRelativeFilePath("C:\\repo", "c:\\repo\\src\\main.ts")).toBe(
20 "src/main.ts",
21 );
22 });
23​
24 it("rejects paths outside the workspace", () => {
25 expect(resolveWorkspaceRelativeFilePath("/repo", "/other/main.ts")).toBeNull();
26 expect(resolveWorkspaceRelativeFilePath("/repo", "../other/main.ts")).toBeNull();
27 expect(resolveWorkspaceRelativeFilePath(null, "/repo/main.ts")).toBeNull();
28 });
29});
30​
31describe("file preview types", () => {
32 it("recognizes browser and image previews", () => {
33 expect(isBrowserPreviewFile("reports/summary.html")).toBe(true);
34 expect(isImagePreviewFile("assets/icon.png")).toBe(true);
35 expect(isImagePreviewFile("assets/diagram.SVG?raw=1")).toBe(true);
36 expect(isImagePreviewFile("src/image.ts")).toBe(false);
37 });
38​
39 it("identifies SVG images that need web rendering", () => {
40 expect(isSvgImagePreviewFile("assets/diagram.svg#icon")).toBe(true);
41 expect(isSvgImagePreviewFile("assets/photo.png")).toBe(false);
42 });
43});