(type: string, filter?: (notification: T) => boolean)
| 320 | } |
| 321 | |
| 322 | public waitForCustomEvent<T>(type: string, filter?: (notification: T) => boolean): Promise<T> { |
| 323 | return new Promise((resolve, reject) => { |
| 324 | setTimeout( |
| 325 | () => { |
| 326 | reject(new Error(`No customEvent '${type}' matching ${filter} received after ${this.defaultTimeout} ms`)); |
| 327 | }, |
| 328 | this.defaultTimeout, |
| 329 | ); |
| 330 | const handler = (event: DebugProtocol.Event) => { |
| 331 | try { |
| 332 | const notification = event.body as T; |
| 333 | if (!filter || filter(notification)) { |
| 334 | this.removeListener(type, handler); |
| 335 | resolve(notification); |
| 336 | } |
| 337 | } catch (e) { |
| 338 | this.removeListener(type, handler); |
| 339 | reject(e); |
| 340 | } |
| 341 | }; |
| 342 | this.on(type, handler); |
| 343 | this.on("terminated", () => this.removeListener(type, handler)); |
| 344 | }); |
| 345 | } |
| 346 | |
| 347 | public async waitForTestNotification<T extends Notification>(type: string, filter: (notification: T) => boolean): Promise<void> { |
| 348 | await this.waitForCustomEvent<T>( |
no test coverage detected