Skip to content
Myr

Wait for streams completion on errors (#722)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by ehmicky · committed by GitHub · parent 5eeaab5 · Browse files · 2 files+20 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+20 added−1 removed

  • tests:+17 added−0 removed
  • other:+3 added−1 removed

2 files+20 added−1 removed

modified:lib/stream.js+3 added-1 removed
modified:test/stdio/node-stream.js+17 added
1import {once} from 'node:events';2import {createReadStream, createWriteStream} from 'node:fs';3import {readFile, writeFile, rm} from 'node:fs/promises';4import {Readable, Writable, PassThrough} from 'node:stream';5import {setTimeout} from 'node:timers/promises';6import {callbackify} from 'node:util';7import test from 'ava';8import tempfile from 'tempfile';9import {execa, execaSync} from '../../index.js';10import {setFixtureDir} from '../helpers/fixtures-dir.js';
104 unmodified lines
115116test('stdout can be [Writable, "pipe"] without a file descriptor', testLazyFileWritable, 1);117test('stderr can be [Writable, "pipe"] without a file descriptor', testLazyFileWritable, 2);118test('stdio[*] can be [Writable, "pipe"] without a file descriptor', testLazyFileWritable, 3);119120test('Wait for custom streams destroy on process errors', async t => {121 let waitedForDestroy = false;122 const stream = new Writable({123 destroy: callbackify(async error => {124 await setTimeout(0);125 waitedForDestroy = true;126 return error;127 }),128 });129 const childProcess = execa('forever.js', {stdout: [stream, 'pipe'], timeout: 1});130 const {timedOut} = await t.throwsAsync(childProcess);131 t.true(timedOut);132 t.true(waitedForDestroy);133});