Skip to content
Myr

Fix `timeout` option (#727)

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

authored by ehmicky · committed by GitHub · parent 1c48d37 · Browse files · 5 files+11 added−7 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+11 added−7 removed

  • tests:+4 added−4 removed
  • other:+7 added−3 removed

5 files+11 added−7 removed

modified:lib/error.js+1 added-1 removed
modified:lib/stream.js+1 added-1 removed
129 unmodified lines
130131// Retrieve result of child process: exit code, signal, error, streams (stdout/stderr/all)132export const getSpawnedResult = async ({133 spawned,134 options: {encoding, buffer, maxBuffer, timeout, killSignal, cleanup, detached},134 options: {encoding, buffer, maxBuffer, timeoutDuration: timeout, killSignal, cleanup, detached},135 context,136 stdioStreamsGroups,137 controller,138}) => {
41 unmodified lines
modified:test/fixtures/no-killable.js+1 added-3 removed
modified:test/kill.js+3 added-1 removed
83 unmodified lines
84 t.is(signal, 'SIGKILL');85 t.true(isCanceled);86 });8788 // For this test to work, the process needs to spawn and setup its `SIGTERM` handler before `timeout` terminates it.89 // This creates a race condition that we can only work around by using `test.serial()` and a higher timeout.90 test.serial('`forceKillAfterDelay` works with the "timeout" option', async t => {89 const {subprocess} = await spawnNoKillable(1, {timeout: 2e3});91 const {subprocess} = await spawnNoKillable(1, {timeout: 5e3});92 const {isTerminated, signal, timedOut} = await t.throwsAsync(subprocess);93 t.true(isTerminated);94 t.is(signal, 'SIGKILL');95 t.true(timedOut);
222 unmodified lines
modified:index.js+5 added-1 removed
101 unmodified lines
102 killSignal,103 forceKillAfterDelay,104});105106// Prevent passing the `timeout` option directly to `child_process.spawn()`107const handleAsyncOptions = ({timeout, ...options}) => ({...options, timeoutDuration: timeout});108109const handleOutput = (options, value) => {110 if (value === undefined || value === null) {111 return;112 }
9 unmodified lines
122 return options.stripFinalNewline ? stripFinalNewline(value) : value;123};124125export function execa(rawFile, rawArgs, rawOptions) {123 const {file, args, command, escapedCommand, options} = handleArguments(rawFile, rawArgs, rawOptions);126 const {file, args, command, escapedCommand, options: normalizedOptions} = handleArguments(rawFile, rawArgs, rawOptions);127 const options = handleAsyncOptions(normalizedOptions);128129 const stdioStreamsGroups = handleInputAsync(options);130131 let spawned;
217 unmodified lines