Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
Complete vi.waitFor() migration for all async streaming tests
copilot-swe-agent[bot]993d53ed97b8
diff --git a/apps/server/src/routes/api/llm.spec.ts b/apps/server/src/routes/api/llm.spec.tsindex 913b515c2b..a1f1ca3c20 100644--- a/apps/server/src/routes/api/llm.spec.ts+++ b/apps/server/src/routes/api/llm.spec.ts@@ -382,12 +382,19 @@ describe("LLM API Tests", () => {message: "Streaming initiated successfully"});- // Wait for async streaming operations to complete- await new Promise(resolve => setTimeout(resolve, 100));-// Import ws service to access mockconst ws = (await import("../../services/ws.js")).default;+ // Wait for async streaming operations to complete+ await vi.waitFor(() => {+ expect(ws.sendMessageToAllClients).toHaveBeenCalledWith({+ type: 'llm-stream',+ chatNoteId: testChatId,+ content: ' world!',+ done: true+ });+ }, { timeout: 1000, interval: 50 });+// Verify WebSocket messages were sentexpect(ws.sendMessageToAllClients).toHaveBeenCalledWith({type: 'llm-stream',@@ -539,12 +546,19 @@ describe("LLM API Tests", () => {expect(response.status).toBe(200);- // Wait for async streaming operations to complete- await new Promise(resolve => setTimeout(resolve, 100));-// Import ws service to access mockconst ws = (await import("../../services/ws.js")).default;+ // Wait for async streaming operations to complete+ await vi.waitFor(() => {+ expect(ws.sendMessageToAllClients).toHaveBeenCalledWith({+ type: 'llm-stream',+ chatNoteId: testChatId,+ thinking: 'Formulating response...',+ done: false+ });+ }, { timeout: 1000, interval: 50 });+// Verify thinking messagesexpect(ws.sendMessageToAllClients).toHaveBeenCalledWith({type: 'llm-stream',@@ -589,12 +603,26 @@ describe("LLM API Tests", () => {expect(response.status).toBe(200);- // Wait for async streaming operations to complete- await new Promise(resolve => setTimeout(resolve, 100));-// Import ws service to access mockconst ws = (await import("../../services/ws.js")).default;+ // Wait for async streaming operations to complete+ await vi.waitFor(() => {+ expect(ws.sendMessageToAllClients).toHaveBeenCalledWith({+ type: 'llm-stream',+ chatNoteId: testChatId,+ toolExecution: {+ tool: 'calculator',+ args: { expression: '2 + 2' },+ result: '4',+ toolCallId: 'call_123',+ action: 'execute',+ error: undefined+ },+ done: false+ });+ }, { timeout: 1000, interval: 50 });+// Verify tool execution messageexpect(ws.sendMessageToAllClients).toHaveBeenCalledWith({type: 'llm-stream',