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

fix(stdio): drain stdio before process.exit #244

Merged
merged 1 commit into from
Apr 23, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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