Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: watch full stdout when waiting for match #23767

Merged
merged 1 commit into from Aug 29, 2022

Conversation

jbedard
Copy link
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? 馃し

@@ -17,7 +17,7 @@ export default async function () {
];
});

const errorMessage = await expectToFail(() => ng('build'));
Copy link
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
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
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
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
@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

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.

None yet

3 participants