(predicate, { timeoutMs = 2_000, intervalMs = 10 } = {})
| 476 | } |
| 477 | |
| 478 | async function waitFor(predicate, { timeoutMs = 2_000, intervalMs = 10 } = {}) { |
| 479 | const deadline = Date.now() + timeoutMs; |
| 480 | while (Date.now() < deadline) { |
| 481 | if (predicate()) return; |
| 482 | await delay(intervalMs); |
| 483 | } |
| 484 | throw new Error("waitFor: predicate did not become true within the timeout"); |
| 485 | } |
| 486 | |
| 487 | function postJson(url, body) { |
| 488 | const payload = JSON.stringify(body); |
no test coverage detected