UNPKG

@inngest/test

Version:
71 lines (70 loc) 2.54 kB
import { OutgoingOp } from "inngest"; import type { ExecutionResult } from "inngest/components/execution/InngestExecution"; import type { InngestTestEngine } from "./InngestTestEngine.js"; import { type DeepPartial } from "./util"; /** * A test run that allows you to wait for specific checkpoints in a run that * covers many executions. * * @TODO We may need to separate run execution by {@link ExecutionVersion}. */ export declare namespace InngestTestRun { /** * Options for creating a new {@link InngestTestRun} instance. */ interface Options { /** * The test engine to use for running the function. */ testEngine: InngestTestEngine; } /** * The possible checkpoints that can be reached during a test run. */ type CheckpointKey = ExecutionResult["type"]; /** * A checkpoint that can be reached during a test run. */ type Checkpoint<T extends CheckpointKey> = Omit<Extract<ExecutionResult, { type: T; }>, "ctx" | "ops">; interface RunOutput extends Pick<InngestTestEngine.ExecutionOutput, "ctx" | "state"> { result?: Checkpoint<"function-resolved">["data"]; error?: Checkpoint<"function-rejected">["error"]; } interface RunStepOutput extends RunOutput { step: OutgoingOp; } } /** * A test run that allows you to wait for specific checkpoints in a run that * covers many executions. * * @TODO We may need to separate run execution by {@link ExecutionVersion}. */ export declare class InngestTestRun { options: InngestTestRun.Options; constructor(options: InngestTestRun.Options); /** * Keep executing the function until a specific checkpoint is reached. * * @TODO What if the thing we're waiting for has already happened? */ waitFor<T extends InngestTestRun.CheckpointKey>( /** * The checkpoint to wait for. */ checkpoint: T, /** * An optional subset of the checkpoint to match against. Any checkpoint of * this type will be matched. * * When providing a `subset`, use `expect` tooling such as * `expect.stringContaining` to match partial values. */ subset?: DeepPartial<InngestTestRun.Checkpoint<T>>): Promise<InngestTestEngine.ExecutionOutput<T>>; /** * Given existing state and an execution result, mutate the state. */ protected static updateState(options: InngestTestEngine.InlineOptions, checkpoint: InngestTestRun.Checkpoint<InngestTestRun.CheckpointKey>): void; }