Skip to content

Commit

Permalink
feat: let timeout be configurable via $ opts (#796)
Browse files Browse the repository at this point in the history
  • Loading branch information
antongolub authored May 8, 2024
1 parent b6420eb commit a3205e1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -246,6 +248,7 @@ export class ProcessPromise extends Promise<ProcessOutput> {
const input = ($.input as ProcessPromise | ProcessOutput)?.stdout ?? $.input

if (input) this.stdio('pipe')
if ($.timeout) this.timeout($.timeout, $.timeoutSignal)

$.log({
kind: 'cmd',
Expand Down
15 changes: 15 additions & 0 deletions test/core.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit a3205e1

Please sign in to comment.