( predicate: () => boolean, timeoutMs = 1000, )
| 208 | } |
| 209 | |
| 210 | async function waitUntil( |
| 211 | predicate: () => boolean, |
| 212 | timeoutMs = 1000, |
| 213 | ): Promise<void> { |
| 214 | const deadline = Date.now() + timeoutMs |
| 215 | while (Date.now() < deadline) { |
| 216 | if (predicate()) { |
| 217 | return |
| 218 | } |
| 219 | await new Promise(resolve => setTimeout(resolve, 10)) |
| 220 | } |
| 221 | throw new Error('Timed out waiting for background refresh') |
| 222 | } |
| 223 | |
| 224 | beforeAll(async () => { |
| 225 | tempConfigDir = await mkdtemp(join(tmpdir(), 'ncode-metrics-opt-out-test-')) |