Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
fix(stdio): drain stdio before process.exit (#244)
Browse files Browse the repository at this point in the history
`process.exit()` may not flush stdio, which in turn can lead to the loss of output.
See nodejs/node#6456.

This issue manifests with `max-failures should work` test being flaky,
where we examine large output and it is sometimes truncated.
  • Loading branch information
dgozman authored Apr 23, 2021
1 parent 49c0d46 commit e218b2d
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,20 @@ async function runTests(command: any) {
const runner = new Runner(loader);
const tagFilter = command.tag && command.tag.length ? command.tag : undefined;
const result = await runner.run(!!command.list, testFiles, tagFilter);

// Calling process.exit() might truncate large stdout/stderr output.
// See /~https://github.com/nodejs/node/issues/6456.
//
// We can use writableNeedDrain to workaround this, but it is only available
// since node v15.2.0.
// See https://nodejs.org/api/stream.html#stream_writable_writableneeddrain.
if ((process.stdout as any).writableNeedDrain)
await new Promise(f => process.stdout.on('drain', f));
if ((process.stderr as any).writableNeedDrain)
await new Promise(f => process.stderr.on('drain', f));

if (result === 'sigint')
process.exit(130);

if (result === 'forbid-only') {
console.error('=====================================');
console.error(' --forbid-only found a focused test.');
Expand Down

0 comments on commit e218b2d

Please sign in to comment.