You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(testing)!: contract-aware fixtures and configurable environments
- item 27: createContractTest(contract, { workflowsPath, activities?,
workerOptions? }) — new ./contract entry; vitest fixtures exposing
{ client, typedClient, worker } wired against the testcontainers server,
reusing the ./extension connection fixtures
- item 27: runActivity(definition, implementation, input, { env? }) — new
vitest-free ./activity entry executing a single AsyncResult activity
implementation inside MockActivityEnvironment, with heartbeat and
cancellation support via a caller-provided environment
- item 28: createTimeSkippingEnvironment forwards
TimeSkippingTestWorkflowEnvironmentOptions; new createTimeSkippingTest
fixture factory so suites can pin the test-server version
- item 28: extension throws a descriptive error naming
@temporal-contract/testing/global-setup when inject values are missing;
workerConnection is now closed in teardown inside try/catch (the known
NativeConnection shutdown race is swallowed)
- item 28: createGlobalSetup({ postgresImage, temporalImage, temporalEnv,
quiet }) factory; the default export becomes createGlobalSetup() with the
previous defaults; add the ./package.json export
- item 29: time-skipping TSDoc examples use .get() and the new
TypedClient.create({ client }) + for(contract) construction; README covers
./contract, ./activity, ./time-skipping and fixes the Client import
- deps: @temporal-contract/client|contract|worker and unthrown become peer
dependencies (they appear in the new public types); the workspace siblings
are resolved via tsconfig paths / vitest aliases locally because declaring
them as dev deps would create a cycle in the package graph (client and
worker already devDepend on this package)
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Configure Vitest to start a Temporal server before all tests:
17
+
Configure Vitest to start a Temporal server (via testcontainers — requires Docker) before all tests:
18
18
19
19
```typescript
20
20
// vitest.config.ts
@@ -28,18 +28,89 @@ export default defineConfig({
28
28
});
29
29
```
30
30
31
-
### Test Extension
31
+
To pin container images, inject extra Temporal env, or silence the progress logs, reference your own module that default-exports `createGlobalSetup(options)`:
32
32
33
-
Use the `it` extension for automatic connection management:
`createContractTest` wires the whole stack for one contract — a running worker, the connection-scoped `TypedClient` root, and the contract-bound `ContractClient`:
const result =awaitclient.executeWorkflow("processOrder", {
66
+
workflowId: `order-${Date.now()}`,
67
+
args: { orderId: "ORD-1" },
68
+
});
69
+
expect(result.isOk()).toBe(true);
70
+
});
71
+
});
72
+
```
73
+
74
+
### Unit-Testing a Single Activity
75
+
76
+
`runActivity` executes one `AsyncResult`-returning activity implementation inside `@temporalio/testing`'s `MockActivityEnvironment` — no worker, no server, no Docker. Pass your own environment to observe heartbeats or trigger cancellation:
const result =awaitrunActivity(chargeCardDefinition, chargeCard, { amount: 100 });
82
+
expect(result.isOk()).toBe(true);
83
+
```
84
+
85
+
### Time-Skipping Environment (no Docker)
86
+
87
+
The `./time-skipping` entry runs suites against Temporal's in-process time-skipping test server (downloaded and cached by `@temporalio/testing` on first use) — hour-long timers resolve instantly:
88
+
89
+
```typescript
90
+
import { it } from"@temporal-contract/testing/time-skipping";
0 commit comments