| 23 | } |
| 24 | |
| 25 | async run (func, args) { |
| 26 | const timeoutPromise = new Promise((_, reject) => { |
| 27 | setTimeout(() => { |
| 28 | this.timeoutEvent.isSet = true |
| 29 | reject(new Error('Test timed out!')) |
| 30 | }, this.timeout) |
| 31 | }) |
| 32 | |
| 33 | try { |
| 34 | await Promise.race([ |
| 35 | func(this.timeoutEvent, this.log.bind(this), this.results, ...args), |
| 36 | timeoutPromise, |
| 37 | ]) |
| 38 | } catch (error) { |
| 39 | if (error.message === 'Test timed out!') { |
| 40 | this.log('Test timed out!') |
| 41 | } else { |
| 42 | this.log(`Test failed: ${error.message}`) |
| 43 | } |
| 44 | } |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | export class TestGroup { |