(schedule)
| 110 | } |
| 111 | |
| 112 | async function runOneScheduledTick(schedule) { |
| 113 | const realSetTimeout = global.setTimeout; |
| 114 | const delays = []; |
| 115 | let resolveDone; |
| 116 | const done = new Promise((resolve) => { resolveDone = resolve; }); |
| 117 | global.setTimeout = (fn, delay) => { |
| 118 | delays.push(delay); |
| 119 | const timer = { unref: () => {} }; |
| 120 | if (delays.length === 1) { |
| 121 | realSetTimeout(async () => { |
| 122 | try { |
| 123 | await fn(); |
| 124 | } finally { |
| 125 | resolveDone(); |
| 126 | } |
| 127 | }, 0); |
| 128 | } |
| 129 | return timer; |
| 130 | }; |
| 131 | try { |
| 132 | schedule(); |
| 133 | await done; |
| 134 | } finally { |
| 135 | global.setTimeout = realSetTimeout; |
| 136 | } |
| 137 | return delays; |
| 138 | } |
| 139 | |
| 140 | async function waitFor(predicate, { timeoutMs = 2000, intervalMs = 25 } = {}) { |
| 141 | const deadline = Date.now() + timeoutMs; |
no test coverage detected