@temporal-contract/testing 0.1.0 โ†’ 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 CHANGED
@@ -12,6 +12,10 @@ 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
21
  import { defineConfig } from "vitest/config";
@@ -24,6 +28,24 @@ export default defineConfig({
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)**
@@ -1,11 +1,12 @@
1
1
  import { Connection } from "@temporalio/client";
2
2
  import { NativeConnection } from "@temporalio/worker/lib/connection.js";
3
- import * as vitest0 from "vitest";
3
+ import * as vitest from "vitest";
4
4
 
5
5
  //#region src/extension.d.ts
6
- declare const it: vitest0.TestAPI<{
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"}
@@ -32,4 +32,5 @@ function getTemporalAddress() {
32
32
  }
33
33
 
34
34
  //#endregion
35
- export { it };
35
+ export { it };
36
+ //# sourceMappingURL=extension.mjs.map
@@ -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"}
@@ -15,4 +15,5 @@ declare function setup({
15
15
  provide
16
16
  }: TestProject): Promise<() => Promise<void>>;
17
17
  //#endregion
18
- export { setup as default };
18
+ export { setup as default };
19
+ //# sourceMappingURL=global-setup.d.mts.map
@@ -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"}
@@ -67,4 +67,5 @@ async function setup({ provide }) {
67
67
  }
68
68
 
69
69
  //#endregion
70
- export { setup as default };
70
+ export { setup as default };
71
+ //# sourceMappingURL=global-setup.mjs.map
@@ -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.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Temporal testing utilities",
5
5
  "type": "module",
6
6
  "exports": {
@@ -23,11 +23,13 @@
23
23
  "testcontainers": "11.11.0"
24
24
  },
25
25
  "devDependencies": {
26
- "@types/node": "25.0.9",
27
- "tsdown": "0.20.0-beta.4",
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.17",
30
- "@temporal-contract/tsconfig": "0.1.0",
31
+ "vitest": "4.0.18",
32
+ "@temporal-contract/tsconfig": "0.2.0",
31
33
  "@temporal-contract/typedoc": "0.1.0"
32
34
  },
33
35
  "peerDependencies": {