Skip to content

test: watch full stdout when waiting for match#23767

Merged
clydin merged 1 commit into
angular:mainfrom
jbedard:e2e-stdout-watch
Aug 29, 2022
Merged

test: watch full stdout when waiting for match#23767
clydin merged 1 commit into
angular:mainfrom
jbedard:e2e-stdout-watch

Conversation

@jbedard
Copy link
Copy Markdown
Contributor

@jbedard jbedard commented Aug 19, 2022

... 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? 🤷

];
});

const errorMessage = await expectToFail(() => ng('build'));
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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');
}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)) {
Copy link
Copy Markdown
Contributor Author

@jbedard jbedard Aug 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) => {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@jbedard jbedard marked this pull request as ready for review August 19, 2022 07:25
@jbedard jbedard requested a review from alan-agius4 August 19, 2022 07:34
@alan-agius4 alan-agius4 added target: patch This PR is targeted for the next patch release action: merge The PR is ready for merge by the caretaker labels Aug 24, 2022
@clydin clydin merged commit fd4755d into angular:main Aug 29, 2022
@angular-automatic-lock-bot
Copy link
Copy Markdown

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot Bot locked and limited conversation to collaborators Sep 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: merge The PR is ready for merge by the caretaker target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants