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

Commit e218b2d

Browse files
authored
fix(stdio): drain stdio before process.exit (#244)
`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.
1 parent 49c0d46 commit e218b2d

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/cli.ts

+12-1
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,20 @@ async function runTests(command: any) {
133133
const runner = new Runner(loader);
134134
const tagFilter = command.tag && command.tag.length ? command.tag : undefined;
135135
const result = await runner.run(!!command.list, testFiles, tagFilter);
136+
137+
// Calling process.exit() might truncate large stdout/stderr output.
138+
// See https://github.com/nodejs/node/issues/6456.
139+
//
140+
// We can use writableNeedDrain to workaround this, but it is only available
141+
// since node v15.2.0.
142+
// See https://nodejs.org/api/stream.html#stream_writable_writableneeddrain.
143+
if ((process.stdout as any).writableNeedDrain)
144+
await new Promise(f => process.stdout.on('drain', f));
145+
if ((process.stderr as any).writableNeedDrain)
146+
await new Promise(f => process.stderr.on('drain', f));
147+
136148
if (result === 'sigint')
137149
process.exit(130);
138-
139150
if (result === 'forbid-only') {
140151
console.error('=====================================');
141152
console.error(' --forbid-only found a focused test.');

0 commit comments

Comments
 (0)