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

path.test.ts

46 lines1.8 KB

1import { describe, expect, it } from "vite-plus/test";
2import {
3 isExplicitRelativePath,
4 isUncPath,
5 isWindowsAbsolutePath,
6 isWindowsDrivePath,
7 normalizeProjectPathForComparison,
8 normalizeProjectPathForDispatch,
9} from "./path.ts";
10​
11describe("path helpers", () => {
12 it("detects windows drive paths", () => {
13 expect(isWindowsDrivePath("C:\\repo")).toBe(true);
14 expect(isWindowsDrivePath("D:/repo")).toBe(true);
15 expect(isWindowsDrivePath("/repo")).toBe(false);
16 });
17​
18 it("detects UNC paths", () => {
19 expect(isUncPath("\\\\server\\share\\repo")).toBe(true);
20 expect(isUncPath("C:\\repo")).toBe(false);
21 });
22​
23 it("detects windows absolute paths", () => {
24 expect(isWindowsAbsolutePath("C:\\repo")).toBe(true);
25 expect(isWindowsAbsolutePath("\\\\server\\share\\repo")).toBe(true);
26 expect(isWindowsAbsolutePath("./repo")).toBe(false);
27 });
28​
29 it("detects explicit relative paths", () => {
30 expect(isExplicitRelativePath(".")).toBe(true);
31 expect(isExplicitRelativePath("..")).toBe(true);
32 expect(isExplicitRelativePath("./repo")).toBe(true);
33 expect(isExplicitRelativePath("..\\repo")).toBe(true);
34 expect(isExplicitRelativePath("~/repo")).toBe(false);
35 });
36​
37 it("normalizes a bare Windows drive root the same as one with a trailing separator", () => {
38 // `C:`, `C:\` and `C:/` all refer to the drive root and must compare equal.
39 expect(normalizeProjectPathForDispatch("C:")).toBe("C:\\");
40 expect(normalizeProjectPathForComparison("C:")).toBe("c:\\");
41 expect(normalizeProjectPathForComparison("C:")).toBe(normalizeProjectPathForComparison("C:\\"));
42 expect(normalizeProjectPathForComparison("C:")).toBe(normalizeProjectPathForComparison("C:/"));
43 // Non-root drive paths keep their trailing separator trimmed as before.
44 expect(normalizeProjectPathForDispatch("C:\\repo\\")).toBe("C:\\repo");
45 });
46});