iterable.js
This file
Path
test/stdio/iterable.js
139 lines · 6.0 KiB · JavaScript
Last changed by
Prefer `setImmediate()` over `setTimeout()` (#733)ehmickybefore adoption66d12bf
History of this fileTake it
Improve error handling (#647)ehmickybefore adoption5b6d859
line 1why, one step back1import {once} from 'node:events';Prefer `setImmediate()` over `setTimeout()` (#733)ehmickybefore adoption66d12bf
line 2why, one step back2import {setTimeout, setImmediate} from 'node:timers/promises';Refactor tests (#628)ehmickybefore adoption30ecc81
lines 3–5why, one step back3import 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 back6import {getStdio} from '../helpers/stdio.js';Allow any type with transforms (#709)ehmickybefore adoptioned8b2ce
lines 7–8why, one step back7import {foobarObject, foobarObjectString} from '../helpers/input.js';8import {serializeGenerator} from '../helpers/generator.js';Refactor tests (#628)ehmickybefore adoption30ecc81
line 9why, one step back9Allow any type with transforms (#709)ehmickybefore adoptioned8b2ce
lines 10–25why, one step back10const stringArray = ['foo', 'bar'];1112const stringGenerator = function * () {13 yield * stringArray;14};1516const textEncoder = new TextEncoder();17const binaryFoo = textEncoder.encode('foo');18const binaryBar = textEncoder.encode('bar');19const binaryArray = [binaryFoo, binaryBar];2021const binaryGenerator = function * () {22 yield * binaryArray;23};2425const asyncGenerator = async function * () {Prefer `setImmediate()` over `setTimeout()` (#733)ehmickybefore adoption66d12bf
line 26why, one step back26 await setImmediate();Allow any type with transforms (#709)ehmickybefore adoptioned8b2ce
lines 27–29why, one step back27 yield * stringArray;28};29Refactor tests (#628)ehmickybefore adoption30ecc81
lines 30–31why, one step back30setFixtureDir();31Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
lines 32–33why, one step back32const testIterable = async (t, stdioOption, index) => {33 const {stdout} = await execa('stdin-fd.js', [`${index}`], getStdio(index, stdioOption));Refactor tests (#628)ehmickybefore adoption30ecc81
lines 34–36why, one step back34 t.is(stdout, 'foobar');35};36Allow any type with transforms (#709)ehmickybefore adoptioned8b2ce
lines 37–40why, one step back37test('stdin option can be an array of strings', testIterable, [stringArray], 0);38test('stdio[*] option can be an array of strings', testIterable, [stringArray], 3);39test('stdin option can be an array of Uint8Arrays', testIterable, [binaryArray], 0);40test('stdio[*] option can be an array of Uint8Arrays', testIterable, [binaryArray], 3);Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
lines 41–46why, one step back41test('stdin option can be an iterable of strings', testIterable, stringGenerator(), 0);42test('stdio[*] option can be an iterable of strings', testIterable, stringGenerator(), 3);43test('stdin option can be an iterable of Uint8Arrays', testIterable, binaryGenerator(), 0);44test('stdio[*] option can be an iterable of Uint8Arrays', testIterable, binaryGenerator(), 3);45test('stdin option can be an async iterable', testIterable, asyncGenerator(), 0);46test('stdio[*] option can be an async iterable', testIterable, asyncGenerator(), 3);Refactor tests (#628)ehmickybefore adoption30ecc81
line 47why, one step back47Allow any type with transforms (#709)ehmickybefore adoptioned8b2ce
lines 48–67why, one step back48const foobarObjectGenerator = function * () {49 yield foobarObject;50};5152const foobarAsyncObjectGenerator = function * () {53 yield foobarObject;54};5556const testObjectIterable = async (t, stdioOption, index) => {57 const {stdout} = await execa('stdin-fd.js', [`${index}`], getStdio(index, [stdioOption, serializeGenerator]));58 t.is(stdout, foobarObjectString);59};6061test('stdin option can be an array of objects', testObjectIterable, [foobarObject], 0);62test('stdio[*] option can be an array of objects', testObjectIterable, [foobarObject], 3);63test('stdin option can be an iterable of objects', testObjectIterable, foobarObjectGenerator(), 0);64test('stdio[*] option can be an iterable of objects', testObjectIterable, foobarObjectGenerator(), 3);65test('stdin option can be an async iterable of objects', testObjectIterable, foobarAsyncObjectGenerator(), 0);66test('stdio[*] option can be an async iterable of objects', testObjectIterable, foobarAsyncObjectGenerator(), 3);67Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
line 68why, one step back68const testIterableSync = (t, stdioOption, index) => {Refactor tests (#628)ehmickybefore adoption30ecc81
line 69why, one step back69 t.throws(() => {Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
line 70why, one step back70 execaSync('empty.js', getStdio(index, stdioOption));Refactor tests (#628)ehmickybefore adoption30ecc81
lines 71–73why, one step back71 }, {message: /an iterable in sync mode/});72};73Allow any type with transforms (#709)ehmickybefore adoptioned8b2ce
lines 74–75why, one step back74test('stdin option cannot be an array of strings - sync', testIterableSync, [stringArray], 0);75test('stdio[*] option cannot be an array of strings - sync', testIterableSync, [stringArray], 3);Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
lines 76–79why, one step back76test('stdin option cannot be a sync iterable - sync', testIterableSync, stringGenerator(), 0);77test('stdio[*] option cannot be a sync iterable - sync', testIterableSync, stringGenerator(), 3);78test('stdin option cannot be an async iterable - sync', testIterableSync, asyncGenerator(), 0);79test('stdio[*] option cannot be an async iterable - sync', testIterableSync, asyncGenerator(), 3);Refactor tests (#628)ehmickybefore adoption30ecc81
line 80why, one step back80Allow any type with transforms (#709)ehmickybefore adoptioned8b2ce
lines 81–85why, one step back81// eslint-disable-next-line require-yield82const throwingGenerator = function * () {83 throw new Error('generator error');84};85Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
lines 86–87why, one step back86const testIterableError = async (t, index) => {87 const {originalMessage} = await t.throwsAsync(execa('stdin-fd.js', [`${index}`], getStdio(index, throwingGenerator())));Refactor tests (#628)ehmickybefore adoption30ecc81
lines 88–90why, one step back88 t.is(originalMessage, 'generator error');89};90Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
lines 91–92why, one step back91test('stdin option handles errors in iterables', testIterableError, 0);92test('stdio[*] option handles errors in iterables', testIterableError, 3);Refactor tests (#628)ehmickybefore adoption30ecc81
line 93why, one step back93Allow any type with transforms (#709)ehmickybefore adoptioned8b2ce
line 94why, one step back94const testNoIterableOutput = (t, stdioOption, index, execaMethod) => {Refactor tests (#628)ehmickybefore adoption30ecc81
line 95why, one step back95 t.throws(() => {Allow any type with transforms (#709)ehmickybefore adoptioned8b2ce
line 96why, one step back96 execaMethod('empty.js', getStdio(index, stdioOption));Refactor tests (#628)ehmickybefore adoption30ecc81
lines 97–99why, one step back97 }, {message: /cannot be an iterable/});98};99Allow any type with transforms (#709)ehmickybefore adoptioned8b2ce
lines 100–118why, one step back100test('stdout option cannot be an array of strings', testNoIterableOutput, [stringArray], 1, execa);101test('stderr option cannot be an array of strings', testNoIterableOutput, [stringArray], 2, execa);102test('stdout option cannot be an array of strings - sync', testNoIterableOutput, [stringArray], 1, execaSync);103test('stderr option cannot be an array of strings - sync', testNoIterableOutput, [stringArray], 2, execaSync);104test('stdout option cannot be an iterable', testNoIterableOutput, stringGenerator(), 1, execa);105test('stderr option cannot be an iterable', testNoIterableOutput, stringGenerator(), 2, execa);106test('stdout option cannot be an iterable - sync', testNoIterableOutput, stringGenerator(), 1, execaSync);107test('stderr option cannot be an iterable - sync', testNoIterableOutput, stringGenerator(), 2, execaSync);108109const infiniteGenerator = () => {110 const controller = new AbortController();111112 const generator = async function * () {113 yield 'foo';114 await setTimeout(1e7, undefined, {signal: controller.signal});115 };116117 return {iterable: generator(), abort: controller.abort.bind(controller)};118};Improve error handling (#647)ehmickybefore adoption5b6d859
lines 119–122why, one step back119120test('stdin option can be an infinite iterable', async t => {121 const {iterable, abort} = infiniteGenerator();122 try {Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
line 123why, one step back123 const childProcess = execa('stdin.js', getStdio(0, iterable));Improve error handling (#647)ehmickybefore adoption5b6d859
lines 124–131why, one step back124 const stdout = await once(childProcess.stdout, 'data');125 t.is(stdout.toString(), 'foo');126 childProcess.kill('SIGKILL');127 await t.throwsAsync(childProcess, {message: /SIGKILL/});128 } finally {129 abort();130 }131});Fix using multiple `stdin` values (#661)ehmickybefore adoption4d8f9ca
line 132why, one step back132Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
lines 133–134why, one step back133const testMultipleIterable = async (t, index) => {134 const {stdout} = await execa('stdin-fd.js', [`${index}`], getStdio(index, [stringGenerator(), asyncGenerator()]));Fix using multiple `stdin` values (#661)ehmickybefore adoption4d8f9ca
lines 135–137why, one step back135 t.is(stdout, 'foobarfoobar');136};137Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
lines 138–139why, one step back138test('stdin option can be multiple iterables', testMultipleIterable, 0);139test('stdio[*] option can be multiple iterables', testMultipleIterable, 3);