Skip to content

Commit 4341754

Browse files
committed
test(custom-modes): make YAML edge case tests path-agnostic on Windows by normalizing fs paths
1 parent d1584a6 commit 4341754

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

src/core/config/__tests__/CustomModesManager.yamlEdgeCases.spec.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ import { GlobalFileNames } from "../../../shared/globalFileNames"
1616

1717
import { CustomModesManager } from "../CustomModesManager"
1818

19+
// Normalize paths for cross-platform (strip drive letter, unify separators)
20+
const normalizePathForTest = (p: string) =>
21+
String(p)
22+
.replace(/^[A-Za-z]:/i, "")
23+
.replace(/\\/g, "/")
24+
1925
vi.mock("vscode", () => ({
2026
workspace: {
2127
workspaceFolders: [],
@@ -44,8 +50,11 @@ describe("CustomModesManager - YAML Edge Cases", () => {
4450

4551
// Helper function to reduce duplication in fs.readFile mocks
4652
const mockFsReadFile = (files: Record<string, string>) => {
47-
;(fs.readFile as Mock).mockImplementation(async (path: string) => {
48-
if (files[path]) return files[path]
53+
;(fs.readFile as Mock).mockImplementation(async (p: string) => {
54+
const needle = normalizePathForTest(p)
55+
for (const [k, v] of Object.entries(files)) {
56+
if (normalizePathForTest(k) === needle) return v
57+
}
4958
throw new Error("File not found")
5059
})
5160
}
@@ -68,12 +77,13 @@ describe("CustomModesManager - YAML Edge Cases", () => {
6877
;(vscode.workspace as any).workspaceFolders = mockWorkspaceFolders
6978
;(vscode.workspace.onDidSaveTextDocument as Mock).mockReturnValue({ dispose: vi.fn() })
7079
;(getWorkspacePath as Mock).mockReturnValue("/mock/workspace")
71-
;(fileExistsAtPath as Mock).mockImplementation(async (path: string) => {
72-
return path === mockSettingsPath || path === mockRoomodes
80+
;(fileExistsAtPath as Mock).mockImplementation(async (p: string) => {
81+
const np = normalizePathForTest(p)
82+
return np === normalizePathForTest(mockSettingsPath) || np === normalizePathForTest(mockRoomodes)
7383
})
7484
;(fs.mkdir as Mock).mockResolvedValue(undefined)
75-
;(fs.readFile as Mock).mockImplementation(async (path: string) => {
76-
if (path === mockSettingsPath) {
85+
;(fs.readFile as Mock).mockImplementation(async (p: string) => {
86+
if (normalizePathForTest(p) === normalizePathForTest(mockSettingsPath)) {
7787
return yaml.stringify({ customModes: [] })
7888
}
7989
throw new Error("File not found")

0 commit comments

Comments
 (0)