mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 07:10:43 +00:00
test: stabilize gateway test helpers
This commit is contained in:
@@ -234,23 +234,7 @@ vi.mock("../../media/store.js", async () => {
|
||||
const { chatHandlers } = await import("./chat.js");
|
||||
|
||||
async function waitForAssertion(assertion: () => void, timeoutMs = 1000, stepMs = 2) {
|
||||
vi.useFakeTimers();
|
||||
try {
|
||||
let lastError: unknown;
|
||||
for (let elapsed = 0; elapsed <= timeoutMs; elapsed += stepMs) {
|
||||
try {
|
||||
assertion();
|
||||
return;
|
||||
} catch (error) {
|
||||
lastError = error;
|
||||
}
|
||||
await Promise.resolve();
|
||||
await vi.advanceTimersByTimeAsync(stepMs);
|
||||
}
|
||||
throw lastError ?? new Error("assertion did not pass in time");
|
||||
} finally {
|
||||
vi.useRealTimers();
|
||||
}
|
||||
await vi.waitFor(assertion, { interval: stepMs, timeout: timeoutMs });
|
||||
}
|
||||
|
||||
function createTranscriptFixture(prefix: string) {
|
||||
|
||||
Reference in New Issue
Block a user