Relocate tests under /test (#1220)

This commit is contained in:
Konstantin Konstantinov 2025-12-06 01:56:12 +02:00 • committed by GitHub
commit 5a9de1c638
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

33
test/helpers/tasks.ts Normal file
View file

@ -0,0 +1,33 @@
import type { Task } from '../../src/types.js';
/**
* Polls the provided getTask function until the task reaches the desired status or times out.
*/
export async function waitForTaskStatus(
getTask: (taskId: string) => Promise<Task | null | undefined>,
taskId: string,
desiredStatus: Task['status'],
{
intervalMs = 100,
timeoutMs = 10_000
}: {
intervalMs?: number;
timeoutMs?: number;
} = {}
): Promise<Task> {
const start = Date.now();
// eslint-disable-next-line no-constant-condition
while (true) {
const task = await getTask(taskId);
if (task && task.status === desiredStatus) {
return task;
}
if (Date.now() - start > timeoutMs) {
throw new Error(`Timed out waiting for task ${taskId} to reach status ${desiredStatus}`);
}
await new Promise(resolve => setTimeout(resolve, intervalMs));
}
}