@temporal-contract/testing 0.0.7 โ 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +24 -2
- package/dist/extension.d.mts +4 -3
- package/dist/extension.d.mts.map +1 -0
- package/dist/extension.mjs +2 -1
- package/dist/extension.mjs.map +1 -0
- package/dist/global-setup.d.mts +2 -1
- package/dist/global-setup.d.mts.map +1 -0
- package/dist/global-setup.mjs +2 -1
- package/dist/global-setup.mjs.map +1 -0
- package/package.json +12 -8
package/README.md
CHANGED
|
@@ -12,18 +12,40 @@ pnpm add -D @temporal-contract/testing
|
|
|
12
12
|
|
|
13
13
|
## Quick Example
|
|
14
14
|
|
|
15
|
+
### Global Setup
|
|
16
|
+
|
|
17
|
+
Configure Vitest to start a Temporal server before all tests:
|
|
18
|
+
|
|
15
19
|
```typescript
|
|
16
20
|
// vitest.config.ts
|
|
17
|
-
import { defineConfig } from
|
|
21
|
+
import { defineConfig } from "vitest/config";
|
|
18
22
|
|
|
19
23
|
export default defineConfig({
|
|
20
24
|
test: {
|
|
21
|
-
globalSetup:
|
|
25
|
+
globalSetup: "@temporal-contract/testing/global-setup",
|
|
22
26
|
testTimeout: 60000,
|
|
23
27
|
},
|
|
24
28
|
});
|
|
25
29
|
```
|
|
26
30
|
|
|
31
|
+
### Test Extension
|
|
32
|
+
|
|
33
|
+
Use the `it` extension for automatic connection management:
|
|
34
|
+
|
|
35
|
+
```typescript
|
|
36
|
+
// my-workflow.spec.ts
|
|
37
|
+
import { it } from "@temporal-contract/testing/extension";
|
|
38
|
+
import { expect } from "vitest";
|
|
39
|
+
|
|
40
|
+
it("should execute workflow", async ({ clientConnection, workerConnection }) => {
|
|
41
|
+
// clientConnection: Connection from @temporalio/client (auto-connected, auto-closed)
|
|
42
|
+
// workerConnection: NativeConnection from @temporalio/worker (auto-connected)
|
|
43
|
+
|
|
44
|
+
const client = new Client({ connection: clientConnection });
|
|
45
|
+
// ... use client and workerConnection in your test
|
|
46
|
+
});
|
|
47
|
+
```
|
|
48
|
+
|
|
27
49
|
## Documentation
|
|
28
50
|
|
|
29
51
|
๐ **[Read the full documentation โ](https://btravers.github.io/temporal-contract)**
|
package/dist/extension.d.mts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { Connection } from "@temporalio/client";
|
|
2
2
|
import { NativeConnection } from "@temporalio/worker/lib/connection.js";
|
|
3
|
-
import * as
|
|
3
|
+
import * as vitest from "vitest";
|
|
4
4
|
|
|
5
5
|
//#region src/extension.d.ts
|
|
6
|
-
declare const it:
|
|
6
|
+
declare const it: vitest.TestAPI<{
|
|
7
7
|
clientConnection: Connection;
|
|
8
8
|
workerConnection: NativeConnection;
|
|
9
9
|
}>;
|
|
10
10
|
//#endregion
|
|
11
|
-
export { it };
|
|
11
|
+
export { it };
|
|
12
|
+
//# sourceMappingURL=extension.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extension.d.mts","names":[],"sources":["../src/extension.ts"],"mappings":";;;;;cAIa,EAAA,SAAE,OAAA"}
|
package/dist/extension.mjs
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extension.mjs","names":["vitestIt"],"sources":["../src/extension.ts"],"sourcesContent":["import { Connection } from \"@temporalio/client\";\nimport { NativeConnection } from \"@temporalio/worker/lib/connection.js\";\nimport { inject, it as vitestIt } from \"vitest\";\n\nexport const it = vitestIt.extend<{\n clientConnection: Connection;\n workerConnection: NativeConnection;\n}>({\n // oxlint-disable-next-line no-empty-pattern\n clientConnection: async ({}, use) => {\n const connection = await getTemporalConnection();\n await use(connection);\n await connection.close();\n },\n // oxlint-disable-next-line no-empty-pattern\n workerConnection: async ({}, use) => {\n const connection = await getTemporalWorkerConnection();\n await use(connection);\n // Note: NativeConnection.close() may cause issues in test cleanup,\n // let the test framework handle cleanup instead\n },\n});\n\n/**\n * Get a connection to the Temporal server (for client)\n * Must be called after setupTemporalTestContainer has been executed\n */\nfunction getTemporalConnection(): Promise<Connection> {\n return Connection.connect({\n address: getTemporalAddress(),\n });\n}\n\n/**\n * Get a native connection to the Temporal server (for worker)\n * Must be called after setupTemporalTestContainer has been executed\n */\nfunction getTemporalWorkerConnection(): Promise<NativeConnection> {\n return NativeConnection.connect({\n address: getTemporalAddress(),\n });\n}\n\nfunction getTemporalAddress(): string {\n return `${inject(\"__TESTCONTAINERS_TEMPORAL_IP__\")}:${inject(\"__TESTCONTAINERS_TEMPORAL_PORT_7233__\")}`;\n}\n"],"mappings":";;;;;AAIA,MAAa,KAAKA,KAAS,OAGxB;CAED,kBAAkB,OAAO,IAAI,QAAQ;EACnC,MAAM,aAAa,MAAM,uBAAuB;AAChD,QAAM,IAAI,WAAW;AACrB,QAAM,WAAW,OAAO;;CAG1B,kBAAkB,OAAO,IAAI,QAAQ;AAEnC,QAAM,IADa,MAAM,6BAA6B,CACjC;;CAIxB,CAAC;;;;;AAMF,SAAS,wBAA6C;AACpD,QAAO,WAAW,QAAQ,EACxB,SAAS,oBAAoB,EAC9B,CAAC;;;;;;AAOJ,SAAS,8BAAyD;AAChE,QAAO,iBAAiB,QAAQ,EAC9B,SAAS,oBAAoB,EAC9B,CAAC;;AAGJ,SAAS,qBAA6B;AACpC,QAAO,GAAG,OAAO,iCAAiC,CAAC,GAAG,OAAO,wCAAwC"}
|
package/dist/global-setup.d.mts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"global-setup.d.mts","names":[],"sources":["../src/global-setup.ts"],"mappings":";;;;YAKmB,eAAA;IACf,8BAAA;IACA,qCAAA;EAAA;AAAA;;;;;iBAQ0B,KAAA,CAAA;EAAQ;AAAA,GAAW,WAAA,GAAW,OAAA,OAAA,OAAA"}
|
package/dist/global-setup.mjs
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"global-setup.mjs","names":[],"sources":["../src/global-setup.ts"],"sourcesContent":["import { GenericContainer, Wait, Network } from \"testcontainers\";\nimport type { TestProject } from \"vitest/node\";\n\ndeclare module \"vitest\" {\n // oxlint-disable-next-line typescript/consistent-type-definitions -- module augmentation requires interface\n export interface ProvidedContext {\n __TESTCONTAINERS_TEMPORAL_IP__: string;\n __TESTCONTAINERS_TEMPORAL_PORT_7233__: number;\n }\n}\n\n/**\n * Setup function for Vitest globalSetup\n * Starts a Temporal server container before all tests\n */\nexport default async function setup({ provide }: TestProject) {\n console.log(\"๐ณ Starting Temporal test environment...\");\n\n // Create a network for containers to communicate\n const network = await new Network().start();\n\n // Start PostgreSQL container first\n console.log(\"๐ณ Starting PostgreSQL container...\");\n const postgresContainer = await new GenericContainer(\"postgres:18.1\")\n .withNetwork(network)\n .withNetworkAliases(\"postgres\")\n .withExposedPorts(5432)\n .withEnvironment({\n POSTGRES_DB: \"temporal\",\n POSTGRES_USER: \"temporal\",\n POSTGRES_PASSWORD: \"temporal\",\n })\n .withHealthCheck({\n test: [\"CMD-SHELL\", \"pg_isready -U temporal\"],\n interval: 1_000,\n retries: 30,\n startPeriod: 1_000,\n timeout: 1_000,\n })\n .withWaitStrategy(Wait.forHealthCheck())\n .start();\n\n console.log(\"โ
PostgreSQL container started\");\n\n // Start Temporal container\n console.log(\"๐ณ Starting Temporal container...\");\n const temporalContainer = await new GenericContainer(\"temporalio/auto-setup:1.29.1\")\n .withNetwork(network)\n .withExposedPorts(7233)\n .withEnvironment({\n DB: \"postgres12\",\n DB_PORT: \"5432\",\n POSTGRES_SEEDS: \"postgres\",\n POSTGRES_USER: \"temporal\",\n POSTGRES_PWD: \"temporal\",\n BIND_ON_IP: \"0.0.0.0\",\n TEMPORAL_BROADCAST_ADDRESS: \"127.0.0.1\",\n })\n .withHealthCheck({\n test: [\"CMD-SHELL\", \"tctl --address 127.0.0.1:7233 workflow list\"],\n interval: 1_000,\n retries: 30,\n startPeriod: 1_000,\n timeout: 1_000,\n })\n .withWaitStrategy(Wait.forHealthCheck())\n .start();\n\n console.log(\"โ
Temporal container started\");\n\n const __TESTCONTAINERS_TEMPORAL_IP__ = temporalContainer.getHost();\n const __TESTCONTAINERS_TEMPORAL_PORT_7233__ = temporalContainer.getMappedPort(7233);\n\n provide(\"__TESTCONTAINERS_TEMPORAL_IP__\", __TESTCONTAINERS_TEMPORAL_IP__);\n provide(\"__TESTCONTAINERS_TEMPORAL_PORT_7233__\", __TESTCONTAINERS_TEMPORAL_PORT_7233__);\n\n console.log(\n `๐ Temporal test environment is ready at ${__TESTCONTAINERS_TEMPORAL_IP__}:${__TESTCONTAINERS_TEMPORAL_PORT_7233__}`,\n );\n\n // Return teardown function\n return async () => {\n console.log(\"๐งน Cleaning up Temporal test environment...\");\n\n try {\n await temporalContainer.stop();\n console.log(\"โ
Temporal container stopped\");\n } catch (error) {\n console.error(\"โ ๏ธ Error stopping container:\", error);\n }\n\n try {\n await postgresContainer.stop();\n console.log(\"โ
PostgreSQL container stopped\");\n } catch (error) {\n console.error(\"โ ๏ธ Error stopping PostgreSQL container:\", error);\n }\n\n try {\n await network.stop();\n console.log(\"โ
Network stopped\");\n } catch (error) {\n console.error(\"โ ๏ธ Error stopping network:\", error);\n }\n };\n}\n"],"mappings":";;;;;;;AAeA,eAA8B,MAAM,EAAE,WAAwB;AAC5D,SAAQ,IAAI,2CAA2C;CAGvD,MAAM,UAAU,MAAM,IAAI,SAAS,CAAC,OAAO;AAG3C,SAAQ,IAAI,sCAAsC;CAClD,MAAM,oBAAoB,MAAM,IAAI,iBAAiB,gBAAgB,CAClE,YAAY,QAAQ,CACpB,mBAAmB,WAAW,CAC9B,iBAAiB,KAAK,CACtB,gBAAgB;EACf,aAAa;EACb,eAAe;EACf,mBAAmB;EACpB,CAAC,CACD,gBAAgB;EACf,MAAM,CAAC,aAAa,yBAAyB;EAC7C,UAAU;EACV,SAAS;EACT,aAAa;EACb,SAAS;EACV,CAAC,CACD,iBAAiB,KAAK,gBAAgB,CAAC,CACvC,OAAO;AAEV,SAAQ,IAAI,iCAAiC;AAG7C,SAAQ,IAAI,oCAAoC;CAChD,MAAM,oBAAoB,MAAM,IAAI,iBAAiB,+BAA+B,CACjF,YAAY,QAAQ,CACpB,iBAAiB,KAAK,CACtB,gBAAgB;EACf,IAAI;EACJ,SAAS;EACT,gBAAgB;EAChB,eAAe;EACf,cAAc;EACd,YAAY;EACZ,4BAA4B;EAC7B,CAAC,CACD,gBAAgB;EACf,MAAM,CAAC,aAAa,8CAA8C;EAClE,UAAU;EACV,SAAS;EACT,aAAa;EACb,SAAS;EACV,CAAC,CACD,iBAAiB,KAAK,gBAAgB,CAAC,CACvC,OAAO;AAEV,SAAQ,IAAI,+BAA+B;CAE3C,MAAM,iCAAiC,kBAAkB,SAAS;CAClE,MAAM,wCAAwC,kBAAkB,cAAc,KAAK;AAEnF,SAAQ,kCAAkC,+BAA+B;AACzE,SAAQ,yCAAyC,sCAAsC;AAEvF,SAAQ,IACN,4CAA4C,+BAA+B,GAAG,wCAC/E;AAGD,QAAO,YAAY;AACjB,UAAQ,IAAI,8CAA8C;AAE1D,MAAI;AACF,SAAM,kBAAkB,MAAM;AAC9B,WAAQ,IAAI,+BAA+B;WACpC,OAAO;AACd,WAAQ,MAAM,iCAAiC,MAAM;;AAGvD,MAAI;AACF,SAAM,kBAAkB,MAAM;AAC9B,WAAQ,IAAI,iCAAiC;WACtC,OAAO;AACd,WAAQ,MAAM,4CAA4C,MAAM;;AAGlE,MAAI;AACF,SAAM,QAAQ,MAAM;AACpB,WAAQ,IAAI,oBAAoB;WACzB,OAAO;AACd,WAAQ,MAAM,+BAA+B,MAAM"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@temporal-contract/testing",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Temporal testing utilities",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -18,22 +18,26 @@
|
|
|
18
18
|
"dist"
|
|
19
19
|
],
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@temporalio/client": "1.14.
|
|
22
|
-
"@temporalio/worker": "1.14.
|
|
23
|
-
"testcontainers": "11.
|
|
21
|
+
"@temporalio/client": "1.14.1",
|
|
22
|
+
"@temporalio/worker": "1.14.1",
|
|
23
|
+
"testcontainers": "11.11.0"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@types/node": "25.
|
|
27
|
-
"tsdown": "0.
|
|
26
|
+
"@types/node": "25.2.3",
|
|
27
|
+
"tsdown": "0.20.3",
|
|
28
|
+
"typedoc": "0.28.17",
|
|
29
|
+
"typedoc-plugin-markdown": "4.10.0",
|
|
28
30
|
"typescript": "5.9.3",
|
|
29
|
-
"vitest": "4.0.
|
|
30
|
-
"@temporal-contract/tsconfig": "0.0
|
|
31
|
+
"vitest": "4.0.18",
|
|
32
|
+
"@temporal-contract/tsconfig": "0.2.0",
|
|
33
|
+
"@temporal-contract/typedoc": "0.1.0"
|
|
31
34
|
},
|
|
32
35
|
"peerDependencies": {
|
|
33
36
|
"vitest": "^4"
|
|
34
37
|
},
|
|
35
38
|
"scripts": {
|
|
36
39
|
"build": "tsdown src/global-setup.ts src/extension.ts --format esm --dts --clean",
|
|
40
|
+
"build:docs": "typedoc",
|
|
37
41
|
"typecheck": "tsc --noEmit"
|
|
38
42
|
}
|
|
39
43
|
}
|