Skip to content
Myr

Fix randomly failing tests (#793)

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

authored by ehmicky · committed by GitHub · parent 4080212 · Browse files · 3 files+23 added−21 removed
This commit

State

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

Diff stats

3 files+23 added−21 removed

  • tests:+23 added−21 removed

3 files+23 added−21 removed

modified:test/stdio/async.js+10 added-9 removed
modified:test/stdio/iterable.js+8 added-6 removed
40 unmodified lines
41test('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);45test.serial('stdin option can be an async iterable', testIterable, asyncGenerator(), 0);46test.serial('stdio[*] option can be an async iterable', testIterable, asyncGenerator(), 3);4748const foobarObjectGenerator = function * () {49 yield foobarObject;50};
55 unmodified lines
106test('stdout option cannot be an iterable - sync', testNoIterableOutput, stringGenerator(), 1, execaSync);107test('stderr option cannot be an iterable - sync', testNoIterableOutput, stringGenerator(), 2, execaSync);108109test('stdin option can be an infinite iterable', async t => {110 const childProcess = execa('stdin.js', getStdio(0, infiniteGenerator()));111 const stdout = await once(childProcess.stdout, 'data');112 t.true(stdout.toString().startsWith('foo'));110 const iterable = infiniteGenerator();111 const childProcess = execa('stdin.js', getStdio(0, iterable));112 await once(childProcess.stdout, 'data');113 childProcess.kill();114 await t.throwsAsync(childProcess, {code: 'ERR_STREAM_PREMATURE_CLOSE'});114 const {stdout} = await t.throwsAsync(childProcess);115 t.true(stdout.startsWith('foo'));116 t.deepEqual(await iterable.next(), {value: undefined, done: true});117});118119const testMultipleIterable = async (t, index) => {120 const {stdout} = await execa('stdin-fd.js', [`${index}`], getStdio(index, [stringGenerator(), asyncGenerator()]));
12 unmodified lines
modified:test/stream.js+5 added-6 removed
1import {Buffer} from 'node:buffer';2import {once} from 'node:events';3import {getDefaultHighWaterMark} from 'node:stream';4import {setTimeout, setImmediate} from 'node:timers/promises';4import {setTimeout} from 'node:timers/promises';5import test from 'ava';6import getStream from 'get-stream';7import {execa, execaSync} from '../index.js';8import {setFixtureDir} from './helpers/fixtures-dir.js';
77 unmodified lines
8687const testLateStream = async (t, index, all) => {88 const subprocess = execa('noop-fd-ipc.js', [`${index}`, foobarString], {...getStdio(4, 'ipc', 4), buffer: false, all});89 await once(subprocess, 'message');90 await setImmediate();90 const [output, allOutput] = await Promise.all([91 getStream(subprocess.stdio[index]),92 all ? getStream(subprocess.all) : undefined,93 subprocess,
5 unmodified lines
99 t.is(allOutput, '');100 }101};102104test('Lacks some data when stdout is read too late `buffer` set to `false`', testLateStream, 1, false);105test('Lacks some data when stderr is read too late `buffer` set to `false`', testLateStream, 2, false);106test('Lacks some data when stdio[*] is read too late `buffer` set to `false`', testLateStream, 3, false);107test('Lacks some data when all is read too late `buffer` set to `false`', testLateStream, 1, true);103test.serial('Lacks some data when stdout is read too late `buffer` set to `false`', testLateStream, 1, false);104test.serial('Lacks some data when stderr is read too late `buffer` set to `false`', testLateStream, 2, false);105test.serial('Lacks some data when stdio[*] is read too late `buffer` set to `false`', testLateStream, 3, false);106test.serial('Lacks some data when all is read too late `buffer` set to `false`', testLateStream, 1, true);107108// eslint-disable-next-line max-params109const testIterationBuffer = async (t, index, buffer, useDataEvents, all) => {110 const subprocess = execa('noop-fd.js', [`${index}`, foobarString], {...fullStdio, buffer, all});
319 unmodified lines