| 321 | * The promise will be rejected if a timeout occurs. |
| 322 | */ |
| 323 | public waitForEvent(eventType: string, description?: string, timeout?: number, match?: (event: DebugProtocol.Event) => boolean): Promise<DebugProtocol.Event> { |
| 324 | let timeoutHandler: any; |
| 325 | const startingTestName = currentTestName; |
| 326 | |
| 327 | return new Promise((resolve, reject) => { |
| 328 | const handler = (event: DebugProtocol.Event) => { |
| 329 | if (!match || match(event)) { |
| 330 | this.removeListener(eventType, handler); |
| 331 | clearTimeout(timeoutHandler); |
| 332 | resolve(event); |
| 333 | } |
| 334 | }; |
| 335 | |
| 336 | this.on(eventType, handler); |
| 337 | if (!this._socket) { // no timeouts if debugging the tests |
| 338 | timeoutHandler = setTimeout(() => { |
| 339 | reject(new Error(`no event '${eventType}' received after ${timeout || this.defaultTimeout} ms (${startingTestName}: ${description})`)); |
| 340 | }, timeout || this.defaultTimeout); |
| 341 | } |
| 342 | }); |
| 343 | } |
| 344 | |
| 345 | /* |
| 346 | * Returns a promise that will resolve if an 'initialized' event was received within some specified time |