* Helper to wait for a condition with timeout. Used for assertions that depend * on the debounce timer (real setTimeout) firing, or on the real watcher's * event delivery in the end-to-end test.
( condition: () => boolean, timeoutMs = 2000, intervalMs = 25 )
| 39 | * event delivery in the end-to-end test. |
| 40 | */ |
| 41 | function waitFor( |
| 42 | condition: () => boolean, |
| 43 | timeoutMs = 2000, |
| 44 | intervalMs = 25 |
| 45 | ): Promise<void> { |
| 46 | return new Promise((resolve, reject) => { |
| 47 | const start = Date.now(); |
| 48 | const check = () => { |
| 49 | if (condition()) return resolve(); |
| 50 | if (Date.now() - start > timeoutMs) return reject(new Error('waitFor timed out')); |
| 51 | setTimeout(check, intervalMs); |
| 52 | }; |
| 53 | check(); |
| 54 | }); |
| 55 | } |
| 56 | |
| 57 | describe('FileWatcher', () => { |
| 58 | let testDir: string; |