Skip to content

Commit

Permalink
types: add some missing methods (#36)
Browse files Browse the repository at this point in the history
Adds type declarations for stderrEmit, stdoutEmit, spawnError,
exitOnSignal, and delay
  • Loading branch information
isaacs authored May 6, 2024
1 parent 6eb58eb commit 3db29e8
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions types/spawk.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,42 @@ declare class Interceptor {
*/
exit(code?: number | (() => number | Promise<number>)): Interceptor

/**
* Tells the interceptor to delay exiting for a given number of
* milliseconds.
*/
delay(ms: number): Interceptor

/**
* Tells the interceptor to delay exiting until it receives the given
* signal. Setting this will ignore any delay you have set. This will
* also be the signal that the interceptor exits with, unless you otherwise
* change it via `interceptor.signal`.
*/
exitOnSignal(signal: NodeJS.Signals): Interceptor

/**
* Tells the interceptor to emit the given error object via the `error`
* event, instead of the normal `spawn` event. The interceptor will not
* emit the `exit` or `close` events in this case, nor will it set up any
* stdio objects. This can be combined with `interceptor.delay` to delay
* this error, or with `interceptor.exitOnSignal` to error when the given
* signal is received (replicating a process that can not be killed).
*/
spawnError(error: Error): Interceptor

/**
* Tells the interceptor to emit a given event from stdout with any number
* of arguments.
*/
stdoutEmit(eventName: string, ...args: any[]): Interceptor

/**
* Tells the interceptor to emit a given event from stderr with any number
* of arguments.
*/
stderrEmit(eventName: string, ...args: any[]): Interceptor

/**
* Tells the interceptor what signal to exit with. Defaults to null (exit with no signal). This can be either a string
* or a function that returns a string. The function can also be async or return a Promise. The function will be
Expand Down

0 comments on commit 3db29e8

Please sign in to comment.