wait-abort.js
This file
Path
test/resolve/wait-abort.js
127 lines · 10.6 KiB · JavaScript
Last changed by
Fix `stdin` iterables and input transforms edge casesSindre Sorhusbefore adoption6925cc3
History of this fileTake it
The walk stopped after 200 commits: lines older than 9f65b86 point at it.
TweaksSindre Sorhusbefore adoption698a1b8
line 1why, one step back1import assert from 'node:assert/strict';100% test coverage (#1018)ehmickybefore adoption9f65b86
line 2why, one step back2import {setImmediate} from 'node:timers/promises';TweaksSindre Sorhusbefore adoption698a1b8
lines 3–4why, one step back3import test from 'node:test';4import {assertRejects, assertLike} from '../helpers/assert.js';100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 5–6why, one step back5import {execa} from '../../index.js';6import {setFixtureDirectory} from '../helpers/fixtures-directory.js';Fix `stdin` iterables and input transforms edge casesSindre Sorhusbefore adoption6925cc3
lines 7–10why, one step back7import {prematureClose, getStdio} from '../helpers/stdio.js';8import {noopGenerator, noopAsyncGenerator} from '../helpers/generator.js';9import {noopDuplex as noopDuplexTransform} from '../helpers/duplex.js';10import {foobarString} from '../helpers/input.js';100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 11–22why, one step back11import {noopReadable, noopWritable, noopDuplex} from '../helpers/stream.js';12import {13 endOptionStream,14 destroyOptionStream,15 destroySubprocessStream,16 getStreamStdio,17} from '../helpers/wait.js';1819setFixtureDirectory();2021const noop = () => {};22TweaksSindre Sorhusbefore adoption698a1b8
line 23why, one step back23const testStreamAbortWait = async (streamMethod, stream, fdNumber, useTransform) => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 24–30why, one step back24 const subprocess = execa('noop-stdin-fd.js', [`${fdNumber}`], getStreamStdio(fdNumber, stream, useTransform));25 streamMethod({stream, subprocess, fdNumber});26 subprocess.stdin.end();27 await setImmediate();28 stream.destroy();2930 const {stdout} = await subprocess;TweaksSindre Sorhusbefore adoption698a1b8
lines 31–32why, one step back31 assert.equal(stdout, '');32 assert.equal(stream.destroyed, true);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 33–34why, one step back33};34TweaksSindre Sorhusbefore adoption698a1b8
lines 35–40why, one step back35test('Keeps running when stdin option is used and subprocess.stdin ends', () => testStreamAbortWait(noop, noopReadable(), 0, false));36test('Keeps running when stdin option is used and subprocess.stdin Duplex ends', () => testStreamAbortWait(noop, noopDuplex(), 0, false));37test('Keeps running when input stdio[*] option is used and input subprocess.stdio[*] ends', () => testStreamAbortWait(noop, noopReadable(), 3, false));38test('Keeps running when stdin option is used and subprocess.stdin ends, with a transform', () => testStreamAbortWait(noop, noopReadable(), 0, true));39test('Keeps running when stdin option is used and subprocess.stdin Duplex ends, with a transform', () => testStreamAbortWait(noop, noopDuplex(), 0, true));40test('Keeps running when input stdio[*] option is used and input subprocess.stdio[*] ends, with a transform', () => testStreamAbortWait(noop, noopReadable(), 3, true));100% test coverage (#1018)ehmickybefore adoption9f65b86
line 41why, one step back41TweaksSindre Sorhusbefore adoption698a1b8
line 42why, one step back42const testStreamAbortSuccess = async (streamMethod, stream, fdNumber, useTransform) => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 43–47why, one step back43 const subprocess = execa('noop-stdin-fd.js', [`${fdNumber}`], getStreamStdio(fdNumber, stream, useTransform));44 streamMethod({stream, subprocess, fdNumber});45 subprocess.stdin.end();4647 const {stdout} = await subprocess;TweaksSindre Sorhusbefore adoption698a1b8
lines 48–49why, one step back48 assert.equal(stdout, '');49 assert.equal(stream.destroyed, true);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 50–51why, one step back50};51TweaksSindre Sorhusbefore adoption698a1b8
lines 52–75why, one step back52test('Passes when stdin option aborts', () => testStreamAbortSuccess(destroyOptionStream, noopReadable(), 0, false));53test('Passes when stdin option Duplex aborts', () => testStreamAbortSuccess(destroyOptionStream, noopDuplex(), 0, false));54test('Passes when input stdio[*] option aborts', () => testStreamAbortSuccess(destroyOptionStream, noopReadable(), 3, false));55test('Passes when stdout option ends with no more writes', () => testStreamAbortSuccess(endOptionStream, noopWritable(), 1, false));56test('Passes when stderr option ends with no more writes', () => testStreamAbortSuccess(endOptionStream, noopWritable(), 2, false));57test('Passes when output stdio[*] option ends with no more writes', () => testStreamAbortSuccess(endOptionStream, noopWritable(), 3, false));58test('Passes when subprocess.stdout aborts with no more writes', () => testStreamAbortSuccess(destroySubprocessStream, noopWritable(), 1, false));59test('Passes when subprocess.stdout Duplex aborts with no more writes', () => testStreamAbortSuccess(destroySubprocessStream, noopDuplex(), 1, false));60test('Passes when subprocess.stderr aborts with no more writes', () => testStreamAbortSuccess(destroySubprocessStream, noopWritable(), 2, false));61test('Passes when subprocess.stderr Duplex aborts with no more writes', () => testStreamAbortSuccess(destroySubprocessStream, noopDuplex(), 2, false));62test('Passes when output subprocess.stdio[*] aborts with no more writes', () => testStreamAbortSuccess(destroySubprocessStream, noopWritable(), 3, false));63test('Passes when output subprocess.stdio[*] Duplex aborts with no more writes', () => testStreamAbortSuccess(destroySubprocessStream, noopDuplex(), 3, false));64test('Passes when stdin option aborts, with a transform', () => testStreamAbortSuccess(destroyOptionStream, noopReadable(), 0, true));65test('Passes when stdin option Duplex aborts, with a transform', () => testStreamAbortSuccess(destroyOptionStream, noopDuplex(), 0, true));66test('Passes when input stdio[*] option aborts, with a transform', () => testStreamAbortSuccess(destroyOptionStream, noopReadable(), 3, true));67test('Passes when stdout option ends with no more writes, with a transform', () => testStreamAbortSuccess(endOptionStream, noopWritable(), 1, true));68test('Passes when stderr option ends with no more writes, with a transform', () => testStreamAbortSuccess(endOptionStream, noopWritable(), 2, true));69test('Passes when output stdio[*] option ends with no more writes, with a transform', () => testStreamAbortSuccess(endOptionStream, noopWritable(), 3, true));70test('Passes when subprocess.stdout aborts with no more writes, with a transform', () => testStreamAbortSuccess(destroySubprocessStream, noopWritable(), 1, true));71test('Passes when subprocess.stdout Duplex aborts with no more writes, with a transform', () => testStreamAbortSuccess(destroySubprocessStream, noopDuplex(), 1, true));72test('Passes when subprocess.stderr aborts with no more writes, with a transform', () => testStreamAbortSuccess(destroySubprocessStream, noopWritable(), 2, true));73test('Passes when subprocess.stderr Duplex aborts with no more writes, with a transform', () => testStreamAbortSuccess(destroySubprocessStream, noopDuplex(), 2, true));74test('Passes when output subprocess.stdio[*] aborts with no more writes, with a transform', () => testStreamAbortSuccess(destroySubprocessStream, noopWritable(), 3, true));75test('Passes when output subprocess.stdio[*] Duplex aborts with no more writes, with a transform', () => testStreamAbortSuccess(destroySubprocessStream, noopDuplex(), 3, true));100% test coverage (#1018)ehmickybefore adoption9f65b86
line 76why, one step back76TweaksSindre Sorhusbefore adoption698a1b8
line 77why, one step back77const testStreamAbortFail = async (streamMethod, stream, fdNumber, useTransform) => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 78–83why, one step back78 const subprocess = execa('noop-stdin-fd.js', [`${fdNumber}`], getStreamStdio(fdNumber, stream, useTransform));79 streamMethod({stream, subprocess, fdNumber});80 if (fdNumber !== 0) {81 subprocess.stdin.end();82 }83TweaksSindre Sorhusbefore adoption698a1b8
lines 84–86why, one step back84 const error = await assertRejects(subprocess);85 assertLike(error, {...prematureClose, exitCode: 0});86 assert.equal(stream.destroyed, true);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 87–88why, one step back87};88TweaksSindre Sorhusbefore adoption698a1b8
lines 89–106why, one step back89test('Throws abort error when subprocess.stdin aborts', () => testStreamAbortFail(destroySubprocessStream, noopReadable(), 0, false));90test('Throws abort error when subprocess.stdin Duplex aborts', () => testStreamAbortFail(destroySubprocessStream, noopDuplex(), 0, false));91test('Throws abort error when input subprocess.stdio[*] aborts', () => testStreamAbortFail(destroySubprocessStream, noopReadable(), 3, false));92test('Throws abort error when stdout option aborts with no more writes', () => testStreamAbortFail(destroyOptionStream, noopWritable(), 1, false));93test('Throws abort error when stdout option Duplex aborts with no more writes', () => testStreamAbortFail(destroyOptionStream, noopDuplex(), 1, false));94test('Throws abort error when stderr option aborts with no more writes', () => testStreamAbortFail(destroyOptionStream, noopWritable(), 2, false));95test('Throws abort error when stderr option Duplex aborts with no more writes', () => testStreamAbortFail(destroyOptionStream, noopDuplex(), 2, false));96test('Throws abort error when output stdio[*] option aborts with no more writes', () => testStreamAbortFail(destroyOptionStream, noopWritable(), 3, false));97test('Throws abort error when output stdio[*] Duplex option aborts with no more writes', () => testStreamAbortFail(destroyOptionStream, noopDuplex(), 3, false));98test('Throws abort error when subprocess.stdin aborts, with a transform', () => testStreamAbortFail(destroySubprocessStream, noopReadable(), 0, true));99test('Throws abort error when subprocess.stdin Duplex aborts, with a transform', () => testStreamAbortFail(destroySubprocessStream, noopDuplex(), 0, true));100test('Throws abort error when input subprocess.stdio[*] aborts, with a transform', () => testStreamAbortFail(destroySubprocessStream, noopReadable(), 3, true));101test('Throws abort error when stdout option aborts with no more writes, with a transform', () => testStreamAbortFail(destroyOptionStream, noopWritable(), 1, true));102test('Throws abort error when stdout option Duplex aborts with no more writes, with a transform', () => testStreamAbortFail(destroyOptionStream, noopDuplex(), 1, true));103test('Throws abort error when stderr option aborts with no more writes, with a transform', () => testStreamAbortFail(destroyOptionStream, noopWritable(), 2, true));104test('Throws abort error when stderr option Duplex aborts with no more writes, with a transform', () => testStreamAbortFail(destroyOptionStream, noopDuplex(), 2, true));105test('Throws abort error when output stdio[*] option aborts with no more writes, with a transform', () => testStreamAbortFail(destroyOptionStream, noopWritable(), 3, true));106test('Throws abort error when output stdio[*] Duplex option aborts with no more writes, with a transform', () => testStreamAbortFail(destroyOptionStream, noopDuplex(), 3, true));Fix `stdin` iterables and input transforms edge casesSindre Sorhusbefore adoption6925cc3
lines 107–127why, one step back107108// Like with `stdin: 'pipe'`, the subprocess does not need to read its input, nor `subprocess.stdin` to be ended109const testUnusedInputTransform = async (fdNumber, transform) => {110 const {exitCode} = await execa('empty.js', getStdio(fdNumber, {value: transform, input: true}));111 assert.equal(exitCode, 0);112};113114test('Passes when the subprocess does not read stdin, with a transform', () => testUnusedInputTransform(0, noopGenerator(false)));115test('Passes when the subprocess does not read stdin, with an async transform', () => testUnusedInputTransform(0, noopAsyncGenerator(false)));116test('Passes when the subprocess does not read stdin, with a Duplex', () => testUnusedInputTransform(0, noopDuplexTransform(false)));117test('Passes when the subprocess does not read stdin, with a TransformStream', () => testUnusedInputTransform(0, {transform: new TransformStream()}));118test('Passes when the subprocess does not read stdio[*], with a transform', () => testUnusedInputTransform(3, noopGenerator(false)));119test('Passes when the subprocess does not read stdin, with stdin: "pipe"', () => testUnusedInputTransform(0, 'pipe'));120test('Passes when the subprocess does not read stdio[*], with stdio[*]: "pipe"', () => testUnusedInputTransform(3, 'pipe'));121122test('Passes when the subprocess does not read the stdin transform it is written to', async () => {123 const subprocess = execa('empty.js', {stdin: noopGenerator(false)});124 subprocess.stdin.write(foobarString);125 const {exitCode} = await subprocess;126 assert.equal(exitCode, 0);127});