diff --git a/apps/server/src/routes/api/llm.spec.ts b/apps/server/src/routes/api/llm.spec.ts index 81bd9e039..e14012893 100644 --- a/apps/server/src/routes/api/llm.spec.ts +++ b/apps/server/src/routes/api/llm.spec.ts @@ -3,7 +3,7 @@ import { beforeAll, describe, expect, it, vi, beforeEach, afterEach } from "vite import supertest from "supertest"; import config from "../../services/config.js"; import { refreshAuth } from "../../services/auth.js"; -import type { WebSocket } from 'ws'; +import { sleepFor } from "@triliumnext/commons"; // Mock the CSRF protection middleware to allow tests to pass vi.mock("../csrf_protection.js", () => ({ @@ -499,6 +499,7 @@ describe("LLM API Tests", () => { const ws = (await import("../../services/ws.js")).default; // Verify thinking message was sent + await sleepFor(1_000); expect(ws.sendMessageToAllClients).toHaveBeenCalledWith({ type: 'llm-stream', chatNoteId: testChatId, diff --git a/packages/commons/src/lib/test-utils.ts b/packages/commons/src/lib/test-utils.ts index edfe90ef0..86ebfb0d6 100644 --- a/packages/commons/src/lib/test-utils.ts +++ b/packages/commons/src/lib/test-utils.ts @@ -54,3 +54,11 @@ export function trimIndentation(strings: TemplateStringsArray, ...values: any[]) } return output.join("\n"); } + +export function flushPromises() { + return new Promise(setImmediate); +} + +export function sleepFor(duration: number) { + return new Promise(resolve => setTimeout(resolve, duration)); +}