You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
| Stubbing `workspace.workspaceFolders` property | Stub wrapper function `workspaceApis.getWorkspaceFolders()`|
45
+
| Comparing `fsPath` to raw string | Compare `fsPath` to `Uri.file(expected).fsPath`|
46
+
| Stubbing `commands.executeCommand` directly | First update production code to use `executeCommand` from `command.api.ts`, then stub that |
47
+
| Stubbing `window.createTreeView` directly | First update production code to use `createTreeView` from `window.apis.ts`, then stub that |
46
48
47
49
**Pre-flight checklist before completing test work:**
48
50
49
51
-[ ] All paths use `Uri.file().fsPath` (no hardcoded `/path/to/x`)
50
52
-[ ] All VS Code API stubs use wrapper modules, not `vscode.*` directly
53
+
-[ ] Production code uses wrappers for any VS Code API that tests need to stub (check `src/common/*.apis.ts`)
51
54
-[ ] Tests pass on both Windows and POSIX
52
55
53
56
## Test Types
@@ -597,4 +600,5 @@ envConfig.inspect
597
600
- Use `sinon.useFakeTimers()` with `clock.tickAsync()` instead of `await new Promise(resolve => setTimeout(resolve, ms))` for debounce/timeout handling - eliminates flakiness and speeds up tests significantly (1)
598
601
- Always compile tests (`npm run compile-tests`) before running them after adding new test cases - test counts will be wrong if running against stale compiled output (1)
599
602
- Never create "documentation tests" that just `assert.ok(true)` — if mocking limitations prevent testing, either test a different layer that IS mockable, or skip the test entirely with a clear explanation (1)
600
-
- When stubbing vscode APIs in tests via wrapper modules (e.g., `workspaceApis`), the production code must also use those wrappers — sinon cannot stub properties directly on the vscode namespace like `workspace.workspaceFolders`, so both production and test code must reference the same stubbable wrapper functions (3)
603
+
- When stubbing vscode APIs in tests via wrapper modules (e.g., `workspaceApis`), the production code must also use those wrappers — sinon cannot stub properties directly on the vscode namespace like `workspace.workspaceFolders`, so both production and test code must reference the same stubbable wrapper functions (4)
604
+
-**Before writing tests**, check if the function under test calls VS Code APIs directly (e.g., `commands.executeCommand`, `window.createTreeView`, `workspace.getConfiguration`). If so, FIRST update the production code to use wrapper functions from `src/common/*.apis.ts` (create the wrapper if it doesn't exist), THEN write tests that stub those wrappers. This prevents CI failures where sinon cannot stub the vscode namespace (4)
"python-envs.revealProjectInExplorer.title": "Reveal Project in Explorer",
46
+
"python-envs.revealEnvInManagerView.title": "Reveal in Environment Managers View",
46
47
"python-envs.runPetInTerminal.title": "Run Python Environment Tool (PET) in Terminal...",
47
48
"python-envs.alwaysUseUv.description": "When set to true, uv will be used to manage all virtual environments if available. When set to false, uv will only manage virtual environments explicitly created by uv."
0 commit comments