chore(llm): try to fix flaky test

This commit is contained in:
Elian Doran 2025-10-09 10:40:35 +03:00
parent 3a3cb0c68d
commit 8ac0425ca5
No known key found for this signature in database
2 changed files with 10 additions and 1 deletions

View File

@ -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,

View File

@ -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));
}