@temporal-contract/testing / contract
contract
Type Aliases
ContractTestContext
type ContractTestContext<TContract> = object;Defined in: contract.ts:86
Fixture context exposed by the it returned from createContractTest.
Type Parameters
| Type Parameter |
|---|
TContract extends ContractDefinition |
Properties
| Property | Type | Description | Defined in |
|---|---|---|---|
client | ContractClient<TContract> | Contract-bound client — typedClient.for(contract). | contract.ts:93 |
namespace | string | The Temporal namespace the worker and clients use — unique to the createContractTest call (so, in practice, to the test file). | contract.ts:91 |
typedClient | TypedClient | Connection-scoped root, for binding further contracts or reaching the raw escape hatch. | contract.ts:98 |
worker | TypedWorker | The running worker for the contract's task queue — created and started before the test (auto), shut down after it. The underlying Temporal Worker stays reachable via worker.raw. | contract.ts:104 |
CreateContractTestOptions
type CreateContractTestOptions<TContract> = object;Defined in: contract.ts:56
Options for createContractTest.
Type Parameters
| Type Parameter |
|---|
TContract extends ContractDefinition |
Properties
| Property | Type | Description | Defined in |
|---|---|---|---|
activities? | ActivitiesHandler<TContract> | Activities handler built with declareActivitiesHandler. Omit it for a workflow-only worker. | contract.ts:69 |
contract | TContract | The contract under test — its task queue names the worker's queue. | contract.ts:58 |
workerOptions? | Omit<CreateWorkerOptions<TContract>, | "activities" | "connection" | "contract" | "workflowBundle" | "workflowsPath"> | Extra options forwarded to TypedWorker.create (e.g. interceptors, tuning knobs). A namespace given here replaces the per-file namespace createContractTest registers — it must already exist on the server — and is also used by the client fixtures. | contract.ts:76 |
workflowsPath | string | Path to the workflows file registered on the worker — typically built with workflowsPathFromURL(import.meta.url, "./x.workflows.js") from @temporal-contract/worker/worker. Bundled once per test file. | contract.ts:64 |
Functions
createContractTest()
function createContractTest<TContract>(options): TestAPI<{
client: ContractClient<TContract>;
clientConnection: Connection;
namespace: string;
typedClient: TypedClient;
worker: TypedWorker;
workerConnection: NativeConnection;
}>;Defined in: contract.ts:123
Build a Vitest it whose fixtures run the given contract against the testcontainers-provided Temporal server: a worker on the contract's task queue (started before each test, shut down after), the connection-scoped TypedClient root, and the contract-bound ContractClient.
Every call registers its own Temporal namespace, used by both the worker and the clients. Test files run in parallel against one server, and a worker polls the contract's real task queue — sharing a namespace, one file's worker would pick up another file's tasks.
Requires the @temporal-contract/testing/global-setup global setup (or a module default-exporting createGlobalSetup(...)) to be registered on the test project. The underlying clientConnection/workerConnection fixtures from ./extension remain available on the context.
Type Parameters
| Type Parameter |
|---|
TContract extends ContractDefinition |
Parameters
| Parameter | Type |
|---|---|
options | CreateContractTestOptions<TContract> |
Returns
TestAPI<{ client: ContractClient<TContract>; clientConnection: Connection; namespace: string; typedClient: TypedClient; worker: TypedWorker; workerConnection: NativeConnection; }>