diff --git a/src/core.ts b/src/core.ts index 96f2062437..404acf3a04 100644 --- a/src/core.ts +++ b/src/core.ts @@ -59,6 +59,8 @@ export interface Options { ac?: AbortController signal?: AbortSignal input?: string | Buffer | Readable | ProcessOutput | ProcessPromise + timeout?: Duration + timeoutSignal?: string stdio: StdioOptions verbose: boolean sync: boolean @@ -246,6 +248,7 @@ export class ProcessPromise extends Promise { const input = ($.input as ProcessPromise | ProcessOutput)?.stdout ?? $.input if (input) this.stdio('pipe') + if ($.timeout) this.timeout($.timeout, $.timeoutSignal) $.log({ kind: 'cmd', diff --git a/test/core.test.js b/test/core.test.js index 75d586e486..e28fa6c42a 100644 --- a/test/core.test.js +++ b/test/core.test.js @@ -480,6 +480,21 @@ describe('core', () => { assert.equal(signal, 'SIGKILL') }) + test('timeout is configurable via opts', async () => { + let exitCode, signal + try { + await $({ + timeout: 10, + timeoutSignal: 'SIGKILL', + })`sleep 999` + } catch (p) { + exitCode = p.exitCode + signal = p.signal + } + assert.equal(exitCode, null) + assert.equal(signal, 'SIGKILL') + }) + test('timeout() expiration works', async () => { let exitCode, signal try {