Skip to main content

Class: TestWorkflowEnvironment

The in-process test engine.

Methods​

completeActivityAsync()​

completeActivityAsync(token, result?): Promise<void>

Complete an activity that called completeAsync() (completeActivityAsync).

Parameters​

token​

string

result?​

unknown

Returns​

Promise<void>


deliverSignal()​

deliverSignal(runId, name, payload, headers?): boolean

Parameters​

runId​

string

name​

string

payload​

unknown

headers?​

Headers

Returns​

boolean


failActivityAsync()​

failActivityAsync(token, error): Promise<void>

Fail an activity that called completeAsync() (failActivityAsync); the retry policy applies.

Parameters​

token​

string

error​

unknown

Returns​

Promise<void>


historyFileOf()​

historyFileOf(runId, extra?): HistoryFile

Parameters​

runId​

string

extra?​

Partial<Omit<HistoryFile, "format" | "formatVersion" | "workflowFn" | "events">>

Returns​

HistoryFile


historyOf()​

historyOf(runId): RunEventRecord[]

Parameters​

runId​

string

Returns​

RunEventRecord[]


holdActivities()​

holdActivities(nodeType?): void

Hold the activity queue of a node type (every node type when omitted): attempts wait instead of starting, and a scheduleToStartTimeout expires (ACTIVITY_TIMED_OUT { timeoutType: SCHEDULE_TO_START }, not retried).

Parameters​

nodeType?​

string

Returns​

void


mock()​

mock<In, Out>(operation, impl, operationName?): void

Mock a node operation (by node type, and operation when given).

Type Parameters​

In​

In

Out​

Out

Parameters​

operation​

string | Operation<In, Out>

impl​

(args, info) => Out | Promise<Out>

operationName?​

string

Returns​

void


mockActivity()​

mockActivity<In, Out>(activity, fn): void

Mock a user activity by name or declaration.

Type Parameters​

In​

In

Out​

Out

Parameters​

activity​

string | ActivityDefinition<In, Out>

fn​

(args, ctx) => Out | Promise<Out>

Returns​

void


mockChild()​

mockChild(workflowKey, impl): void

Mock a child workflow started by key (graph or durable).

Parameters​

workflowKey​

string

impl​

ChildMock

Returns​

void


now()​

now(): number

The fake clock, in epoch milliseconds.

Returns​

number


query()​

query(runId, query, args?): Promise<Json>

Answer a query from the run's history (a replay-only query task).

Parameters​

runId​

string

query​

string | QueryDefinition<unknown, unknown>

args?​

unknown

Returns​

Promise<Json>


registerActivity()​

registerActivity(implementation): void

Register a user-activity implementation. A later one replaces an earlier of the same name.

Parameters​

implementation​

ActivityImplementation<never, unknown>

Returns​

void


registered()​

registered(): Readonly<Record<string, DurableWorkflow<never, unknown>>>

Every tier-2 function registered, by export name.

Returns​

Readonly<Record<string, DurableWorkflow<never, unknown>>>


releaseActivities()​

releaseActivities(nodeType?): void

Release held activity queues (all when no node type is given).

Parameters​

nodeType?​

string

Returns​

void


requestCancel()​

requestCancel(runId, reason?): boolean

Parameters​

runId​

string

reason?​

string

Returns​

boolean


reset()​

reset(runId, options?): Promise<string>

Reset a run (11 §2.7): a new run whose history is the original's up to and including the chosen completed workflow task (with its commands), then WORKFLOW_RESET, then the signals (and, as UPDATE_ADMITTED, the accepted updates) received after that point. The original is terminated with reason RESET; children it started before the point follow the new run, the others get their parent-close policy. Returns the new run id.

Parameters​

runId​

string

options?​

ResetOptions

Returns​

Promise<string>


resultOf()​

resultOf(runId): Promise<Json>

Parameters​

runId​

string

Returns​

Promise<Json>


runIds()​

runIds(): string[]

Every run, in start order.

Returns​

string[]


runUntilIdle()​

runUntilIdle(skipTime): Promise<void>

Run every runnable task and activity; skip time when allowed and idle.

Parameters​

skipTime​

boolean

Returns​

Promise<void>


sinkCallsOf()​

sinkCallsOf(runId): SinkCall[]

Sink calls the run's tasks made.

Parameters​

runId​

string

Returns​

SinkCall[]


sleep()​

sleep(duration): Promise<void>

Advance the clock by duration, firing timers and running work as it comes due.

Parameters​

duration​

Duration

Returns​

Promise<void>


start()​

start<In, Out>(definition, options?): Promise<TestRunHandle<Out>>

Start a run of a tier-2 function (by declaration, or by export name with a task executor).

Type Parameters​

In​

In

Out​

Out

Parameters​

definition​

string | DurableWorkflow<In, Out>

options?​

StartOptions

Returns​

Promise<TestRunHandle<Out>>


startWithUpdate()​

startWithUpdate<In, Out>(definition, options): Promise<{ handle: TestRunHandle<Out>; update: UpdateResult; }>

Update-with-start (11 §2.6): start the run (or, with idConflictPolicy: USE_EXISTING, reach the open one) and deliver the update before any other task runs.

Type Parameters​

In​

In

Out​

Out

Parameters​

definition​

string | DurableWorkflow<In, Out>

options​

StartOptions & object

Returns​

Promise<{ handle: TestRunHandle<Out>; update: UpdateResult; }>


stateOf()​

stateOf(runId): RunState

Parameters​

runId​

string

Returns​

RunState


taskFailureOf()​

taskFailureOf(runId): WorkflowTaskResult

The failed workflow task that stopped a run, if one did.

Parameters​

runId​

string

Returns​

WorkflowTaskResult


terminate()​

terminate(runId, reason): void

Parameters​

runId​

string

reason​

string

Returns​

void


update()​

update<Args, Result>(runId, update, args?, options?): Promise<UpdateResult>

Send an update to a run and run until idle (05 §6). The result is REJECTED (the validator refused it or no handler took it; nothing is written to history), COMPLETED, or ACCEPTED while its handler still waits (for a timer without time skipping, or with waitFor: ACCEPTED).

Type Parameters​

Args​

Args

Result​

Result

Parameters​

runId​

string

update​

string | UpdateDefinition<Args, Result>

args?​

Args

options?​

UpdateOptions

Returns​

Promise<UpdateResult>


updateResultOf()​

updateResultOf(runId, updateId): UpdateResult

The current result of an update.

Parameters​

runId​

string

updateId​

string

Returns​

UpdateResult


create()​

static create(options?): Promise<TestWorkflowEnvironment>

Create an environment.

Parameters​

options?​

TestEnvironmentOptions

Returns​

Promise<TestWorkflowEnvironment>