iterable.js
This file
Path
test/stdio/iterable.js
202 lines · 10.7 KiB · JavaScript
Last changed by
Upgrade xo (#980)ehmickybefore adoptionccfa412
History of this fileTake it
The walk stopped after 200 commits: lines older than db95b51 point at it.
Fix calling `.kill()` many times (#768)ehmickybefore adoptiondb95b51
line 1why, one step back1import {once} from 'node:events';Improve stream cleanup and termination logic (#775)ehmickybefore adoption5aa90bd
line 2why, one step back2import {setImmediate} from 'node:timers/promises';Fix calling `.kill()` many times (#768)ehmickybefore adoptiondb95b51
lines 3–4why, one step back3import test from 'ava';4import {execa, execaSync} from '../../index.js';Upgrade xo (#980)ehmickybefore adoptionccfa412
line 5why, one step back5import {setFixtureDirectory} from '../helpers/fixtures-directory.js';Fix calling `.kill()` many times (#768)ehmickybefore adoptiondb95b51
line 6why, one step back6import {getStdio} from '../helpers/stdio.js';Upgrade xo (#980)ehmickybefore adoptionccfa412
lines 7–18why, one step back7import {8 foobarString,9 foobarObject,10 foobarObjectString,11 foobarArray,12} from '../helpers/input.js';13import {14 noopGenerator,15 serializeGenerator,16 infiniteGenerator,17 throwingGenerator,18} from '../helpers/generator.js';Fix calling `.kill()` many times (#768)ehmickybefore adoptiondb95b51
lines 19–20why, one step back1920const stringGenerator = function * () {Add support for sync iterables with `execaSync()` (#944)ehmickybefore adoptionf744f7d
line 21why, one step back21 yield * foobarArray;Fix calling `.kill()` many times (#768)ehmickybefore adoptiondb95b51
lines 22–32why, one step back22};2324const textEncoder = new TextEncoder();25const binaryFoo = textEncoder.encode('foo');26const binaryBar = textEncoder.encode('bar');27const binaryArray = [binaryFoo, binaryBar];2829const binaryGenerator = function * () {30 yield * binaryArray;31};32Add support for sync iterables with `execaSync()` (#944)ehmickybefore adoptionf744f7d
lines 33–38why, one step back33const mixedArray = [foobarArray[0], binaryArray[1]];3435const mixedGenerator = function * () {36 yield * mixedArray;37};38Fix calling `.kill()` many times (#768)ehmickybefore adoptiondb95b51
lines 39–40why, one step back39const asyncGenerator = async function * () {40 await setImmediate();Add support for sync iterables with `execaSync()` (#944)ehmickybefore adoptionf744f7d
line 41why, one step back41 yield * foobarArray;Fix calling `.kill()` many times (#768)ehmickybefore adoptiondb95b51
lines 42–43why, one step back42};43Upgrade xo (#980)ehmickybefore adoptionccfa412
line 44why, one step back44setFixtureDirectory();Fix calling `.kill()` many times (#768)ehmickybefore adoptiondb95b51
line 45why, one step back45Add support for sync iterables with `execaSync()` (#944)ehmickybefore adoptionf744f7d
lines 46–47why, one step back46const testIterable = async (t, stdioOption, fdNumber, execaMethod) => {47 const {stdout} = await execaMethod('stdin-fd.js', [`${fdNumber}`], getStdio(fdNumber, stdioOption));Fix calling `.kill()` many times (#768)ehmickybefore adoptiondb95b51
lines 48–50why, one step back48 t.is(stdout, 'foobar');49};50Add support for sync iterables with `execaSync()` (#944)ehmickybefore adoptionf744f7d
lines 51–67why, one step back51test.serial('stdin option can be an array of strings', testIterable, [foobarArray], 0, execa);52test.serial('stdin option can be an array of strings - sync', testIterable, [foobarArray], 0, execaSync);53test.serial('stdio[*] option can be an array of strings', testIterable, [foobarArray], 3, execa);54test.serial('stdin option can be an array of Uint8Arrays', testIterable, [binaryArray], 0, execa);55test.serial('stdin option can be an array of Uint8Arrays - sync', testIterable, [binaryArray], 0, execaSync);56test.serial('stdio[*] option can be an array of Uint8Arrays', testIterable, [binaryArray], 3, execa);57test.serial('stdin option can be an iterable of strings', testIterable, stringGenerator(), 0, execa);58test.serial('stdin option can be an iterable of strings - sync', testIterable, stringGenerator(), 0, execaSync);59test.serial('stdio[*] option can be an iterable of strings', testIterable, stringGenerator(), 3, execa);60test.serial('stdin option can be an iterable of Uint8Arrays', testIterable, binaryGenerator(), 0, execa);61test.serial('stdin option can be an iterable of Uint8Arrays - sync', testIterable, binaryGenerator(), 0, execaSync);62test.serial('stdio[*] option can be an iterable of Uint8Arrays', testIterable, binaryGenerator(), 3, execa);63test.serial('stdin option can be an iterable of strings + Uint8Arrays', testIterable, mixedGenerator(), 0, execa);64test.serial('stdin option can be an iterable of strings + Uint8Arrays - sync', testIterable, mixedGenerator(), 0, execaSync);65test.serial('stdio[*] option can be an iterable of strings + Uint8Arrays', testIterable, mixedGenerator(), 3, execa);66test.serial('stdin option can be an async iterable', testIterable, asyncGenerator(), 0, execa);67test.serial('stdio[*] option can be an async iterable', testIterable, asyncGenerator(), 3, execa);Fix calling `.kill()` many times (#768)ehmickybefore adoptiondb95b51
lines 68–72why, one step back6869const foobarObjectGenerator = function * () {70 yield foobarObject;71};72Add support for sync iterables with `execaSync()` (#944)ehmickybefore adoptionf744f7d
line 73why, one step back73const foobarAsyncObjectGenerator = async function * () {Fix calling `.kill()` many times (#768)ehmickybefore adoptiondb95b51
lines 74–76why, one step back74 yield foobarObject;75};76Add support for transforms with `execaSync()` (#945)ehmickybefore adoptionc5f9f09
lines 77–78why, one step back77const testObjectIterable = async (t, stdioOption, fdNumber, execaMethod) => {78 const {stdout} = await execaMethod('stdin-fd.js', [`${fdNumber}`], getStdio(fdNumber, [stdioOption, serializeGenerator(true)]));Fix calling `.kill()` many times (#768)ehmickybefore adoptiondb95b51
lines 79–81why, one step back79 t.is(stdout, foobarObjectString);80};81Add support for transforms with `execaSync()` (#945)ehmickybefore adoptionc5f9f09
lines 82–89why, one step back82test('stdin option can be an array of objects', testObjectIterable, [foobarObject], 0, execa);83test('stdio[*] option can be an array of objects', testObjectIterable, [foobarObject], 3, execa);84test('stdin option can be an iterable of objects', testObjectIterable, foobarObjectGenerator(), 0, execa);85test('stdio[*] option can be an iterable of objects', testObjectIterable, foobarObjectGenerator(), 3, execa);86test('stdin option can be an async iterable of objects', testObjectIterable, foobarAsyncObjectGenerator(), 0, execa);87test('stdio[*] option can be an async iterable of objects', testObjectIterable, foobarAsyncObjectGenerator(), 3, execa);88test('stdin option can be an array of objects - sync', testObjectIterable, [foobarObject], 0, execaSync);89test('stdin option can be an iterable of objects - sync', testObjectIterable, foobarObjectGenerator(), 0, execaSync);Fix calling `.kill()` many times (#768)ehmickybefore adoptiondb95b51
line 90why, one step back90Add support for transforms with `execaSync()` (#945)ehmickybefore adoptionc5f9f09
lines 91–108why, one step back91const testIterableNoGeneratorsSync = (t, stdioOption, fdNumber) => {92 t.throws(() => {93 execaSync('empty.js', getStdio(fdNumber, stdioOption));94 }, {message: /must be used to serialize/});95};9697test('stdin option cannot be an array of objects without generators - sync', testIterableNoGeneratorsSync, [[foobarObject]], 0);98test('stdin option cannot be an iterable of objects without generators - sync', testIterableNoGeneratorsSync, foobarObjectGenerator(), 0);99100const testIterableNoSerializeSync = (t, stdioOption, fdNumber) => {101 t.throws(() => {102 execaSync('empty.js', getStdio(fdNumber, [stdioOption, noopGenerator()]));103 }, {message: /The `stdin` option's transform must use "objectMode: true" to receive as input: object/});104};105106test('stdin option cannot be an array of objects without serializing - sync', testIterableNoSerializeSync, [foobarObject], 0);107test('stdin option cannot be an iterable of objects without serializing - sync', testIterableNoSerializeSync, foobarObjectGenerator(), 0);108Rename `index` to `fdNumber` (#862)ehmickybefore adoption295ef40
line 109why, one step back109const testIterableSync = (t, stdioOption, fdNumber) => {Fix calling `.kill()` many times (#768)ehmickybefore adoptiondb95b51
line 110why, one step back110 t.throws(() => {Rename `index` to `fdNumber` (#862)ehmickybefore adoption295ef40
line 111why, one step back111 execaSync('empty.js', getStdio(fdNumber, stdioOption));Improve validation of `execaSync()` `stdio` option (#941)ehmickybefore adoptioncc565f9
line 112why, one step back112 }, {message: /an iterable with synchronous methods/});Fix calling `.kill()` many times (#768)ehmickybefore adoptiondb95b51
lines 113–114why, one step back113};114Add support for sync iterables with `execaSync()` (#944)ehmickybefore adoptionf744f7d
lines 115–121why, one step back115test('stdio[*] option cannot be an array of strings - sync', testIterableSync, [foobarArray], 3);116test('stdio[*] option cannot be an array of Uint8Arrays - sync', testIterableSync, [binaryArray], 3);117test('stdio[*] option cannot be an array of objects - sync', testIterableSync, [[foobarObject]], 3);118test('stdio[*] option cannot be an iterable of strings - sync', testIterableSync, stringGenerator(), 3);119test('stdio[*] option cannot be an iterable of Uint8Arrays - sync', testIterableSync, binaryGenerator(), 3);120test('stdio[*] option cannot be an iterable of objects - sync', testIterableSync, foobarObjectGenerator(), 3);121test('stdio[*] option cannot be multiple iterables - sync', testIterableSync, [stringGenerator(), stringGenerator()], 3);Fix calling `.kill()` many times (#768)ehmickybefore adoptiondb95b51
line 122why, one step back122Add support for sync iterables with `execaSync()` (#944)ehmickybefore adoptionf744f7d
lines 123–133why, one step back123const testAsyncIterableSync = (t, stdioOption, fdNumber) => {124 t.throws(() => {125 execaSync('empty.js', getStdio(fdNumber, stdioOption));126 }, {message: /an async iterable with synchronous method/});127};128129test('stdin option cannot be an async iterable - sync', testAsyncIterableSync, asyncGenerator(), 0);130test('stdio[*] option cannot be an async iterable - sync', testAsyncIterableSync, asyncGenerator(), 3);131test('stdin option cannot be an async iterable of objects - sync', testAsyncIterableSync, foobarAsyncObjectGenerator(), 0);132test('stdio[*] option cannot be an async iterable of objects - sync', testAsyncIterableSync, foobarAsyncObjectGenerator(), 3);133Add support for transforms with `execaSync()` (#945)ehmickybefore adoptionc5f9f09
lines 134–137why, one step back134const testIterableError = async (t, fdNumber) => {135 const cause = new Error(foobarString);136 const error = await t.throwsAsync(execa('stdin-fd.js', [`${fdNumber}`], getStdio(fdNumber, throwingGenerator(cause)().transform())));137 t.is(error.cause, cause);Fix calling `.kill()` many times (#768)ehmickybefore adoptiondb95b51
lines 138–139why, one step back138};139Add support for transforms with `execaSync()` (#945)ehmickybefore adoptionc5f9f09
lines 140–141why, one step back140test('stdin option handles errors in iterables', testIterableError, 0);141test('stdio[*] option handles errors in iterables', testIterableError, 3);Fix calling `.kill()` many times (#768)ehmickybefore adoptiondb95b51
line 142why, one step back142Add support for transforms with `execaSync()` (#945)ehmickybefore adoptionc5f9f09
lines 143–148why, one step back143const testIterableErrorSync = (t, fdNumber) => {144 const cause = new Error(foobarString);145 const error = t.throws(() => {146 execaSync('stdin-fd.js', [`${fdNumber}`], getStdio(fdNumber, throwingGenerator(cause)().transform()));147 });148 t.is(error, cause);Add support for sync iterables with `execaSync()` (#944)ehmickybefore adoptionf744f7d
lines 149–150why, one step back149};150Add support for transforms with `execaSync()` (#945)ehmickybefore adoptionc5f9f09
lines 151–152why, one step back151test('stdin option handles errors in iterables - sync', testIterableErrorSync, 0);152test('stdio[*] option handles errors in iterables - sync', testIterableErrorSync, 3);Add support for sync iterables with `execaSync()` (#944)ehmickybefore adoptionf744f7d
line 153why, one step back153Rename `index` to `fdNumber` (#862)ehmickybefore adoption295ef40
line 154why, one step back154const testNoIterableOutput = (t, stdioOption, fdNumber, execaMethod) => {Fix calling `.kill()` many times (#768)ehmickybefore adoptiondb95b51
line 155why, one step back155 t.throws(() => {Rename `index` to `fdNumber` (#862)ehmickybefore adoption295ef40
line 156why, one step back156 execaMethod('empty.js', getStdio(fdNumber, stdioOption));Fix calling `.kill()` many times (#768)ehmickybefore adoptiondb95b51
lines 157–159why, one step back157 }, {message: /cannot be an iterable/});158};159Add support for sync iterables with `execaSync()` (#944)ehmickybefore adoptionf744f7d
lines 160–163why, one step back160test('stdout option cannot be an array of strings', testNoIterableOutput, [foobarArray], 1, execa);161test('stderr option cannot be an array of strings', testNoIterableOutput, [foobarArray], 2, execa);162test('stdout option cannot be an array of strings - sync', testNoIterableOutput, [foobarArray], 1, execaSync);163test('stderr option cannot be an array of strings - sync', testNoIterableOutput, [foobarArray], 2, execaSync);Fix calling `.kill()` many times (#768)ehmickybefore adoptiondb95b51
lines 164–169why, one step back164test('stdout option cannot be an iterable', testNoIterableOutput, stringGenerator(), 1, execa);165test('stderr option cannot be an iterable', testNoIterableOutput, stringGenerator(), 2, execa);166test('stdout option cannot be an iterable - sync', testNoIterableOutput, stringGenerator(), 1, execaSync);167test('stderr option cannot be an iterable - sync', testNoIterableOutput, stringGenerator(), 2, execaSync);168169test('stdin option can be an infinite iterable', async t => {Refactor tests (#934)ehmickybefore adoption52c4bde
line 170why, one step back170 const iterable = infiniteGenerator().transform();Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343
lines 171–174why, one step back171 const subprocess = execa('stdin.js', getStdio(0, iterable));172 await once(subprocess.stdout, 'data');173 subprocess.kill();174 const {stdout} = await t.throwsAsync(subprocess);Fix randomly failing tests (#793)ehmickybefore adoption45475e7
lines 175–176why, one step back175 t.true(stdout.startsWith('foo'));176 t.deepEqual(await iterable.next(), {value: undefined, done: true});Fix calling `.kill()` many times (#768)ehmickybefore adoptiondb95b51
lines 177–178why, one step back177});178Add support for sync iterables with `execaSync()` (#944)ehmickybefore adoptionf744f7d
lines 179–185why, one step back179const testMultipleIterable = async (t, stdioOption, fdNumber, execaMethod) => {180 const {stdout} = await execaMethod('stdin-fd.js', [`${fdNumber}`], getStdio(fdNumber, stdioOption));181 const expectedOutputs = [182 `${foobarArray[0]}${foobarArray[1]}${foobarArray[0]}${foobarArray[1]}`,183 `${foobarArray[0]}${foobarArray[0]}${foobarArray[1]}${foobarArray[1]}`,184 ];185 t.true(expectedOutputs.includes(stdout));Fix calling `.kill()` many times (#768)ehmickybefore adoptiondb95b51
lines 186–187why, one step back186};187Add support for sync iterables with `execaSync()` (#944)ehmickybefore adoptionf744f7d
lines 188–195why, one step back188test('stdin option can be multiple iterables', testMultipleIterable, [stringGenerator(), stringGenerator()], 0, execa);189test('stdio[*] option can be multiple iterables', testMultipleIterable, [stringGenerator(), stringGenerator()], 3, execa);190test('stdin option can be multiple iterables - sync', testMultipleIterable, [stringGenerator(), stringGenerator()], 0, execaSync);191test('stdin option can be multiple mixed iterables', testMultipleIterable, [stringGenerator(), binaryGenerator()], 0, execa);192test('stdio[*] option can be multiple mixed iterables', testMultipleIterable, [stringGenerator(), binaryGenerator()], 3, execa);193test('stdin option can be multiple mixed iterables - sync', testMultipleIterable, [stringGenerator(), binaryGenerator()], 0, execaSync);194test('stdin option can be sync/async mixed iterables', testMultipleIterable, [stringGenerator(), asyncGenerator()], 0, execa);195test('stdio[*] option can be sync/async mixed iterables', testMultipleIterable, [stringGenerator(), asyncGenerator()], 3, execa);Cancel generators when the process errors (#783)ehmickybefore adoption4b487ce
line 196why, one step back196Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343
line 197why, one step back197test('stdin option iterable is canceled on subprocess error', async t => {Refactor tests (#934)ehmickybefore adoption52c4bde
line 198why, one step back198 const iterable = infiniteGenerator().transform();Cancel generators when the process errors (#783)ehmickybefore adoption4b487ce
line 199why, one step back199 await t.throwsAsync(execa('stdin.js', {stdin: iterable, timeout: 1}), {message: /timed out/});Upgrade xo (#980)ehmickybefore adoptionccfa412
line 200why, one step back200 // eslint-disable-next-line no-emptyCancel generators when the process errors (#783)ehmickybefore adoption4b487ce
lines 201–202why, one step back201 for await (const _ of iterable) {}202});