@temporalio/testing 1.0.0-rc.0 → 1.0.1

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.
@@ -1,4 +1,5 @@
1
1
  /// <reference types="node" />
2
+ /// <reference types="node" />
2
3
  import { ChildProcess } from 'child_process';
3
4
  export declare class ChildProcessError extends Error {
4
5
  readonly code: number | null;
package/lib/index.d.ts CHANGED
@@ -1,3 +1,13 @@
1
+ /**
2
+ * `npm i @temporalio/testing`
3
+ *
4
+ * Testing library for the SDK.
5
+ *
6
+ * [Documentation](https://docs.temporal.io/typescript/testing)
7
+ *
8
+ * @module
9
+ */
10
+ /// <reference types="node" />
1
11
  /// <reference types="node" />
2
12
  import * as activity from '@temporalio/activity';
3
13
  import { AsyncCompletionClient, WorkflowClient as BaseWorkflowClient, WorkflowClientOptions as BaseWorkflowClientOptions, WorkflowResultOptions as BaseWorkflowResultOptions, WorkflowStartOptions as BaseWorkflowStartOptions } from '@temporalio/client';
package/lib/index.js CHANGED
@@ -1,4 +1,13 @@
1
1
  "use strict";
2
+ /**
3
+ * `npm i @temporalio/testing`
4
+ *
5
+ * Testing library for the SDK.
6
+ *
7
+ * [Documentation](https://docs.temporal.io/typescript/testing)
8
+ *
9
+ * @module
10
+ */
2
11
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
12
  if (k2 === undefined) k2 = k;
4
13
  var desc = Object.getOwnPropertyDescriptor(m, k);
@@ -202,6 +211,7 @@ exports.TestWorkflowEnvironment = TestWorkflowEnvironment;
202
211
  */
203
212
  exports.defaultActivityInfo = {
204
213
  attempt: 1,
214
+ taskQueue: 'test',
205
215
  isLocal: false,
206
216
  taskToken: Buffer.from('test'),
207
217
  activityId: 'test',
@@ -235,6 +245,9 @@ class MockActivityEnvironment extends events_1.default.EventEmitter {
235
245
  });
236
246
  const heartbeatCallback = (details) => this.emit('heartbeat', details);
237
247
  this.context = new activity.Context({ ...exports.defaultActivityInfo, ...info }, promise, abortController.signal, heartbeatCallback);
248
+ promise.catch(() => {
249
+ /* avoid unhandled rejection */
250
+ });
238
251
  }
239
252
  /**
240
253
  * Run a function in Activity Context
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+DAAiD;AACjD,+CAM4B;AAC5B,+CAA8G;AAC9G,+CAA6E;AAC7E,gDAAwB;AACxB,4CAAoB;AACpB,uDAAmD;AACnD,iDAAkE;AAClE,oDAA4B;AAC5B,mDAAoD;AAEpD,+DAAgE;AAEhE,MAAM,2BAA2B,GAAG,YAAE,CAAC,QAAQ,EAAE,KAAK,OAAO,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC,aAAa,CAAC;AAErF,QAAA,wBAAwB,GAAG,cAAI,CAAC,IAAI,CAAC,SAAS,EAAE,MAAM,2BAA2B,EAAE,CAAC,CAAC;AAgClG;;;;GAIG;AACH,MAAa,cAAe,SAAQ,uBAAkB;IAGpD,YAAY,OAA8B;QACxC,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC;IACpD,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,OAAO,CAClB,kBAA8B,EAC9B,OAAgC;QAEhC,OAAO,KAAK,CAAC,OAAO,CAAC,kBAAkB,EAAE,OAAO,CAAC,CAAC;IACpD,CAAC;IAED;;;;OAIG;IACM,KAAK,CAAC,MAAM,CACnB,UAAkB,EAClB,KAA0B,EAC1B,IAAwC;QAExC,IAAI,IAAI,EAAE,eAAe,EAAE;YACzB,OAAO,MAAM,KAAK,CAAC,MAAM,CAAC,UAAU,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;SACpD;QACD,MAAM,IAAI,CAAC,WAAW,CAAC,kBAAkB,CAAC,EAAE,CAAC,CAAC;QAC9C,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AAG,IAAI,EAAE,EACnC,OAAO,EACP,eAAe,CAAC,MAAM,EACtB,iBAAiB,CAClB,CAAC;QACF,OAAO,CAAC,KAAK,CAAC,GAAG,EAAE;YACjB,+BAA+B;QACjC,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACI,GAAG,CAAuD,EAAK,EAAE,GAAG,IAAO;QAChF,OAAO,QAAQ,CAAC,iBAAiB,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,EAAE,GAAG,IAAI,CAAC,CAAC;IACnE,CAAC;CACF;AA/BD,0DA+BC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@temporalio/testing",
3
- "version": "1.0.0-rc.0",
3
+ "version": "1.0.1",
4
4
  "description": "Temporal.io SDK Testing sub-package",
5
5
  "main": "lib/index.js",
6
6
  "types": "./lib/index.d.ts",
@@ -17,17 +17,17 @@
17
17
  "author": "Temporal Technologies Inc. <sdk@temporal.io>",
18
18
  "license": "MIT",
19
19
  "dependencies": {
20
- "@grpc/grpc-js": "^1.5.7",
21
- "@temporalio/activity": "^1.0.0-rc.0",
22
- "@temporalio/client": "^1.0.0-rc.0",
23
- "@temporalio/common": "^1.0.0-rc.0",
24
- "@temporalio/worker": "^1.0.0-rc.0",
25
- "@types/long": "^4.0.1",
20
+ "@grpc/grpc-js": "^1.6.7",
21
+ "@temporalio/activity": "^1.0.1",
22
+ "@temporalio/client": "^1.0.1",
23
+ "@temporalio/common": "^1.0.1",
24
+ "@temporalio/worker": "^1.0.1",
25
+ "@types/long": "^4.0.2",
26
26
  "abort-controller": "^3.0.0",
27
27
  "get-port": "^6.1.2",
28
- "got": "^12.0.1",
29
- "long": "^4.0.0",
30
- "protobufjs": "^6.11.2",
28
+ "got": "^12.1.0",
29
+ "long": "^5.2.0",
30
+ "protobufjs": "^7.0.0",
31
31
  "tar-stream": "^2.2.0",
32
32
  "unzipper": "^0.10.11"
33
33
  },
@@ -37,11 +37,12 @@
37
37
  "homepage": "https://github.com/temporalio/sdk-typescript/tree/main/packages/testing",
38
38
  "files": [
39
39
  "lib",
40
+ "src",
40
41
  "generated-protos",
41
42
  "scripts"
42
43
  ],
43
44
  "publishConfig": {
44
45
  "access": "public"
45
46
  },
46
- "gitHead": "c25e91309b980f2118df4048d760306982019871"
47
+ "gitHead": "a1dae539e72b6b088b400998d7bef482e8ed52f1"
47
48
  }
@@ -1,12 +1,14 @@
1
+ import { createRequire } from 'module';
1
2
  import { resolve, dirname } from 'path';
2
3
  import { fileURLToPath } from 'url';
3
4
  import { promisify } from 'util';
4
5
  import dedent from 'dedent';
5
6
  import glob from 'glob';
6
7
  import { statSync, mkdirSync, readFileSync, writeFileSync } from 'fs';
7
- import pbjs from 'protobufjs/cli/pbjs.js';
8
- import pbts from 'protobufjs/cli/pbts.js';
8
+ import pbjs from 'protobufjs-cli/pbjs.js';
9
+ import pbts from 'protobufjs-cli/pbts.js';
9
10
 
11
+ const require = createRequire(import.meta.url);
10
12
  const __dirname = dirname(fileURLToPath(import.meta.url));
11
13
  const outputDir = resolve(__dirname, '../generated-protos');
12
14
  const outputFile = resolve(outputDir, 'index.js');
@@ -40,6 +42,7 @@ async function compileProtos(protoPath, jsOutputFile, dtsOutputFile, ...args) {
40
42
  '__temporal_testing',
41
43
  '--out',
42
44
  jsOutputFile,
45
+ resolve(require.resolve('protobufjs'), '../google/protobuf/descriptor.proto'),
43
46
  protoPath,
44
47
  ];
45
48
  await promisify(pbjs.main)(pbjsArgs);
@@ -58,24 +61,17 @@ async function compileProtos(protoPath, jsOutputFile, dtsOutputFile, ...args) {
58
61
  );
59
62
  }
60
63
 
61
- async function main() {
62
- mkdirSync(outputDir, { recursive: true });
64
+ mkdirSync(outputDir, { recursive: true });
63
65
 
64
- const protoFiles = glob.sync(resolve(protoBaseDir, '**/*.proto'));
65
- const protosMTime = Math.max(...protoFiles.map(mtime));
66
- const genMTime = mtime(outputFile);
66
+ const protoFiles = glob.sync(resolve(protoBaseDir, '**/*.proto'));
67
+ const protosMTime = Math.max(...protoFiles.map(mtime));
68
+ const genMTime = mtime(outputFile);
67
69
 
68
- if (protosMTime < genMTime) {
69
- console.log('Assuming protos are up to date');
70
- return;
71
- }
72
-
73
- await compileProtos(serviceProtoPath, outputFile, resolve(outputDir, 'index.d.ts'), '--path', resolve(protoBaseDir));
74
-
75
- console.log('Done');
70
+ if (protosMTime < genMTime) {
71
+ console.log('Assuming protos are up to date');
72
+ process.exit(0);
76
73
  }
77
74
 
78
- main().catch((err) => {
79
- console.error(err);
80
- process.exit(1);
81
- });
75
+ await compileProtos(serviceProtoPath, outputFile, resolve(outputDir, 'index.d.ts'), '--path', resolve(protoBaseDir));
76
+
77
+ console.log('Done');
@@ -0,0 +1,38 @@
1
+ import assert from 'assert';
2
+ import { ApplicationFailure, WorkflowInterceptors } from '@temporalio/workflow';
3
+
4
+ /**
5
+ * Simple interceptor that transforms {@link assert.AssertionError} into non retryable failures.
6
+ *
7
+ * This allows conveniently using `assert` directly from Workflows.
8
+ */
9
+ export function interceptors(): WorkflowInterceptors {
10
+ return {
11
+ inbound: [
12
+ {
13
+ async handleSignal(input, next) {
14
+ try {
15
+ return await next(input);
16
+ } catch (err) {
17
+ if (err instanceof assert.AssertionError) {
18
+ const appErr = ApplicationFailure.nonRetryable(err.message);
19
+ appErr.stack = err.stack;
20
+ throw appErr;
21
+ }
22
+ }
23
+ },
24
+ async execute(input, next) {
25
+ try {
26
+ return await next(input);
27
+ } catch (err) {
28
+ if (err instanceof assert.AssertionError) {
29
+ const appErr = ApplicationFailure.nonRetryable(err.message);
30
+ appErr.stack = err.stack;
31
+ throw appErr;
32
+ }
33
+ }
34
+ },
35
+ },
36
+ ],
37
+ };
38
+ }
@@ -0,0 +1,60 @@
1
+ // TODO: this code is duplicated in the scripts directory, consider moving to external dependency
2
+ import { ChildProcess } from 'child_process';
3
+
4
+ export class ChildProcessError extends Error {
5
+ public readonly name = 'ChildProcessError';
6
+
7
+ constructor(message: string, public readonly code: number | null, public readonly signal: NodeJS.Signals | null) {
8
+ super(message);
9
+ }
10
+ }
11
+
12
+ export interface WaitOptions {
13
+ validReturnCodes: number[];
14
+ }
15
+
16
+ export async function waitOnChild(child: ChildProcess, opts?: WaitOptions): Promise<void> {
17
+ return new Promise((resolve, reject) => {
18
+ child.on('exit', (code, signal) => {
19
+ if (code !== null && (opts?.validReturnCodes ?? [0]).includes(code)) {
20
+ resolve();
21
+ } else {
22
+ reject(new ChildProcessError('Process failed', code, signal));
23
+ }
24
+ });
25
+ child.on('error', reject);
26
+ });
27
+ }
28
+
29
+ export async function kill(child: ChildProcess, signal: NodeJS.Signals = 'SIGINT', opts?: WaitOptions): Promise<void> {
30
+ if (child.pid === undefined) {
31
+ throw new TypeError('Expected child with pid');
32
+ }
33
+ process.kill(child.pid, signal);
34
+ try {
35
+ await waitOnChild(child, opts);
36
+ } catch (err) {
37
+ // Should error if the error is not a child process error or it is a child
38
+ // process and either the platform is Windows or the signal matches.
39
+ const shouldError = !(err instanceof ChildProcessError) || (process.platform !== 'win32' && err.signal !== signal);
40
+ if (shouldError) {
41
+ throw err;
42
+ }
43
+ }
44
+ }
45
+
46
+ export async function killIfExists(
47
+ child: ChildProcess,
48
+ signal: NodeJS.Signals = 'SIGINT',
49
+ opts?: WaitOptions
50
+ ): Promise<void> {
51
+ try {
52
+ await kill(child, signal, opts);
53
+ } catch (err: any) {
54
+ if (err.code !== 'ESRCH') {
55
+ throw err;
56
+ }
57
+ }
58
+ }
59
+
60
+ export const shell = process.platform === 'win32';
@@ -0,0 +1,2 @@
1
+ // Reexports the contents of this package under the "testing" namespace for better docs generation
2
+ export * as testing from './index';
package/src/index.ts ADDED
@@ -0,0 +1,358 @@
1
+ /**
2
+ * `npm i @temporalio/testing`
3
+ *
4
+ * Testing library for the SDK.
5
+ *
6
+ * [Documentation](https://docs.temporal.io/typescript/testing)
7
+ *
8
+ * @module
9
+ */
10
+
11
+ import * as activity from '@temporalio/activity';
12
+ import {
13
+ AsyncCompletionClient,
14
+ WorkflowClient as BaseWorkflowClient,
15
+ WorkflowClientOptions as BaseWorkflowClientOptions,
16
+ WorkflowResultOptions as BaseWorkflowResultOptions,
17
+ WorkflowStartOptions as BaseWorkflowStartOptions,
18
+ } from '@temporalio/client';
19
+ import { ActivityFunction, CancelledFailure, msToTs, Workflow, WorkflowResultType } from '@temporalio/common';
20
+ import { NativeConnection, Logger, DefaultLogger } from '@temporalio/worker';
21
+ import path from 'path';
22
+ import os from 'os';
23
+ import { AbortController } from 'abort-controller';
24
+ import { ChildProcess, spawn, StdioOptions } from 'child_process';
25
+ import events from 'events';
26
+ import { kill, waitOnChild } from './child-process';
27
+ import type getPortType from 'get-port';
28
+ import { Connection, TestService } from './test-service-client';
29
+
30
+ const TEST_SERVER_EXECUTABLE_NAME = os.platform() === 'win32' ? 'test-server.exe' : 'test-server';
31
+
32
+ export const DEFAULT_TEST_SERVER_PATH = path.join(__dirname, `../${TEST_SERVER_EXECUTABLE_NAME}`);
33
+
34
+ /**
35
+ * Options passed to {@link WorkflowClient.result}, these are the same as the
36
+ * {@link BaseWorkflowResultOptions} with an additional option that controls
37
+ * whether to toggle time skipping in the Test server while waiting on a
38
+ * Workflow's result.
39
+ */
40
+ export interface WorkflowResultOptions extends BaseWorkflowResultOptions {
41
+ /**
42
+ * If set to `true`, waiting for the result does not enable time skipping
43
+ */
44
+ runInNormalTime?: boolean;
45
+ }
46
+
47
+ /**
48
+ * Options passed to {@link WorkflowClient.execute}, these are the same as the
49
+ * {@link BaseWorkflowStartOptions} with an additional option that controls
50
+ * whether to toggle time skipping in the Test server while waiting on a
51
+ * Workflow's result.
52
+ */
53
+ export type WorkflowStartOptions<T extends Workflow> = BaseWorkflowStartOptions<T> & {
54
+ /**
55
+ * If set to `true`, waiting for the result does not enable time skipping
56
+ */
57
+ runInNormalTime?: boolean;
58
+ };
59
+
60
+ export interface WorkflowClientOptions extends BaseWorkflowClientOptions {
61
+ connection: Connection;
62
+ }
63
+
64
+ /**
65
+ * A client with the exact same API as the "normal" client with 1 exception,
66
+ * When this client waits on a Workflow's result, it will enable time skipping
67
+ * in the test server.
68
+ */
69
+ export class WorkflowClient extends BaseWorkflowClient {
70
+ protected readonly testService: TestService;
71
+
72
+ constructor(options: WorkflowClientOptions) {
73
+ super(options);
74
+ this.testService = options.connection.testService;
75
+ }
76
+
77
+ /**
78
+ * Execute a Workflow and wait for completion.
79
+ *
80
+ * @see {@link BaseWorkflowClient.execute}
81
+ */
82
+ public async execute<T extends Workflow>(
83
+ workflowTypeOrFunc: string | T,
84
+ options: WorkflowStartOptions<T>
85
+ ): Promise<WorkflowResultType<T>> {
86
+ return super.execute(workflowTypeOrFunc, options);
87
+ }
88
+
89
+ /**
90
+ * Gets the result of a Workflow execution.
91
+ *
92
+ * @see {@link BaseWorkflowClient.result}
93
+ */
94
+ override async result<T>(
95
+ workflowId: string,
96
+ runId?: string | undefined,
97
+ opts?: WorkflowResultOptions | undefined
98
+ ): Promise<T> {
99
+ if (opts?.runInNormalTime) {
100
+ return await super.result(workflowId, runId, opts);
101
+ }
102
+ await this.testService.unlockTimeSkipping({});
103
+ try {
104
+ return await super.result(workflowId, runId, opts);
105
+ } finally {
106
+ await this.testService.lockTimeSkipping({});
107
+ }
108
+ }
109
+ }
110
+
111
+ /**
112
+ * Convenience workflow interceptors
113
+ *
114
+ * Contains a single interceptor for transforming `AssertionError`s into non
115
+ * retryable `ApplicationFailure`s.
116
+ */
117
+ export const workflowInterceptorModules = [path.join(__dirname, 'assert-to-failure-interceptor')];
118
+
119
+ export interface TestServerSpawnerOptions {
120
+ /**
121
+ * @default {@link DEFAULT_TEST_SERVER_PATH}
122
+ */
123
+ path?: string;
124
+ /**
125
+ * @default ignore
126
+ */
127
+ stdio?: StdioOptions;
128
+ }
129
+
130
+ /**
131
+ * A generic callback that returns a child process
132
+ */
133
+ export type TestServerSpawner = (port: number) => ChildProcess;
134
+
135
+ /**
136
+ * Options for {@link TestWorkflowEnvironment.create}
137
+ */
138
+ export interface TestWorkflowEnvironmentOptions {
139
+ testServer?: TestServerSpawner | TestServerSpawnerOptions;
140
+ logger?: Logger;
141
+ }
142
+
143
+ interface TestWorkflowEnvironmentOptionsWithDefaults {
144
+ testServerSpawner: TestServerSpawner;
145
+ logger: Logger;
146
+ }
147
+
148
+ function addDefaults({
149
+ testServer,
150
+ logger,
151
+ }: TestWorkflowEnvironmentOptions): TestWorkflowEnvironmentOptionsWithDefaults {
152
+ return {
153
+ testServerSpawner:
154
+ typeof testServer === 'function'
155
+ ? testServer
156
+ : (port: number) =>
157
+ spawn(testServer?.path || DEFAULT_TEST_SERVER_PATH, [`${port}`], {
158
+ stdio: testServer?.stdio || 'ignore',
159
+ }),
160
+ logger: logger ?? new DefaultLogger('INFO'),
161
+ };
162
+ }
163
+
164
+ // TS transforms `import` statements into `require`s, this is a workaround until
165
+ // tsconfig module nodenext is stable.
166
+ const _importDynamic = new Function('modulePath', 'return import(modulePath)');
167
+
168
+ /**
169
+ * An execution environment for running Workflow integration tests.
170
+ *
171
+ * Runs an external server.
172
+ * By default, the Java test server is used which supports time skipping.
173
+ */
174
+ export class TestWorkflowEnvironment {
175
+ /**
176
+ * Get an extablished {@link Connection} to the test server
177
+ */
178
+ public readonly connection: Connection;
179
+
180
+ /**
181
+ * An {@link AsyncCompletionClient} for interacting with the test server
182
+ */
183
+ public readonly asyncCompletionClient: AsyncCompletionClient;
184
+
185
+ /**
186
+ * A {@link WorkflowClient} for interacting with the test server
187
+ */
188
+ public readonly workflowClient: WorkflowClient;
189
+
190
+ /**
191
+ * A {@link NativeConnection} for interacting with the test server.
192
+ *
193
+ * Use this connection when creating Workers for testing.
194
+ */
195
+ public readonly nativeConnection: NativeConnection;
196
+
197
+ protected constructor(
198
+ protected readonly serverProc: ChildProcess,
199
+ connection: Connection,
200
+ nativeConnection: NativeConnection
201
+ ) {
202
+ this.connection = connection;
203
+ this.nativeConnection = nativeConnection;
204
+ this.workflowClient = new WorkflowClient({ connection });
205
+ this.asyncCompletionClient = new AsyncCompletionClient({ connection });
206
+ }
207
+
208
+ /**
209
+ * Create a new test environment
210
+ */
211
+ static async create(opts?: TestWorkflowEnvironmentOptions): Promise<TestWorkflowEnvironment> {
212
+ // No, we're not going to compile this to ESM for one dependency
213
+ const getPort = (await _importDynamic('get-port')).default as typeof getPortType;
214
+ const port = await getPort();
215
+
216
+ const { testServerSpawner, logger } = addDefaults(opts ?? {});
217
+
218
+ const child = testServerSpawner(port);
219
+
220
+ const address = `127.0.0.1:${port}`;
221
+ const connPromise = Connection.connect({ address });
222
+
223
+ try {
224
+ await Promise.race([
225
+ connPromise,
226
+ waitOnChild(child).then(() => {
227
+ throw new Error('Test server child process exited prematurely');
228
+ }),
229
+ ]);
230
+ } catch (err) {
231
+ try {
232
+ await kill(child);
233
+ } catch (error) {
234
+ logger.error('Failed to kill test server child process', { error });
235
+ }
236
+ throw err;
237
+ }
238
+
239
+ const conn = await connPromise;
240
+ const nativeConnection = await NativeConnection.connect({ address });
241
+
242
+ return new this(child, conn, nativeConnection);
243
+ }
244
+
245
+ /**
246
+ * Kill the test server process and close the connection to it
247
+ */
248
+ async teardown(): Promise<void> {
249
+ await this.connection.close();
250
+ await this.nativeConnection.close();
251
+ // TODO: the server should return exit code 0
252
+ await kill(this.serverProc, 'SIGINT', { validReturnCodes: [0, 130] });
253
+ }
254
+
255
+ /**
256
+ * Wait for `durationMs` in "test server time".
257
+ *
258
+ * The test server toggles between skipped time and normal time depending on what it needs to execute.
259
+ *
260
+ * This method is likely to resolve in less than `durationMs` of "real time".
261
+ *
262
+ * Useful for simulating events far into the future like completion of long running activities.
263
+ *
264
+ * @param durationMs {@link https://www.npmjs.com/package/ms | ms} formatted string or number of milliseconds
265
+ *
266
+ * @example
267
+ *
268
+ * `workflow.ts`
269
+ *
270
+ * ```ts
271
+ * const activities = proxyActivities({ startToCloseTimeout: 2_000_000 });
272
+ *
273
+ * export async function raceActivityAndTimer(): Promise<string> {
274
+ * return await Promise.race([
275
+ * wf.sleep(500_000).then(() => 'timer'),
276
+ * activities.longRunning().then(() => 'activity'),
277
+ * ]);
278
+ * }
279
+ * ```
280
+ *
281
+ * `test.ts`
282
+ *
283
+ * ```ts
284
+ * const worker = await Worker.create({
285
+ * connection: testEnv.nativeConnection,
286
+ * activities: {
287
+ * async longRunning() {
288
+ * await testEnv.sleep(1_000_000); // <-- sleep called here
289
+ * },
290
+ * },
291
+ * // ...
292
+ * });
293
+ * ```
294
+ */
295
+ sleep = async (durationMs: number | string): Promise<void> => {
296
+ await this.connection.testService.unlockTimeSkippingWithSleep({ duration: msToTs(durationMs) });
297
+ };
298
+ }
299
+
300
+ /**
301
+ * Used as the default activity info for Activities executed in the {@link MockActivityEnvironment}
302
+ */
303
+ export const defaultActivityInfo: activity.Info = {
304
+ attempt: 1,
305
+ taskQueue: 'test',
306
+ isLocal: false,
307
+ taskToken: Buffer.from('test'),
308
+ activityId: 'test',
309
+ activityType: 'unknown',
310
+ workflowType: 'test',
311
+ base64TaskToken: Buffer.from('test').toString('base64'),
312
+ heartbeatDetails: undefined,
313
+ activityNamespace: 'default',
314
+ workflowNamespace: 'default',
315
+ workflowExecution: { workflowId: 'test', runId: 'dead-beef' },
316
+ scheduledTimestampMs: 1,
317
+ startToCloseTimeoutMs: 1000,
318
+ scheduleToCloseTimeoutMs: 1000,
319
+ };
320
+
321
+ /**
322
+ * An execution environment for testing Activities.
323
+ *
324
+ * Mocks Activity {@link Context | activity.Context} and exposes hooks for
325
+ * cancellation and heartbeats.
326
+ */
327
+ export class MockActivityEnvironment extends events.EventEmitter {
328
+ public cancel: (reason?: any) => void = () => undefined;
329
+ public readonly context: activity.Context;
330
+
331
+ constructor(info?: Partial<activity.Info>) {
332
+ super();
333
+ const abortController = new AbortController();
334
+ const promise = new Promise<never>((_, reject) => {
335
+ this.cancel = (reason?: any) => {
336
+ abortController.abort();
337
+ reject(new CancelledFailure(reason));
338
+ };
339
+ });
340
+ const heartbeatCallback = (details?: unknown) => this.emit('heartbeat', details);
341
+ this.context = new activity.Context(
342
+ { ...defaultActivityInfo, ...info },
343
+ promise,
344
+ abortController.signal,
345
+ heartbeatCallback
346
+ );
347
+ promise.catch(() => {
348
+ /* avoid unhandled rejection */
349
+ });
350
+ }
351
+
352
+ /**
353
+ * Run a function in Activity Context
354
+ */
355
+ public run<P extends any[], R, F extends ActivityFunction<P, R>>(fn: F, ...args: P): Promise<R> {
356
+ return activity.asyncLocalStorage.run(this.context, fn, ...args);
357
+ }
358
+ }