|
1 | 1 | import * as vscode from "vscode" |
2 | 2 | import { diagnosticsToProblemsString } from ".." |
3 | 3 |
|
| 4 | +// Mock path module |
| 5 | +jest.mock("path", () => ({ |
| 6 | + relative: jest.fn((cwd, fullPath) => { |
| 7 | + // Handle the specific case already present |
| 8 | + if (cwd === "/project/root" && fullPath === "/project/root/src/utils/file.ts") { |
| 9 | + return "src/utils/file.ts" |
| 10 | + } |
| 11 | + // Handle the test cases with /path/to as cwd |
| 12 | + if (cwd === "/path/to") { |
| 13 | + // Simple relative path calculation for the test cases |
| 14 | + return fullPath.replace(cwd + "/", "") |
| 15 | + } |
| 16 | + // Fallback for other cases (can be adjusted if needed) |
| 17 | + return fullPath |
| 18 | + }), |
| 19 | +})) |
| 20 | + |
4 | 21 | // Mock vscode module |
5 | 22 | jest.mock("vscode", () => ({ |
6 | 23 | Uri: { |
@@ -130,7 +147,7 @@ describe("diagnosticsToProblemsString", () => { |
130 | 147 | // Verify the output contains the expected directory indicator |
131 | 148 | expect(result).toContain("(directory)") |
132 | 149 | expect(result).toContain("Directory diagnostic message") |
133 | | - expect(result).toMatch(/directory\n- \[test Error\] 1 \| \(directory\) : Directory diagnostic message/) |
| 150 | + expect(result).toMatch(/directory\/\n- \[test Error\] 1 \| \(directory\) : Directory diagnostic message/) |
134 | 151 | }) |
135 | 152 |
|
136 | 153 | it("should correctly handle multiple diagnostics for the same file", async () => { |
@@ -340,16 +357,6 @@ describe("diagnosticsToProblemsString", () => { |
340 | 357 | } |
341 | 358 | vscode.workspace.openTextDocument = jest.fn().mockResolvedValue(mockDocument) |
342 | 359 |
|
343 | | - // Mock path.relative to return the expected relative path |
344 | | - jest.mock("path", () => ({ |
345 | | - relative: jest.fn((cwd, fullPath) => { |
346 | | - if (cwd === "/project/root" && fullPath === "/project/root/src/utils/file.ts") { |
347 | | - return "src/utils/file.ts" |
348 | | - } |
349 | | - return fullPath |
350 | | - }), |
351 | | - })) |
352 | | - |
353 | 360 | // Call the function with cwd set to the project root |
354 | 361 | const result = await diagnosticsToProblemsString( |
355 | 362 | [[fileUri, [diagnostic]]], |
|
0 commit comments