Skip to content

Latest commit

 

History

History
250 lines (138 loc) · 5.44 KB

File metadata and controls

250 lines (138 loc) · 5.44 KB

Home > @aws/durable-execution-sdk-js-testing > LocalDurableTestRunner

LocalDurableTestRunner class

Local test runner for durable executions that runs handlers in-process with a local checkpoint server for development and testing scenarios.

This test runner executes durable functions locally without requiring AWS Lambda infrastructure, making it ideal for unit testing and local development workflows.

Signature:

export declare class LocalDurableTestRunner<TResult = any> implements DurableTestRunner<DurableOperation, TResult>

Implements: DurableTestRunner<DurableOperation, TResult>

Example

import { LocalDurableTestRunner } from "@aws/durable-execution-sdk-js-testing";
import { withDurableExecution } from "@aws/durable-execution-sdk-js";

const handler = withDurableExecution(async (input, context) => {
  const result = await context.step("process", () => processData(input));
  return result;
});

const runner = new LocalDurableTestRunner({ handlerFunction: handler });

const execution = await runner.run({ payload: { data: "test" } });
const result = execution.getResult();

Constructors

Constructor

Modifiers

Description

(constructor)({ handlerFunction })

Creates a new LocalDurableTestRunner instance and starts the checkpoint server.

Properties

Property

Modifiers

Type

Description

fakeClock

static

InstalledClock | undefined

skipTime

static

boolean

Methods

Method

Modifiers

Description

getOperation(name, index)

Gets the first operation with the specified name.

getOperationById(id)

Gets an operation by its unique identifier.

getOperationByIndex(index)

Gets an operation by its execution order index.

getOperationByNameAndIndex(name, index)

Gets an operation by name and index when multiple operations have the same name.

registerDurableFunction(functionName, durableHandler)

Registers a durable function handler that can be invoked during durable execution testing.

registerFunction(functionName, handler)

Registers a function handler that can be invoked during durable execution testing.

reset()

Resets the test runner state, clearing all cached operations and history.

This method should be called between test runs to ensure a clean state. It clears the operation index, wait manager, and operation storage, allowing the runner to be reused for multiple test executions.

run(params)

Executes the durable function and returns the result. The method will not resolve until the handler function completes successfully or throws an error.

setupTestEnvironment(params)

static

Sets up the test environment for local durable execution testing.

This method initializes the checkpoint server, configures fake timers for time manipulation, and prepares the environment for running durable function tests. This should be called once before running any tests, typically in a test setup hook like beforeAll.

teardownTestEnvironment()

static

Cleans up and tears down the test environment after durable execution testing.

This method stops the checkpoint server, uninstalls fake timers, and performs cleanup of resources that were initialized during test environment setup. This should be called once after all tests have completed, typically in a test cleanup hook like afterAll.