(category: string, expected: string, timeout?: number)
| 435 | * The promise will be rejected as soon as the received data cannot match the expected data or if a timeout occurs. |
| 436 | */ |
| 437 | public assertOutput(category: string, expected: string, timeout?: number): Promise<DebugProtocol.Event> { |
| 438 | |
| 439 | return new Promise((resolve, reject) => { |
| 440 | let output = ''; |
| 441 | let timeoutHandler: any; |
| 442 | this.on('output', event => { |
| 443 | const e = <DebugProtocol.OutputEvent>event; |
| 444 | if (e.body.category === category) { |
| 445 | output += e.body.output; |
| 446 | if (output.indexOf(expected) === 0) { |
| 447 | clearTimeout(timeoutHandler); |
| 448 | resolve(event); |
| 449 | } else if (expected.indexOf(output) !== 0) { |
| 450 | const sanitize = (s: string) => s.toString().replace(/\r/mg, '\\r').replace(/\n/mg, '\\n'); |
| 451 | reject(new Error(`received data '${sanitize(output)}' is not a prefix of the expected data '${sanitize(expected)}'`)); |
| 452 | } |
| 453 | } |
| 454 | }); |
| 455 | if (!this._socket) { // no timeouts if debugging the tests |
| 456 | timeoutHandler = setTimeout(() => { |
| 457 | reject(new Error(`not enough output data received after ${timeout || this.defaultTimeout} ms`)); |
| 458 | }, timeout || this.defaultTimeout); |
| 459 | } |
| 460 | }); |
| 461 | } |
| 462 | |
| 463 | public assertPath(path: string | undefined, expected: string | RegExp | undefined, message?: string) { |
| 464 | if (!expected || !path) { |
no test coverage detected