Skip to content
Myr

Avoid code duplication with logic related to `maxListeners` (#831)

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

authored by ehmicky · committed by GitHub · parent 100f04f · Browse files · 5 files+37 added−32 removed
This commit

State

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

Diff stats

5 files+37 added−32 removed

  • tests:+20 added−17 removed
  • other:+17 added−15 removed

5 files+37 added−32 removed

modified:lib/stdio/async.js+4 added-15 removed
modified:lib/stdio/utils.js+13 added
added:test/helpers/listeners.js+14 added
modified:test/stdio/async.js+3 added-9 removed
4 unmodified lines
5import {execa} from '../../index.js';6import {STANDARD_STREAMS} from '../helpers/stdio.js';7import {foobarString} from '../helpers/input.js';8import {setFixtureDir} from '../helpers/fixtures-dir.js';9import {assertMaxListeners} from '../helpers/listeners.js';1011setFixtureDir();1213const getStandardStreamListeners = stream => Object.fromEntries(stream.eventNames().map(eventName => [eventName, stream.listeners(eventName)]));
35 unmodified lines
49 t.true(results.every(({stdout}) => stdout === foobarString));50});5152const testMaxListeners = async (t, isMultiple, maxListenersCount) => {52 let warning;53 const captureWarning = warningArgument => {54 warning = warningArgument;55 };53 const checkMaxListeners = assertMaxListeners(t);5457 process.on('warning', captureWarning);5855 for (const standardStream of STANDARD_STREAMS) {56 standardStream.setMaxListeners(maxListenersCount);57 }58
1 unmodified line
60 const results = await Promise.all(61 Array.from({length: processesCount}, () => execa('empty.js', getComplexStdio(isMultiple))),62 );63 t.true(results.every(({exitCode}) => exitCode === 0));68 t.is(warning, undefined);64 } finally {65 await setImmediate();66 await setImmediate();67 checkMaxListeners();6869 for (const standardStream of STANDARD_STREAMS) {70 t.is(standardStream.getMaxListeners(), maxListenersCount);71 standardStream.setMaxListeners(defaultMaxListeners);72 }7778 process.off('warning', captureWarning);73 }74};7576test.serial('No warning with maxListeners 1 and ["pipe", "inherit"]', testMaxListeners, false, 1);
9 unmodified lines
modified:test/kill.js+3 added-8 removed
5 unmodified lines
6import {pEvent} from 'p-event';7import isRunning from 'is-running';8import {execa, execaSync} from '../index.js';9import {setFixtureDir, FIXTURES_DIR} from './helpers/fixtures-dir.js';10import {assertMaxListeners} from './helpers/listeners.js';1112setFixtureDir();1314const isWindows = process.platform === 'win32';
107 unmodified lines
122 t.is(signal, 'SIGKILL');123 });124125 test.serial('Can call `.kill()` with `forceKillAfterDelay` many times without triggering the maxListeners warning', async t => {125 let warning;126 const captureWarning = warningArgument => {127 warning = warningArgument;128 };126 const checkMaxListeners = assertMaxListeners(t);127130 process.once('warning', captureWarning);131128 const subprocess = spawnNoKillableSimple();129 for (let index = 0; index < defaultMaxListeners + 1; index += 1) {130 subprocess.kill();131 }
1 unmodified line
133 const {isTerminated, signal} = await t.throwsAsync(subprocess);134 t.true(isTerminated);135 t.is(signal, 'SIGKILL');136141 t.is(warning, undefined);142 process.off('warning', captureWarning);137 checkMaxListeners();138 });139140 test('Can call `.kill()` with `forceKillAfterDelay` multiple times', async t => {141 const subprocess = spawnNoKillableSimple();
360 unmodified lines