(hookFn, ms = 2000)
| 18 | // callback fired and the argument it received. A done that never fires becomes |
| 19 | // a fast, named rejection instead of a mocha timeout. |
| 20 | function runHook(hookFn, ms = 2000) { |
| 21 | return new Promise((resolve, reject) => { |
| 22 | let count = 0 |
| 23 | let arg |
| 24 | const timer = setTimeout(() => reject(new Error('done callback was never called')), ms) |
| 25 | timer.unref?.() |
| 26 | hookFn(err => { |
| 27 | count++ |
| 28 | arg = err |
| 29 | const settle = setTimeout(() => { |
| 30 | clearTimeout(timer) |
| 31 | resolve({ count, arg }) |
| 32 | }, 50) |
| 33 | settle.unref?.() |
| 34 | }) |
| 35 | }) |
| 36 | } |
| 37 | |
| 38 | describe('AsyncWrapper', () => { |
| 39 | beforeEach(async () => { |
no test coverage detected