refactor(test): centralize temp home + polling

This commit is contained in:
Peter Steinberger
2026-01-09 16:48:24 +01:00
parent eb73b4e58e
commit c8b15af979
5 changed files with 98 additions and 94 deletions

25
test/helpers/poll.ts Normal file
View File

@@ -0,0 +1,25 @@
export type PollOptions = {
timeoutMs?: number;
intervalMs?: number;
};
function sleep(ms: number) {
return new Promise<void>((resolve) => setTimeout(resolve, ms));
}
export async function pollUntil<T>(
fn: () => Promise<T | null | undefined>,
opts: PollOptions = {},
): Promise<T | undefined> {
const timeoutMs = opts.timeoutMs ?? 2000;
const intervalMs = opts.intervalMs ?? 25;
const start = Date.now();
while (Date.now() - start < timeoutMs) {
const value = await fn();
if (value !== null && value !== undefined) return value;
await sleep(intervalMs);
}
return undefined;
}