Skip to main content

Class: TestWorkflowEnvironment

testing.TestWorkflowEnvironment

An execution environment for running Workflow integration tests.

Runs an external server. By default, the Java test server is used which supports time skipping.

Properties

asyncCompletionClient

Readonly asyncCompletionClient: AsyncCompletionClient

An AsyncCompletionClient for interacting with the test server


connection

Readonly connection: Connection

Get an extablished Connection to the test server


nativeConnection

Readonly nativeConnection: NativeConnection

A NativeConnection for interacting with the test server.

Use this connection when creating Workers for testing.


sleep

sleep: (durationMs: string | number) => Promise<void>

Type declaration

▸ (durationMs): Promise<void>

Wait for durationMs in "test server time".

The test server toggles between skipped time and normal time depending on what it needs to execute.

This method is likely to resolve in less than durationMs of "real time".

Useful for simulating events far into the future like completion of long running activities.

Example

workflow.ts

const activities = proxyActivities({ startToCloseTimeout: 2_000_000 });

export async function raceActivityAndTimer(): Promise<string> {
return await Promise.race([
wf.sleep(500_000).then(() => 'timer'),
activities.longRunning().then(() => 'activity'),
]);
}

test.ts

const worker = await Worker.create({
connection: testEnv.nativeConnection,
activities: {
async longRunning() {
await testEnv.sleep(1_000_000); // <-- sleep called here
},
},
// ...
});
Parameters
NameTypeDescription
durationMsstring | numberms formatted string or number of milliseconds
Returns

Promise<void>


workflowClient

Readonly workflowClient: WorkflowClient

A WorkflowClient for interacting with the test server

Methods

teardown

teardown(): Promise<void>

Kill the test server process and close the connection to it

Returns

Promise<void>


create

Static create(opts?): Promise<TestWorkflowEnvironment>

Create a new test environment

Parameters

NameType
opts?TestWorkflowEnvironmentOptions

Returns

Promise<TestWorkflowEnvironment>