Skip to content

@btravstack/temporal-testing


@btravstack/temporal-testing ​

Type Aliases ​

TemporalEnvironment ​

ts
type TemporalEnvironment = object;

Defined in: index.ts:39

The environment a spec spreads into start's env: the server, and a namespace of the spec file's own.

Properties ​

PropertyModifierTypeDefined in
TEMPORAL_ADDRESSreadonlystringindex.ts:40
TEMPORAL_NAMESPACEreadonlystringindex.ts:41

TemporalServerOptions ​

ts
type TemporalServerOptions = object;

Defined in: index.ts:18

Options for temporalServer.

Properties ​

PropertyModifierTypeDefault valueDescriptionDefined in
reuse?readonlybooleantruetrue attaches to the server an earlier or a concurrent run on the same Docker host started, and leaves it running for the next one. false starts a server for this run alone and stops it when the run ends.index.ts:35
startupTimeoutMs?readonlynumber60_000How long the container may take to report healthy, in milliseconds: the Docker health check's start period and retry count, testcontainers' own wait, and how long a run refused the shared name waits for the winner's container, all take it.index.ts:27

Variables ​

default ​

ts
default: (__namedParameters) => Promise<(() => Promise<void>) | undefined>;

Defined in: index.ts:101

Parameters ​

ParameterType
__namedParametersTestProject

Returns ​

Promise<(() => Promise<void>) | undefined>

Functions ​

temporalEnvironment() ​

ts
function temporalEnvironment(prefix?): [(context, use) => Promise<void>, {
  scope: "file";
}];

Defined in: index.ts:223

A file-scoped Vitest fixture answering the TemporalEnvironment of a namespace registered for the spec file, on the server temporalServer provided. The namespace is the isolation boundary: the starter reads its task queue off the contract, so two spec files polling the same queue are kept apart by namespace, and so are suites listing workflows on a shared server. Nothing is cleaned up.

Parameters ​

ParameterTypeDefault value
prefix?string"spec"

Returns ​

[(context, use) => Promise<void>, { scope: "file"; }]

Example ​

ts
export const it = test.extend<{ temporal: TemporalEnvironment; boot: Boot }>({
  temporal: temporalEnvironment("orders"),
  boot: bootFixture(),
});

it("fulfils", async ({ temporal, boot }) => {
  const app = boot(OrderWorker, { env: { ...temporal } });
});

temporalNamespace() ​

ts
function temporalNamespace(address, prefix?): Promise<string>;

Defined in: index.ts:174

Registers the namespace <prefix>-<uuid> on the Temporal server at address, and answers its name once every Temporal service can use it. It needs no test context, so a Vitest globalSetup can register one namespace for the whole run, for workers it starts once and shares across spec files.

Registering a namespace is not the same as being able to use one: each Temporal service refreshes its namespace registry on its own interval, so a namespace-scoped read is retried for up to a minute, each read under that deadline. A namespace that never becomes usable, or a server that stops answering, rejects with an error naming the namespace, the server's last answer as its cause.

Parameters ​

ParameterTypeDefault value
addressstringundefined
prefix?string"spec"

Returns ​

Promise<string>

Example ​

ts
// workers-setup.ts, named in `globalSetup` after the server's setup
export default async (project: TestProject) => {
  const address = project.getProvidedContext().__BTRAVSTACK_TEMPORAL_ADDRESS__;
  const namespace = await temporalNamespace(address, "workers");
};

temporalServer() ​

ts
function temporalServer(__namedParameters?): (__namedParameters) => Promise<(() => Promise<void>) | undefined>;

Defined in: index.ts:71

A Vitest globalSetup providing a Temporal server's address: the Temporal CLI's development server, one temporalio/temporal container started through testcontainers, in memory. The package default-exports it with the default options, so globalSetup: ["@btravstack/temporal-testing"] is the whole configuration.

By default the container is reused: every run on the Docker host, including concurrent ones in other processes, attaches to one server, which outlives the run. reuse: false owns a server for this run instead, and stops it at the run's end.

Parameters ​

ParameterType
__namedParameters?TemporalServerOptions

Returns ​

(__namedParameters) => Promise<(() => Promise<void>) | undefined>

Example ​

ts
// temporal-setup.ts, for a run that owns its server
import { temporalServer } from "@btravstack/temporal-testing";

export default temporalServer({ reuse: false });

Released under the MIT License.