UNPKG

actionhero

Version:

The reusable, scalable, and quick node.js API server for stateless and stateful applications

60 lines (59 loc) 2.66 kB
import { Task, Action, Connection } from "./../index"; import { WebServer } from "../servers/web"; import { AsyncReturnType } from "type-fest"; import { TaskInputs } from "../classes/task"; export type SpecHelperConnection = Connection & { actionCallbacks?: { [key: string]: Function; }; }; export declare namespace specHelper { /** * Generate a connection to use in your tests */ function buildConnection(): Promise<SpecHelperConnection>; /** * Run an action via the specHelper server. */ function runAction<A extends Action | void = void>(actionName: string, input?: Partial<SpecHelperConnection> | Record<string, any>): Promise<(A extends Action ? AsyncReturnType<A["run"]> : { [key: string]: any; }) & { messageId?: string; error?: NodeJS.ErrnoException | string | any; requesterInformation?: ReturnType<WebServer["buildRequesterInformation"]>; serverInformation?: ReturnType<WebServer["buildServerInformation"]>; }>; /** * Mock a specHelper connection requesting a file from the server. */ function getStaticFile(file: string): Promise<any>; /** * Use the specHelper to run a task. * Note: this only runs the task's `run()` method, and no middleware. This is faster than api.specHelper.runFullTask. */ function runTask<T extends Task | void = void>(taskName: string, params: object | Array<any>): Promise<(T extends Task ? AsyncReturnType<T["run"]> : { [key: string]: any; }) & { error?: NodeJS.ErrnoException | string; }>; /** * Use the specHelper to run a task. * Note: this will run a full Task worker, and will also include any middleware. This is slower than api.specHelper.runTask. */ function runFullTask<T extends Task | void = void>(taskName: string, params: object | Array<any>): Promise<(T extends Task ? AsyncReturnType<T["run"]> : { [key: string]: any; }) & { error?: string; }>; /** * Use the specHelper to find enqueued instances of a task * This will return an array of instances of the task which have been enqueued either in the normal queues or delayed queues * If a task is enqueued in a delayed queue, it will have a 'timestamp' property * i.e. [ { class: 'regularTask', queue: 'testQueue', args: [ [Object] ] } ] */ function findEnqueuedTasks(taskName: string): Promise<TaskInputs[]>; /** * Delete all enqueued instances of a task, both in all the normal queues and all of the delayed queues */ function deleteEnqueuedTasks(taskName: string, params: {}): Promise<void>; }