Skip to content
Myr

iterable.js

This file

Path

test/stdio/iterable.js

192 lines · 10.7 KiB · JavaScript

Last changed by

Add support for transforms with `execaSync()` (#945)ehmickybefore adoptionc5f9f09

History of this file

Take it

The walk stopped after 200 commits: lines older than 249e7c4 point at it.

Improve error handling (#647)ehmickybefore adoption5b6d859

line 1why, one step back
1import {once} from 'node:events';

Improve stream cleanup and termination logic (#775)ehmickybefore adoption5aa90bd

line 2why, one step back
2import {setImmediate} from 'node:timers/promises';

Improve performance of `childProcess.all` when `stdout` or `stderr` is `ignore` (#646)ehmickybefore adoption249e7c4

lines 3–5why, one step back
3import test from 'ava';
4import {execa, execaSync} from '../../index.js';5import {setFixtureDir} from '../helpers/fixtures-dir.js';

Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207

line 6why, one step back
6import {getStdio} from '../helpers/stdio.js';

Add support for transforms with `execaSync()` (#945)ehmickybefore adoptionc5f9f09

lines 7–8why, one step back
7import {foobarString, foobarObject, foobarObjectString, foobarArray} from '../helpers/input.js';
8import {noopGenerator, serializeGenerator, infiniteGenerator, throwingGenerator} from '../helpers/generator.js';

Improve performance of `childProcess.all` when `stdout` or `stderr` is `ignore` (#646)ehmickybefore adoption249e7c4

line 9why, one step back
9

Allow any type with transforms (#709)ehmickybefore adoptioned8b2ce

line 10why, one step back
10const stringGenerator = function * () {

Add support for sync iterables with `execaSync()` (#944)ehmickybefore adoptionf744f7d

line 11why, one step back
11 yield * foobarArray;

Allow any type with transforms (#709)ehmickybefore adoptioned8b2ce

lines 12–22why, one step back
12};
1314const textEncoder = new TextEncoder();15const binaryFoo = textEncoder.encode('foo');16const binaryBar = textEncoder.encode('bar');17const binaryArray = [binaryFoo, binaryBar];1819const binaryGenerator = function * () {20 yield * binaryArray;21};22

Add support for sync iterables with `execaSync()` (#944)ehmickybefore adoptionf744f7d

lines 23–28why, one step back
23const mixedArray = [foobarArray[0], binaryArray[1]];
2425const mixedGenerator = function * () {26 yield * mixedArray;27};28

Allow any type with transforms (#709)ehmickybefore adoptioned8b2ce

line 29why, one step back
29const asyncGenerator = async function * () {

Prefer `setImmediate()` over `setTimeout()` (#733)ehmickybefore adoption66d12bf

line 30why, one step back
30 await setImmediate();

Add support for sync iterables with `execaSync()` (#944)ehmickybefore adoptionf744f7d

line 31why, one step back
31 yield * foobarArray;

Allow any type with transforms (#709)ehmickybefore adoptioned8b2ce

lines 32–33why, one step back
32};
33

Improve performance of `childProcess.all` when `stdout` or `stderr` is `ignore` (#646)ehmickybefore adoption249e7c4

lines 34–35why, one step back
34setFixtureDir();
35

Add support for sync iterables with `execaSync()` (#944)ehmickybefore adoptionf744f7d

lines 36–37why, one step back
36const testIterable = async (t, stdioOption, fdNumber, execaMethod) => {
37 const {stdout} = await execaMethod('stdin-fd.js', [`${fdNumber}`], getStdio(fdNumber, stdioOption));

Improve performance of `childProcess.all` when `stdout` or `stderr` is `ignore` (#646)ehmickybefore adoption249e7c4

lines 38–40why, one step back
38 t.is(stdout, 'foobar');
39};40

Add support for sync iterables with `execaSync()` (#944)ehmickybefore adoptionf744f7d

lines 41–57why, one step back
41test.serial('stdin option can be an array of strings', testIterable, [foobarArray], 0, execa);
42test.serial('stdin option can be an array of strings - sync', testIterable, [foobarArray], 0, execaSync);43test.serial('stdio[*] option can be an array of strings', testIterable, [foobarArray], 3, execa);44test.serial('stdin option can be an array of Uint8Arrays', testIterable, [binaryArray], 0, execa);45test.serial('stdin option can be an array of Uint8Arrays - sync', testIterable, [binaryArray], 0, execaSync);46test.serial('stdio[*] option can be an array of Uint8Arrays', testIterable, [binaryArray], 3, execa);47test.serial('stdin option can be an iterable of strings', testIterable, stringGenerator(), 0, execa);48test.serial('stdin option can be an iterable of strings - sync', testIterable, stringGenerator(), 0, execaSync);49test.serial('stdio[*] option can be an iterable of strings', testIterable, stringGenerator(), 3, execa);50test.serial('stdin option can be an iterable of Uint8Arrays', testIterable, binaryGenerator(), 0, execa);51test.serial('stdin option can be an iterable of Uint8Arrays - sync', testIterable, binaryGenerator(), 0, execaSync);52test.serial('stdio[*] option can be an iterable of Uint8Arrays', testIterable, binaryGenerator(), 3, execa);53test.serial('stdin option can be an iterable of strings + Uint8Arrays', testIterable, mixedGenerator(), 0, execa);54test.serial('stdin option can be an iterable of strings + Uint8Arrays - sync', testIterable, mixedGenerator(), 0, execaSync);55test.serial('stdio[*] option can be an iterable of strings + Uint8Arrays', testIterable, mixedGenerator(), 3, execa);56test.serial('stdin option can be an async iterable', testIterable, asyncGenerator(), 0, execa);57test.serial('stdio[*] option can be an async iterable', testIterable, asyncGenerator(), 3, execa);

Improve performance of `childProcess.all` when `stdout` or `stderr` is `ignore` (#646)ehmickybefore adoption249e7c4

line 58why, one step back
58

Allow any type with transforms (#709)ehmickybefore adoptioned8b2ce

lines 59–62why, one step back
59const foobarObjectGenerator = function * () {
60 yield foobarObject;61};62

Add support for sync iterables with `execaSync()` (#944)ehmickybefore adoptionf744f7d

line 63why, one step back
63const foobarAsyncObjectGenerator = async function * () {

Allow any type with transforms (#709)ehmickybefore adoptioned8b2ce

lines 64–66why, one step back
64 yield foobarObject;
65};66

Add support for transforms with `execaSync()` (#945)ehmickybefore adoptionc5f9f09

lines 67–68why, one step back
67const testObjectIterable = async (t, stdioOption, fdNumber, execaMethod) => {
68 const {stdout} = await execaMethod('stdin-fd.js', [`${fdNumber}`], getStdio(fdNumber, [stdioOption, serializeGenerator(true)]));

Allow any type with transforms (#709)ehmickybefore adoptioned8b2ce

lines 69–71why, one step back
69 t.is(stdout, foobarObjectString);
70};71

Add support for transforms with `execaSync()` (#945)ehmickybefore adoptionc5f9f09

lines 72–79why, one step back
72test('stdin option can be an array of objects', testObjectIterable, [foobarObject], 0, execa);
73test('stdio[*] option can be an array of objects', testObjectIterable, [foobarObject], 3, execa);74test('stdin option can be an iterable of objects', testObjectIterable, foobarObjectGenerator(), 0, execa);75test('stdio[*] option can be an iterable of objects', testObjectIterable, foobarObjectGenerator(), 3, execa);76test('stdin option can be an async iterable of objects', testObjectIterable, foobarAsyncObjectGenerator(), 0, execa);77test('stdio[*] option can be an async iterable of objects', testObjectIterable, foobarAsyncObjectGenerator(), 3, execa);78test('stdin option can be an array of objects - sync', testObjectIterable, [foobarObject], 0, execaSync);79test('stdin option can be an iterable of objects - sync', testObjectIterable, foobarObjectGenerator(), 0, execaSync);

Allow any type with transforms (#709)ehmickybefore adoptioned8b2ce

line 80why, one step back
80

Add support for transforms with `execaSync()` (#945)ehmickybefore adoptionc5f9f09

lines 81–98why, one step back
81const testIterableNoGeneratorsSync = (t, stdioOption, fdNumber) => {
82 t.throws(() => {83 execaSync('empty.js', getStdio(fdNumber, stdioOption));84 }, {message: /must be used to serialize/});85};8687test('stdin option cannot be an array of objects without generators - sync', testIterableNoGeneratorsSync, [[foobarObject]], 0);88test('stdin option cannot be an iterable of objects without generators - sync', testIterableNoGeneratorsSync, foobarObjectGenerator(), 0);8990const testIterableNoSerializeSync = (t, stdioOption, fdNumber) => {91 t.throws(() => {92 execaSync('empty.js', getStdio(fdNumber, [stdioOption, noopGenerator()]));93 }, {message: /The `stdin` option's transform must use "objectMode: true" to receive as input: object/});94};9596test('stdin option cannot be an array of objects without serializing - sync', testIterableNoSerializeSync, [foobarObject], 0);97test('stdin option cannot be an iterable of objects without serializing - sync', testIterableNoSerializeSync, foobarObjectGenerator(), 0);98

Rename `index` to `fdNumber` (#862)ehmickybefore adoption295ef40

line 99why, one step back
99const testIterableSync = (t, stdioOption, fdNumber) => {

Improve performance of `childProcess.all` when `stdout` or `stderr` is `ignore` (#646)ehmickybefore adoption249e7c4

line 100why, one step back
100 t.throws(() => {

Rename `index` to `fdNumber` (#862)ehmickybefore adoption295ef40

line 101why, one step back
101 execaSync('empty.js', getStdio(fdNumber, stdioOption));

Improve validation of `execaSync()` `stdio` option (#941)ehmickybefore adoptioncc565f9

line 102why, one step back
102 }, {message: /an iterable with synchronous methods/});

Improve performance of `childProcess.all` when `stdout` or `stderr` is `ignore` (#646)ehmickybefore adoption249e7c4

lines 103–104why, one step back
103};
104

Add support for sync iterables with `execaSync()` (#944)ehmickybefore adoptionf744f7d

lines 105–111why, one step back
105test('stdio[*] option cannot be an array of strings - sync', testIterableSync, [foobarArray], 3);
106test('stdio[*] option cannot be an array of Uint8Arrays - sync', testIterableSync, [binaryArray], 3);107test('stdio[*] option cannot be an array of objects - sync', testIterableSync, [[foobarObject]], 3);108test('stdio[*] option cannot be an iterable of strings - sync', testIterableSync, stringGenerator(), 3);109test('stdio[*] option cannot be an iterable of Uint8Arrays - sync', testIterableSync, binaryGenerator(), 3);110test('stdio[*] option cannot be an iterable of objects - sync', testIterableSync, foobarObjectGenerator(), 3);111test('stdio[*] option cannot be multiple iterables - sync', testIterableSync, [stringGenerator(), stringGenerator()], 3);

Improve performance of `childProcess.all` when `stdout` or `stderr` is `ignore` (#646)ehmickybefore adoption249e7c4

line 112why, one step back
112

Add support for sync iterables with `execaSync()` (#944)ehmickybefore adoptionf744f7d

lines 113–123why, one step back
113const testAsyncIterableSync = (t, stdioOption, fdNumber) => {
114 t.throws(() => {115 execaSync('empty.js', getStdio(fdNumber, stdioOption));116 }, {message: /an async iterable with synchronous method/});117};118119test('stdin option cannot be an async iterable - sync', testAsyncIterableSync, asyncGenerator(), 0);120test('stdio[*] option cannot be an async iterable - sync', testAsyncIterableSync, asyncGenerator(), 3);121test('stdin option cannot be an async iterable of objects - sync', testAsyncIterableSync, foobarAsyncObjectGenerator(), 0);122test('stdio[*] option cannot be an async iterable of objects - sync', testAsyncIterableSync, foobarAsyncObjectGenerator(), 3);123

Add support for transforms with `execaSync()` (#945)ehmickybefore adoptionc5f9f09

lines 124–127why, one step back
124const testIterableError = async (t, fdNumber) => {
125 const cause = new Error(foobarString);126 const error = await t.throwsAsync(execa('stdin-fd.js', [`${fdNumber}`], getStdio(fdNumber, throwingGenerator(cause)().transform())));127 t.is(error.cause, cause);

Improve performance of `childProcess.all` when `stdout` or `stderr` is `ignore` (#646)ehmickybefore adoption249e7c4

lines 128–129why, one step back
128};
129

Add support for transforms with `execaSync()` (#945)ehmickybefore adoptionc5f9f09

lines 130–131why, one step back
130test('stdin option handles errors in iterables', testIterableError, 0);
131test('stdio[*] option handles errors in iterables', testIterableError, 3);

Improve performance of `childProcess.all` when `stdout` or `stderr` is `ignore` (#646)ehmickybefore adoption249e7c4

line 132why, one step back
132

Add support for transforms with `execaSync()` (#945)ehmickybefore adoptionc5f9f09

lines 133–138why, one step back
133const testIterableErrorSync = (t, fdNumber) => {
134 const cause = new Error(foobarString);135 const error = t.throws(() => {136 execaSync('stdin-fd.js', [`${fdNumber}`], getStdio(fdNumber, throwingGenerator(cause)().transform()));137 });138 t.is(error, cause);

Add support for sync iterables with `execaSync()` (#944)ehmickybefore adoptionf744f7d

lines 139–140why, one step back
139};
140

Add support for transforms with `execaSync()` (#945)ehmickybefore adoptionc5f9f09

lines 141–142why, one step back
141test('stdin option handles errors in iterables - sync', testIterableErrorSync, 0);
142test('stdio[*] option handles errors in iterables - sync', testIterableErrorSync, 3);

Add support for sync iterables with `execaSync()` (#944)ehmickybefore adoptionf744f7d

line 143why, one step back
143

Rename `index` to `fdNumber` (#862)ehmickybefore adoption295ef40

line 144why, one step back
144const testNoIterableOutput = (t, stdioOption, fdNumber, execaMethod) => {

Improve performance of `childProcess.all` when `stdout` or `stderr` is `ignore` (#646)ehmickybefore adoption249e7c4

line 145why, one step back
145 t.throws(() => {

Rename `index` to `fdNumber` (#862)ehmickybefore adoption295ef40

line 146why, one step back
146 execaMethod('empty.js', getStdio(fdNumber, stdioOption));

Improve performance of `childProcess.all` when `stdout` or `stderr` is `ignore` (#646)ehmickybefore adoption249e7c4

lines 147–149why, one step back
147 }, {message: /cannot be an iterable/});
148};149

Add support for sync iterables with `execaSync()` (#944)ehmickybefore adoptionf744f7d

lines 150–153why, one step back
150test('stdout option cannot be an array of strings', testNoIterableOutput, [foobarArray], 1, execa);
151test('stderr option cannot be an array of strings', testNoIterableOutput, [foobarArray], 2, execa);152test('stdout option cannot be an array of strings - sync', testNoIterableOutput, [foobarArray], 1, execaSync);153test('stderr option cannot be an array of strings - sync', testNoIterableOutput, [foobarArray], 2, execaSync);

Allow any type with transforms (#709)ehmickybefore adoptioned8b2ce

lines 154–158why, one step back
154test('stdout option cannot be an iterable', testNoIterableOutput, stringGenerator(), 1, execa);
155test('stderr option cannot be an iterable', testNoIterableOutput, stringGenerator(), 2, execa);156test('stdout option cannot be an iterable - sync', testNoIterableOutput, stringGenerator(), 1, execaSync);157test('stderr option cannot be an iterable - sync', testNoIterableOutput, stringGenerator(), 2, execaSync);158

Improve error handling (#647)ehmickybefore adoption5b6d859

line 159why, one step back
159test('stdin option can be an infinite iterable', async t => {

Refactor tests (#934)ehmickybefore adoption52c4bde

line 160why, one step back
160 const iterable = infiniteGenerator().transform();

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

lines 161–164why, one step back
161 const subprocess = execa('stdin.js', getStdio(0, iterable));
162 await once(subprocess.stdout, 'data');163 subprocess.kill();164 const {stdout} = await t.throwsAsync(subprocess);

Fix randomly failing tests (#793)ehmickybefore adoption45475e7

lines 165–166why, one step back
165 t.true(stdout.startsWith('foo'));
166 t.deepEqual(await iterable.next(), {value: undefined, done: true});

Improve error handling (#647)ehmickybefore adoption5b6d859

line 167why, one step back
167});

Fix using multiple `stdin` values (#661)ehmickybefore adoption4d8f9ca

line 168why, one step back
168

Add support for sync iterables with `execaSync()` (#944)ehmickybefore adoptionf744f7d

lines 169–175why, one step back
169const testMultipleIterable = async (t, stdioOption, fdNumber, execaMethod) => {
170 const {stdout} = await execaMethod('stdin-fd.js', [`${fdNumber}`], getStdio(fdNumber, stdioOption));171 const expectedOutputs = [172 `${foobarArray[0]}${foobarArray[1]}${foobarArray[0]}${foobarArray[1]}`,173 `${foobarArray[0]}${foobarArray[0]}${foobarArray[1]}${foobarArray[1]}`,174 ];175 t.true(expectedOutputs.includes(stdout));

Fix using multiple `stdin` values (#661)ehmickybefore adoption4d8f9ca

lines 176–177why, one step back
176};
177

Add support for sync iterables with `execaSync()` (#944)ehmickybefore adoptionf744f7d

lines 178–185why, one step back
178test('stdin option can be multiple iterables', testMultipleIterable, [stringGenerator(), stringGenerator()], 0, execa);
179test('stdio[*] option can be multiple iterables', testMultipleIterable, [stringGenerator(), stringGenerator()], 3, execa);180test('stdin option can be multiple iterables - sync', testMultipleIterable, [stringGenerator(), stringGenerator()], 0, execaSync);181test('stdin option can be multiple mixed iterables', testMultipleIterable, [stringGenerator(), binaryGenerator()], 0, execa);182test('stdio[*] option can be multiple mixed iterables', testMultipleIterable, [stringGenerator(), binaryGenerator()], 3, execa);183test('stdin option can be multiple mixed iterables - sync', testMultipleIterable, [stringGenerator(), binaryGenerator()], 0, execaSync);184test('stdin option can be sync/async mixed iterables', testMultipleIterable, [stringGenerator(), asyncGenerator()], 0, execa);185test('stdio[*] option can be sync/async mixed iterables', testMultipleIterable, [stringGenerator(), asyncGenerator()], 3, execa);

Cancel generators when the process errors (#783)ehmickybefore adoption4b487ce

line 186why, one step back
186

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 187why, one step back
187test('stdin option iterable is canceled on subprocess error', async t => {

Refactor tests (#934)ehmickybefore adoption52c4bde

line 188why, one step back
188 const iterable = infiniteGenerator().transform();

Cancel generators when the process errors (#783)ehmickybefore adoption4b487ce

lines 189–192why, one step back
189 await t.throwsAsync(execa('stdin.js', {stdin: iterable, timeout: 1}), {message: /timed out/});
190 // eslint-disable-next-line no-unused-vars, no-empty191 for await (const _ of iterable) {}192});