@temporalio/testing 1.5.2 → 1.7.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/lib/assert-to-failure-interceptor.js +2 -0
- package/lib/assert-to-failure-interceptor.js.map +1 -1
- package/lib/connection.js +1 -0
- package/lib/connection.js.map +1 -1
- package/lib/index.d.ts +15 -15
- package/lib/index.js +29 -24
- package/lib/index.js.map +1 -1
- package/package.json +15 -10
- package/src/assert-to-failure-interceptor.ts +2 -0
- package/src/connection.ts +1 -0
- package/src/index.ts +38 -33
|
@@ -25,6 +25,7 @@ function interceptors() {
|
|
|
25
25
|
appErr.stack = err.stack;
|
|
26
26
|
throw appErr;
|
|
27
27
|
}
|
|
28
|
+
throw err;
|
|
28
29
|
}
|
|
29
30
|
},
|
|
30
31
|
async execute(input, next) {
|
|
@@ -37,6 +38,7 @@ function interceptors() {
|
|
|
37
38
|
appErr.stack = err.stack;
|
|
38
39
|
throw appErr;
|
|
39
40
|
}
|
|
41
|
+
throw err;
|
|
40
42
|
}
|
|
41
43
|
},
|
|
42
44
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assert-to-failure-interceptor.js","sourceRoot":"","sources":["../src/assert-to-failure-interceptor.ts"],"names":[],"mappings":";;;;;;AAAA,oDAA4B;AAC5B,mDAAgF;AAEhF;;;;GAIG;AACH,SAAgB,YAAY;IAC1B,OAAO;QACL,OAAO,EAAE;YACP;gBACE,KAAK,CAAC,YAAY,CAAC,KAAK,EAAE,IAAI;oBAC5B,IAAI;wBACF,OAAO,MAAM,IAAI,CAAC,KAAK,CAAC,CAAC;qBAC1B;oBAAC,OAAO,GAAG,EAAE;wBACZ,IAAI,GAAG,YAAY,gBAAM,CAAC,cAAc,EAAE;4BACxC,MAAM,MAAM,GAAG,6BAAkB,CAAC,YAAY,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;4BAC5D,MAAM,CAAC,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC;4BACzB,MAAM,MAAM,CAAC;yBACd;
|
|
1
|
+
{"version":3,"file":"assert-to-failure-interceptor.js","sourceRoot":"","sources":["../src/assert-to-failure-interceptor.ts"],"names":[],"mappings":";;;;;;AAAA,oDAA4B;AAC5B,mDAAgF;AAEhF;;;;GAIG;AACH,SAAgB,YAAY;IAC1B,OAAO;QACL,OAAO,EAAE;YACP;gBACE,KAAK,CAAC,YAAY,CAAC,KAAK,EAAE,IAAI;oBAC5B,IAAI;wBACF,OAAO,MAAM,IAAI,CAAC,KAAK,CAAC,CAAC;qBAC1B;oBAAC,OAAO,GAAG,EAAE;wBACZ,IAAI,GAAG,YAAY,gBAAM,CAAC,cAAc,EAAE;4BACxC,MAAM,MAAM,GAAG,6BAAkB,CAAC,YAAY,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;4BAC5D,MAAM,CAAC,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC;4BACzB,MAAM,MAAM,CAAC;yBACd;wBACD,MAAM,GAAG,CAAC;qBACX;gBACH,CAAC;gBACD,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI;oBACvB,IAAI;wBACF,OAAO,MAAM,IAAI,CAAC,KAAK,CAAC,CAAC;qBAC1B;oBAAC,OAAO,GAAG,EAAE;wBACZ,IAAI,GAAG,YAAY,gBAAM,CAAC,cAAc,EAAE;4BACxC,MAAM,MAAM,GAAG,6BAAkB,CAAC,YAAY,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;4BAC5D,MAAM,CAAC,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC;4BACzB,MAAM,MAAM,CAAC;yBACd;wBACD,MAAM,GAAG,CAAC;qBACX;gBACH,CAAC;aACF;SACF;KACF,CAAC;AACJ,CAAC;AA/BD,oCA+BC"}
|
package/lib/connection.js
CHANGED
|
@@ -43,6 +43,7 @@ class Connection extends client_1.Connection {
|
|
|
43
43
|
client: ctorOptions.client,
|
|
44
44
|
callContextStorage: ctorOptions.callContextStorage,
|
|
45
45
|
interceptors: ctorOptions.options.interceptors,
|
|
46
|
+
staticMetadata: ctorOptions.options.metadata,
|
|
46
47
|
});
|
|
47
48
|
const testService = exports.TestService.create(rpcImpl, false, false);
|
|
48
49
|
return { ...ctorOptions, testService };
|
package/lib/connection.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connection.js","sourceRoot":"","sources":["../src/connection.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oDAAsC;AACtC,+CAAqF;AAErF,6CAA6C;AAG9B,mBAAW,GAAK,gBAAQ,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,aAAC;AAM3D;;GAEG;AACH,MAAa,UAAW,SAAQ,mBAAc;
|
|
1
|
+
{"version":3,"file":"connection.js","sourceRoot":"","sources":["../src/connection.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oDAAsC;AACtC,+CAAqF;AAErF,6CAA6C;AAG9B,mBAAW,GAAK,gBAAQ,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,aAAC;AAM3D;;GAEG;AACH,MAAa,UAAW,SAAQ,mBAAc;IA4B5C,YAAsB,OAA8B;QAClD,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;IACzC,CAAC;IA3BS,MAAM,CAAC,iBAAiB,CAAC,OAA2B;QAC5D,MAAM,WAAW,GAAG,mBAAc,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC;QAC9D,MAAM,OAAO,GAAG,IAAI,CAAC,yBAAyB,CAAC;YAC7C,WAAW,EAAE,yCAAyC;YACtD,MAAM,EAAE,WAAW,CAAC,MAAM;YAC1B,kBAAkB,EAAE,WAAW,CAAC,kBAAkB;YAClD,YAAY,EAAE,WAAW,CAAC,OAAO,CAAC,YAAY;YAC9C,cAAc,EAAE,WAAW,CAAC,OAAO,CAAC,QAAQ;SAC7C,CAAC,CAAC;QACH,MAAM,WAAW,GAAG,mBAAW,CAAC,MAAM,CAAC,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;QAC9D,OAAO,EAAE,GAAG,WAAW,EAAE,WAAW,EAAE,CAAC;IACzC,CAAC;IAED,MAAM,CAAC,IAAI,CAAC,OAA2B;QACrC,MAAM,WAAW,GAAG,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC;QACpD,OAAO,IAAI,IAAI,CAAC,WAAW,CAAC,CAAC;IAC/B,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,OAA2B;QAC9C,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC/B,MAAM,GAAG,CAAC,eAAe,EAAE,CAAC;QAC5B,OAAO,GAAG,CAAC;IACb,CAAC;;AA1BH,gCAgCC;AA/BwB,4BAAiB,GAAG,IAAI,CAAC,4BAA4B,CAAC,EAAE,EAAE,aAAa,EAAE,EAAE,CAAC,CAAC"}
|
package/lib/index.d.ts
CHANGED
|
@@ -8,14 +8,15 @@
|
|
|
8
8
|
* @module
|
|
9
9
|
*/
|
|
10
10
|
/// <reference types="node" />
|
|
11
|
-
import
|
|
11
|
+
import 'abort-controller/polyfill';
|
|
12
|
+
import events from 'node:events';
|
|
12
13
|
import * as activity from '@temporalio/activity';
|
|
13
14
|
import { AsyncCompletionClient, Client, ClientOptions, ConnectionLike, WorkflowClient, WorkflowClientOptions, WorkflowResultOptions } from '@temporalio/client';
|
|
14
15
|
import { ActivityFunction } from '@temporalio/common';
|
|
15
16
|
import { NativeConnection } from '@temporalio/worker';
|
|
16
|
-
import { EphemeralServer, EphemeralServerConfig,
|
|
17
|
+
import { EphemeralServer, EphemeralServerConfig, DevServerConfig, TimeSkippingServerConfig } from '@temporalio/core-bridge';
|
|
17
18
|
import { Connection, TestService } from './connection';
|
|
18
|
-
export { TimeSkippingServerConfig,
|
|
19
|
+
export { TimeSkippingServerConfig, DevServerConfig, EphemeralServerExecutable } from '@temporalio/core-bridge';
|
|
19
20
|
export { EphemeralServerConfig };
|
|
20
21
|
export interface TimeSkippingWorkflowClientOptions extends WorkflowClientOptions {
|
|
21
22
|
connection: Connection;
|
|
@@ -55,8 +56,8 @@ export declare type ClientOptionsForTestEnv = Omit<ClientOptions, 'namespace' |
|
|
|
55
56
|
/**
|
|
56
57
|
* Options for {@link TestWorkflowEnvironment.create}
|
|
57
58
|
*/
|
|
58
|
-
declare type TestWorkflowEnvironmentOptions = {
|
|
59
|
-
server
|
|
59
|
+
export declare type TestWorkflowEnvironmentOptions = {
|
|
60
|
+
server: EphemeralServerConfig;
|
|
60
61
|
client?: ClientOptionsForTestEnv;
|
|
61
62
|
};
|
|
62
63
|
/**
|
|
@@ -70,7 +71,7 @@ export declare type TimeSkippingTestWorkflowEnvironmentOptions = {
|
|
|
70
71
|
* Options for {@link TestWorkflowEnvironment.createLocal}
|
|
71
72
|
*/
|
|
72
73
|
export declare type LocalTestWorkflowEnvironmentOptions = {
|
|
73
|
-
server?: Omit<
|
|
74
|
+
server?: Omit<DevServerConfig, 'type'>;
|
|
74
75
|
client?: ClientOptionsForTestEnv;
|
|
75
76
|
};
|
|
76
77
|
export declare type TestWorkflowEnvironmentOptionsWithDefaults = Required<TestWorkflowEnvironmentOptions>;
|
|
@@ -114,7 +115,7 @@ export declare class TestWorkflowEnvironment {
|
|
|
114
115
|
* Use this connection when creating Workers for testing.
|
|
115
116
|
*/
|
|
116
117
|
readonly nativeConnection: NativeConnection;
|
|
117
|
-
protected constructor(options: TestWorkflowEnvironmentOptionsWithDefaults, supportsTimeSkipping: boolean, server: EphemeralServer, connection: Connection, nativeConnection: NativeConnection);
|
|
118
|
+
protected constructor(options: TestWorkflowEnvironmentOptionsWithDefaults, supportsTimeSkipping: boolean, server: EphemeralServer, connection: Connection, nativeConnection: NativeConnection, namespace: string | undefined);
|
|
118
119
|
/**
|
|
119
120
|
* Start a time skipping workflow environment.
|
|
120
121
|
*
|
|
@@ -143,20 +144,19 @@ export declare class TestWorkflowEnvironment {
|
|
|
143
144
|
* {@link createTimeSkipping} does. {@link supportsTimeSkipping} will always return `false` for this environment.
|
|
144
145
|
* {@link sleep} will sleep the actual amount of time and {@link currentTimeMs} will return the current time.
|
|
145
146
|
*
|
|
146
|
-
*
|
|
147
|
-
* for Temporal
|
|
148
|
-
*
|
|
149
|
-
* `'cached-download'`.
|
|
147
|
+
* This local environment will be powered by [Temporal CLI](https://github.com/temporalio/cli), which is a
|
|
148
|
+
* self-contained executable for Temporal. By default, Temporal's database will not be persisted to disk, and no UI
|
|
149
|
+
* will be started.
|
|
150
150
|
*
|
|
151
|
-
*
|
|
151
|
+
* The CLI executable will be downloaded and cached to a temporary directory. See
|
|
152
|
+
* {@link LocalTestWorkflowEnvironmentOptions.server.executable.type} if you'd prefer to provide the CLI executable
|
|
153
|
+
* yourself.
|
|
152
154
|
*/
|
|
153
155
|
static createLocal(opts?: LocalTestWorkflowEnvironmentOptions): Promise<TestWorkflowEnvironment>;
|
|
154
156
|
/**
|
|
155
157
|
* Create a new test environment
|
|
156
|
-
*
|
|
157
|
-
* @deprecated - use {@link createTimeSkipping} or {@link createLocal}
|
|
158
158
|
*/
|
|
159
|
-
static create
|
|
159
|
+
private static create;
|
|
160
160
|
/**
|
|
161
161
|
* Kill the test server process and close the connection to it
|
|
162
162
|
*/
|
package/lib/index.js
CHANGED
|
@@ -36,9 +36,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
36
36
|
};
|
|
37
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
38
|
exports.MockActivityEnvironment = exports.defaultActivityInfo = exports.TestWorkflowEnvironment = exports.workflowInterceptorModules = exports.TimeSkippingWorkflowClient = void 0;
|
|
39
|
-
|
|
40
|
-
const
|
|
41
|
-
const
|
|
39
|
+
require("abort-controller/polyfill"); // eslint-disable-line import/no-unassigned-import
|
|
40
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
41
|
+
const node_events_1 = __importDefault(require("node:events"));
|
|
42
42
|
const ms_1 = __importDefault(require("ms"));
|
|
43
43
|
const activity = __importStar(require("@temporalio/activity"));
|
|
44
44
|
const client_1 = require("@temporalio/client");
|
|
@@ -103,12 +103,9 @@ class TestEnvClient extends client_1.Client {
|
|
|
103
103
|
* Contains a single interceptor for transforming `AssertionError`s into non
|
|
104
104
|
* retryable `ApplicationFailure`s.
|
|
105
105
|
*/
|
|
106
|
-
exports.workflowInterceptorModules = [
|
|
106
|
+
exports.workflowInterceptorModules = [node_path_1.default.join(__dirname, 'assert-to-failure-interceptor')];
|
|
107
107
|
function addDefaults(opts) {
|
|
108
108
|
return {
|
|
109
|
-
server: {
|
|
110
|
-
type: 'time-skipping',
|
|
111
|
-
},
|
|
112
109
|
client: {},
|
|
113
110
|
...opts,
|
|
114
111
|
};
|
|
@@ -120,7 +117,7 @@ function addDefaults(opts) {
|
|
|
120
117
|
* By default, the Java test server is used which supports time skipping.
|
|
121
118
|
*/
|
|
122
119
|
class TestWorkflowEnvironment {
|
|
123
|
-
constructor(options, supportsTimeSkipping, server, connection, nativeConnection) {
|
|
120
|
+
constructor(options, supportsTimeSkipping, server, connection, nativeConnection, namespace) {
|
|
124
121
|
this.options = options;
|
|
125
122
|
this.supportsTimeSkipping = supportsTimeSkipping;
|
|
126
123
|
this.server = server;
|
|
@@ -178,11 +175,11 @@ class TestWorkflowEnvironment {
|
|
|
178
175
|
};
|
|
179
176
|
this.connection = connection;
|
|
180
177
|
this.nativeConnection = nativeConnection;
|
|
181
|
-
this.namespace =
|
|
178
|
+
this.namespace = namespace;
|
|
182
179
|
this.client = new TestEnvClient({
|
|
183
180
|
connection,
|
|
184
181
|
namespace: this.namespace,
|
|
185
|
-
enableTimeSkipping:
|
|
182
|
+
enableTimeSkipping: supportsTimeSkipping,
|
|
186
183
|
...options.client,
|
|
187
184
|
});
|
|
188
185
|
// eslint-disable-next-line deprecation/deprecation
|
|
@@ -211,8 +208,11 @@ class TestWorkflowEnvironment {
|
|
|
211
208
|
* In the future, the test server implementation may be changed to another implementation.
|
|
212
209
|
*/
|
|
213
210
|
static async createTimeSkipping(opts) {
|
|
214
|
-
|
|
215
|
-
|
|
211
|
+
return await this.create({
|
|
212
|
+
server: { type: 'time-skipping', ...opts?.server },
|
|
213
|
+
client: opts?.client,
|
|
214
|
+
supportsTimeSkipping: true,
|
|
215
|
+
});
|
|
216
216
|
}
|
|
217
217
|
/**
|
|
218
218
|
* Start a full Temporal server locally, downloading if necessary.
|
|
@@ -221,29 +221,34 @@ class TestWorkflowEnvironment {
|
|
|
221
221
|
* {@link createTimeSkipping} does. {@link supportsTimeSkipping} will always return `false` for this environment.
|
|
222
222
|
* {@link sleep} will sleep the actual amount of time and {@link currentTimeMs} will return the current time.
|
|
223
223
|
*
|
|
224
|
-
*
|
|
225
|
-
* for Temporal
|
|
226
|
-
*
|
|
227
|
-
* `'cached-download'`.
|
|
224
|
+
* This local environment will be powered by [Temporal CLI](https://github.com/temporalio/cli), which is a
|
|
225
|
+
* self-contained executable for Temporal. By default, Temporal's database will not be persisted to disk, and no UI
|
|
226
|
+
* will be started.
|
|
228
227
|
*
|
|
229
|
-
*
|
|
228
|
+
* The CLI executable will be downloaded and cached to a temporary directory. See
|
|
229
|
+
* {@link LocalTestWorkflowEnvironmentOptions.server.executable.type} if you'd prefer to provide the CLI executable
|
|
230
|
+
* yourself.
|
|
230
231
|
*/
|
|
231
232
|
static async createLocal(opts) {
|
|
232
233
|
// eslint-disable-next-line deprecation/deprecation
|
|
233
|
-
return await this.create({
|
|
234
|
+
return await this.create({
|
|
235
|
+
server: { type: 'dev-server', ...opts?.server },
|
|
236
|
+
client: opts?.client,
|
|
237
|
+
namespace: opts?.server?.namespace,
|
|
238
|
+
supportsTimeSkipping: false,
|
|
239
|
+
});
|
|
234
240
|
}
|
|
235
241
|
/**
|
|
236
242
|
* Create a new test environment
|
|
237
|
-
*
|
|
238
|
-
* @deprecated - use {@link createTimeSkipping} or {@link createLocal}
|
|
239
243
|
*/
|
|
240
244
|
static async create(opts) {
|
|
241
|
-
const
|
|
245
|
+
const { supportsTimeSkipping, namespace, ...rest } = opts;
|
|
246
|
+
const optsWithDefaults = addDefaults((0, internal_non_workflow_1.filterNullAndUndefined)(rest));
|
|
242
247
|
const server = await worker_1.Runtime.instance().createEphemeralServer(optsWithDefaults.server);
|
|
243
248
|
const address = (0, core_bridge_1.getEphemeralServerTarget)(server);
|
|
244
249
|
const nativeConnection = await worker_1.NativeConnection.connect({ address });
|
|
245
250
|
const connection = await connection_1.Connection.connect({ address });
|
|
246
|
-
return new this(optsWithDefaults,
|
|
251
|
+
return new this(optsWithDefaults, supportsTimeSkipping, server, connection, nativeConnection, namespace);
|
|
247
252
|
}
|
|
248
253
|
/**
|
|
249
254
|
* Kill the test server process and close the connection to it
|
|
@@ -296,11 +301,11 @@ exports.defaultActivityInfo = {
|
|
|
296
301
|
* Mocks Activity {@link Context | activity.Context} and exposes hooks for
|
|
297
302
|
* cancellation and heartbeats.
|
|
298
303
|
*/
|
|
299
|
-
class MockActivityEnvironment extends
|
|
304
|
+
class MockActivityEnvironment extends node_events_1.default.EventEmitter {
|
|
300
305
|
constructor(info) {
|
|
301
306
|
super();
|
|
302
307
|
this.cancel = () => undefined;
|
|
303
|
-
const abortController = new
|
|
308
|
+
const abortController = new AbortController();
|
|
304
309
|
const promise = new Promise((_, reject) => {
|
|
305
310
|
this.cancel = (reason) => {
|
|
306
311
|
abortController.abort();
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,qCAAmC,CAAC,kDAAkD;A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C,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.
|
|
3
|
+
"version": "1.7.0",
|
|
4
4
|
"description": "Temporal.io SDK Testing sub-package",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
@@ -12,20 +12,25 @@
|
|
|
12
12
|
"author": "Temporal Technologies Inc. <sdk@temporal.io>",
|
|
13
13
|
"license": "MIT",
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@grpc/grpc-js": "
|
|
16
|
-
"@temporalio/activity": "
|
|
17
|
-
"@temporalio/client": "
|
|
18
|
-
"@temporalio/common": "
|
|
19
|
-
"@temporalio/core-bridge": "
|
|
20
|
-
"@temporalio/proto": "
|
|
21
|
-
"@temporalio/worker": "
|
|
22
|
-
"@temporalio/workflow": "
|
|
15
|
+
"@grpc/grpc-js": "~1.7.3",
|
|
16
|
+
"@temporalio/activity": "1.7.0",
|
|
17
|
+
"@temporalio/client": "1.7.0",
|
|
18
|
+
"@temporalio/common": "1.7.0",
|
|
19
|
+
"@temporalio/core-bridge": "1.7.0",
|
|
20
|
+
"@temporalio/proto": "1.7.0",
|
|
21
|
+
"@temporalio/worker": "1.7.0",
|
|
22
|
+
"@temporalio/workflow": "1.7.0",
|
|
23
23
|
"abort-controller": "^3.0.0",
|
|
24
24
|
"ms": "^2.1.3"
|
|
25
25
|
},
|
|
26
26
|
"bugs": {
|
|
27
27
|
"url": "https://github.com/temporalio/sdk-typescript/issues"
|
|
28
28
|
},
|
|
29
|
+
"repository": {
|
|
30
|
+
"type": "git",
|
|
31
|
+
"url": "git+https://github.com/temporalio/sdk-typescript.git",
|
|
32
|
+
"directory": "packages/testing"
|
|
33
|
+
},
|
|
29
34
|
"homepage": "https://github.com/temporalio/sdk-typescript/tree/main/packages/testing",
|
|
30
35
|
"files": [
|
|
31
36
|
"lib",
|
|
@@ -34,5 +39,5 @@
|
|
|
34
39
|
"publishConfig": {
|
|
35
40
|
"access": "public"
|
|
36
41
|
},
|
|
37
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "2b32bac62f879b35238b487d3aaed093a1e449a7"
|
|
38
43
|
}
|
|
@@ -19,6 +19,7 @@ export function interceptors(): WorkflowInterceptors {
|
|
|
19
19
|
appErr.stack = err.stack;
|
|
20
20
|
throw appErr;
|
|
21
21
|
}
|
|
22
|
+
throw err;
|
|
22
23
|
}
|
|
23
24
|
},
|
|
24
25
|
async execute(input, next) {
|
|
@@ -30,6 +31,7 @@ export function interceptors(): WorkflowInterceptors {
|
|
|
30
31
|
appErr.stack = err.stack;
|
|
31
32
|
throw appErr;
|
|
32
33
|
}
|
|
34
|
+
throw err;
|
|
33
35
|
}
|
|
34
36
|
},
|
|
35
37
|
},
|
package/src/connection.ts
CHANGED
|
@@ -24,6 +24,7 @@ export class Connection extends BaseConnection {
|
|
|
24
24
|
client: ctorOptions.client,
|
|
25
25
|
callContextStorage: ctorOptions.callContextStorage,
|
|
26
26
|
interceptors: ctorOptions.options.interceptors,
|
|
27
|
+
staticMetadata: ctorOptions.options.metadata,
|
|
27
28
|
});
|
|
28
29
|
const testService = TestService.create(rpcImpl, false, false);
|
|
29
30
|
return { ...ctorOptions, testService };
|
package/src/index.ts
CHANGED
|
@@ -8,9 +8,9 @@
|
|
|
8
8
|
* @module
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import
|
|
11
|
+
import 'abort-controller/polyfill'; // eslint-disable-line import/no-unassigned-import
|
|
12
|
+
import path from 'node:path';
|
|
13
|
+
import events from 'node:events';
|
|
14
14
|
import ms from 'ms';
|
|
15
15
|
import * as activity from '@temporalio/activity';
|
|
16
16
|
import {
|
|
@@ -29,13 +29,13 @@ import {
|
|
|
29
29
|
EphemeralServer,
|
|
30
30
|
EphemeralServerConfig,
|
|
31
31
|
getEphemeralServerTarget,
|
|
32
|
-
|
|
32
|
+
DevServerConfig,
|
|
33
33
|
TimeSkippingServerConfig,
|
|
34
34
|
} from '@temporalio/core-bridge';
|
|
35
35
|
import { filterNullAndUndefined } from '@temporalio/common/lib/internal-non-workflow';
|
|
36
36
|
import { Connection, TestService } from './connection';
|
|
37
37
|
|
|
38
|
-
export { TimeSkippingServerConfig,
|
|
38
|
+
export { TimeSkippingServerConfig, DevServerConfig, EphemeralServerExecutable } from '@temporalio/core-bridge';
|
|
39
39
|
export { EphemeralServerConfig };
|
|
40
40
|
|
|
41
41
|
export interface TimeSkippingWorkflowClientOptions extends WorkflowClientOptions {
|
|
@@ -121,8 +121,8 @@ export type ClientOptionsForTestEnv = Omit<ClientOptions, 'namespace' | 'connect
|
|
|
121
121
|
/**
|
|
122
122
|
* Options for {@link TestWorkflowEnvironment.create}
|
|
123
123
|
*/
|
|
124
|
-
type TestWorkflowEnvironmentOptions = {
|
|
125
|
-
server
|
|
124
|
+
export type TestWorkflowEnvironmentOptions = {
|
|
125
|
+
server: EphemeralServerConfig;
|
|
126
126
|
client?: ClientOptionsForTestEnv;
|
|
127
127
|
};
|
|
128
128
|
|
|
@@ -138,7 +138,7 @@ export type TimeSkippingTestWorkflowEnvironmentOptions = {
|
|
|
138
138
|
* Options for {@link TestWorkflowEnvironment.createLocal}
|
|
139
139
|
*/
|
|
140
140
|
export type LocalTestWorkflowEnvironmentOptions = {
|
|
141
|
-
server?: Omit<
|
|
141
|
+
server?: Omit<DevServerConfig, 'type'>;
|
|
142
142
|
client?: ClientOptionsForTestEnv;
|
|
143
143
|
};
|
|
144
144
|
|
|
@@ -146,9 +146,6 @@ export type TestWorkflowEnvironmentOptionsWithDefaults = Required<TestWorkflowEn
|
|
|
146
146
|
|
|
147
147
|
function addDefaults(opts: TestWorkflowEnvironmentOptions): TestWorkflowEnvironmentOptionsWithDefaults {
|
|
148
148
|
return {
|
|
149
|
-
server: {
|
|
150
|
-
type: 'time-skipping',
|
|
151
|
-
},
|
|
152
149
|
client: {},
|
|
153
150
|
...opts,
|
|
154
151
|
};
|
|
@@ -201,15 +198,16 @@ export class TestWorkflowEnvironment {
|
|
|
201
198
|
public readonly supportsTimeSkipping: boolean,
|
|
202
199
|
protected readonly server: EphemeralServer,
|
|
203
200
|
connection: Connection,
|
|
204
|
-
nativeConnection: NativeConnection
|
|
201
|
+
nativeConnection: NativeConnection,
|
|
202
|
+
namespace: string | undefined
|
|
205
203
|
) {
|
|
206
204
|
this.connection = connection;
|
|
207
205
|
this.nativeConnection = nativeConnection;
|
|
208
|
-
this.namespace =
|
|
206
|
+
this.namespace = namespace;
|
|
209
207
|
this.client = new TestEnvClient({
|
|
210
208
|
connection,
|
|
211
209
|
namespace: this.namespace,
|
|
212
|
-
enableTimeSkipping:
|
|
210
|
+
enableTimeSkipping: supportsTimeSkipping,
|
|
213
211
|
...options.client,
|
|
214
212
|
});
|
|
215
213
|
// eslint-disable-next-line deprecation/deprecation
|
|
@@ -239,8 +237,11 @@ export class TestWorkflowEnvironment {
|
|
|
239
237
|
* In the future, the test server implementation may be changed to another implementation.
|
|
240
238
|
*/
|
|
241
239
|
static async createTimeSkipping(opts?: TimeSkippingTestWorkflowEnvironmentOptions): Promise<TestWorkflowEnvironment> {
|
|
242
|
-
|
|
243
|
-
|
|
240
|
+
return await this.create({
|
|
241
|
+
server: { type: 'time-skipping', ...opts?.server },
|
|
242
|
+
client: opts?.client,
|
|
243
|
+
supportsTimeSkipping: true,
|
|
244
|
+
});
|
|
244
245
|
}
|
|
245
246
|
|
|
246
247
|
/**
|
|
@@ -250,38 +251,42 @@ export class TestWorkflowEnvironment {
|
|
|
250
251
|
* {@link createTimeSkipping} does. {@link supportsTimeSkipping} will always return `false` for this environment.
|
|
251
252
|
* {@link sleep} will sleep the actual amount of time and {@link currentTimeMs} will return the current time.
|
|
252
253
|
*
|
|
253
|
-
*
|
|
254
|
-
* for Temporal
|
|
255
|
-
*
|
|
256
|
-
* `'cached-download'`.
|
|
254
|
+
* This local environment will be powered by [Temporal CLI](https://github.com/temporalio/cli), which is a
|
|
255
|
+
* self-contained executable for Temporal. By default, Temporal's database will not be persisted to disk, and no UI
|
|
256
|
+
* will be started.
|
|
257
257
|
*
|
|
258
|
-
*
|
|
258
|
+
* The CLI executable will be downloaded and cached to a temporary directory. See
|
|
259
|
+
* {@link LocalTestWorkflowEnvironmentOptions.server.executable.type} if you'd prefer to provide the CLI executable
|
|
260
|
+
* yourself.
|
|
259
261
|
*/
|
|
260
262
|
static async createLocal(opts?: LocalTestWorkflowEnvironmentOptions): Promise<TestWorkflowEnvironment> {
|
|
261
263
|
// eslint-disable-next-line deprecation/deprecation
|
|
262
|
-
return await this.create({
|
|
264
|
+
return await this.create({
|
|
265
|
+
server: { type: 'dev-server', ...opts?.server },
|
|
266
|
+
client: opts?.client,
|
|
267
|
+
namespace: opts?.server?.namespace,
|
|
268
|
+
supportsTimeSkipping: false,
|
|
269
|
+
});
|
|
263
270
|
}
|
|
264
271
|
|
|
265
272
|
/**
|
|
266
273
|
* Create a new test environment
|
|
267
|
-
*
|
|
268
|
-
* @deprecated - use {@link createTimeSkipping} or {@link createLocal}
|
|
269
274
|
*/
|
|
270
|
-
static async create(
|
|
271
|
-
|
|
275
|
+
private static async create(
|
|
276
|
+
opts: TestWorkflowEnvironmentOptions & {
|
|
277
|
+
supportsTimeSkipping: boolean;
|
|
278
|
+
namespace?: string;
|
|
279
|
+
}
|
|
280
|
+
): Promise<TestWorkflowEnvironment> {
|
|
281
|
+
const { supportsTimeSkipping, namespace, ...rest } = opts;
|
|
282
|
+
const optsWithDefaults = addDefaults(filterNullAndUndefined(rest));
|
|
272
283
|
const server = await Runtime.instance().createEphemeralServer(optsWithDefaults.server);
|
|
273
284
|
const address = getEphemeralServerTarget(server);
|
|
274
285
|
|
|
275
286
|
const nativeConnection = await NativeConnection.connect({ address });
|
|
276
287
|
const connection = await Connection.connect({ address });
|
|
277
288
|
|
|
278
|
-
return new this(
|
|
279
|
-
optsWithDefaults,
|
|
280
|
-
optsWithDefaults.server.type === 'time-skipping',
|
|
281
|
-
server,
|
|
282
|
-
connection,
|
|
283
|
-
nativeConnection
|
|
284
|
-
);
|
|
289
|
+
return new this(optsWithDefaults, supportsTimeSkipping, server, connection, nativeConnection, namespace);
|
|
285
290
|
}
|
|
286
291
|
|
|
287
292
|
/**
|