test: watch full stdout when waiting for match#23767
Conversation
| ]; | ||
| }); | ||
|
|
||
| const errorMessage = await expectToFail(() => ng('build')); |
There was a problem hiding this comment.
errorMessage is an Error and this was relying on errorMessage.toString() in the .test below. When making the expectToFail return type stricter this becomes an error.
| `STDOUT:\n${stdout}`, | ||
| `STDERR:\n${stderr}`, | ||
| ].join('\n\n'); | ||
| } |
There was a problem hiding this comment.
Everything above here was just moved into the new Promise so the waitForMatch logic in the callbacks can resolve the promise.
| childProcess.stdout!.on('data', (data: Buffer) => { | ||
| stdout += data.toString('utf-8'); | ||
|
|
||
| if (options.waitForMatch && stdout.match(options.waitForMatch)) { |
There was a problem hiding this comment.
Previously this did data.match which in theory could fail if the stdout was spread across multiple 'data' events (this was in the deleted if (options.waitForMatch below). Same with stderr.
| .forEach((line) => console.error(colors.yellow(' ' + line))); | ||
| }); | ||
|
|
||
| childProcess.on('close', (code: number) => { |
There was a problem hiding this comment.
Note this changed from exit to close to ensure stdout/err have completed:
https://nodejs.org/api/child_process.html#event-close
The 'close' event is emitted after a process has ended and the stdio streams of a child process have been closed
https://nodejs.org/api/child_process.html#event-exit
When the 'exit' event is triggered, child process stdio streams might still be open.
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
... and cleanup a few typescript types.
I've been debugging a failing test where stderr is not being matched. I tried these fixes and figured they may as well be merged? 🤷