( predicate: () => boolean, label: string, timeoutMs = 2000, )
| 412 | }) |
| 413 | |
| 414 | function waitFor( |
| 415 | predicate: () => boolean, |
| 416 | label: string, |
| 417 | timeoutMs = 2000, |
| 418 | ): Promise<void> { |
| 419 | const deadline = Date.now() + timeoutMs |
| 420 | return new Promise((resolve, reject) => { |
| 421 | const tick = () => { |
| 422 | if (predicate()) { |
| 423 | resolve() |
| 424 | return |
| 425 | } |
| 426 | if (Date.now() >= deadline) { |
| 427 | reject(new Error(`timed out waiting for ${label}`)) |
| 428 | return |
| 429 | } |
| 430 | setTimeout(tick, 10) |
| 431 | } |
| 432 | tick() |
| 433 | }) |
| 434 | } |
| 435 | |
| 436 | function createNativeWsV2LoopbackServer(options?: { |
| 437 | readonly keepRequestsOpen?: boolean |
no test coverage detected