Skip to content

Commit 900af52

Browse files
committed
fix: update WorkspaceTracker test to handle async operations correctly
1 parent 62c84b9 commit 900af52

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/integrations/workspace/__tests__/WorkspaceTracker.spec.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ describe("WorkspaceTracker", () => {
8282
// Create provider mock
8383
mockProvider = {
8484
postMessageToWebview: vitest.fn().mockResolvedValue(undefined),
85-
} as unknown as ClineProvider & { postMessageToWebview: Mock }
85+
handleWorkspaceFolderChange: vitest.fn().mockResolvedValue(undefined),
86+
} as unknown as ClineProvider & { postMessageToWebview: Mock; handleWorkspaceFolderChange: Mock }
8687

8788
// Create tracker instance
8889
workspaceTracker = new WorkspaceTracker(mockProvider)
@@ -225,23 +226,32 @@ describe("WorkspaceTracker", () => {
225226
// Simulate tab change event
226227
await registeredTabChangeCallback!()
227228

228-
// Run the debounce timer for workspaceDidReset
229+
// Run the debounce timer for workspaceDidReset (300ms)
229230
vitest.advanceTimersByTime(300)
230231

232+
// Wait for the async operations in the timeout callback to complete
233+
await Promise.resolve() // For the setTimeout callback
234+
await Promise.resolve() // For the async operations inside
235+
await Promise.resolve() // For handleWorkspaceFolderChange
236+
231237
// Should clear file paths and reset workspace
232238
expect(mockProvider.postMessageToWebview).toHaveBeenCalledWith({
233239
type: "workspaceUpdated",
234240
filePaths: [],
235241
openedTabs: [],
236242
})
237243

244+
// Should have called handleWorkspaceFolderChange
245+
expect(mockProvider.handleWorkspaceFolderChange).toHaveBeenCalled()
246+
238247
// Run all remaining timers to complete initialization
239-
await Promise.resolve() // Wait for initializeFilePaths to complete
240248
vitest.runAllTimers()
241249

250+
// Wait for initializeFilePaths to complete
251+
await Promise.resolve()
252+
242253
// Should initialize file paths for new workspace
243254
expect(listFiles).toHaveBeenCalledWith("/test/new-workspace", true, 1000)
244-
vitest.runAllTimers()
245255
})
246256

247257
it("should not update file paths if workspace changes during initialization", async () => {

0 commit comments

Comments
 (0)