* 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 )
| 43 | * event delivery in the end-to-end test. |
| 44 | */ |
| 45 | function waitFor( |
| 46 | condition: () => boolean, |
| 47 | timeoutMs = 2000, |
| 48 | intervalMs = 25 |
| 49 | ): Promise<void> { |
| 50 | return new Promise((resolve, reject) => { |
| 51 | const start = Date.now(); |
| 52 | const check = () => { |
| 53 | if (condition()) return resolve(); |
| 54 | if (Date.now() - start > timeoutMs) return reject(new Error('waitFor timed out')); |
| 55 | setTimeout(check, intervalMs); |
| 56 | }; |
| 57 | check(); |
| 58 | }); |
| 59 | } |
| 60 | |
| 61 | describe('FileWatcher', () => { |
| 62 | let testDir: string; |
no test coverage detected