@temporalio/testing 1.11.8 → 1.12.0-rc.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/client.d.ts +39 -0
- package/lib/client.js +58 -0
- package/lib/client.js.map +1 -0
- package/lib/connection.js +1 -0
- package/lib/connection.js.map +1 -1
- package/lib/ephemeral-server.d.ts +109 -0
- package/lib/ephemeral-server.js +62 -0
- package/lib/ephemeral-server.js.map +1 -0
- package/lib/index.d.ts +4 -242
- package/lib/index.js +9 -300
- package/lib/index.js.map +1 -1
- package/lib/mocking-activity-environment.d.ts +35 -0
- package/lib/mocking-activity-environment.js +71 -0
- package/lib/mocking-activity-environment.js.map +1 -0
- package/lib/pkg.d.ts +5 -0
- package/lib/pkg.js +12 -0
- package/lib/pkg.js.map +1 -0
- package/lib/testing-workflow-environment.d.ts +205 -0
- package/lib/testing-workflow-environment.js +278 -0
- package/lib/testing-workflow-environment.js.map +1 -0
- package/package.json +12 -9
- package/src/client.ts +81 -0
- package/src/ephemeral-server.ts +185 -0
- package/src/index.ts +27 -439
- package/src/mocking-activity-environment.ts +90 -0
- package/src/pkg.ts +7 -0
- package/src/testing-workflow-environment.ts +337 -0
package/lib/client.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import 'abort-controller/polyfill';
|
|
2
|
+
import { Client, ClientOptions, WorkflowClient, WorkflowClientOptions, WorkflowResultOptions } from '@temporalio/client';
|
|
3
|
+
import { Connection, TestService } from './connection';
|
|
4
|
+
export interface TimeSkippingWorkflowClientOptions extends WorkflowClientOptions {
|
|
5
|
+
connection: Connection;
|
|
6
|
+
enableTimeSkipping: boolean;
|
|
7
|
+
}
|
|
8
|
+
export interface TestEnvClientOptions extends ClientOptions {
|
|
9
|
+
connection: Connection;
|
|
10
|
+
enableTimeSkipping: boolean;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Subset of the "normal" client options that are used to create a client for the test environment.
|
|
14
|
+
*/
|
|
15
|
+
export type ClientOptionsForTestEnv = Omit<ClientOptions, 'namespace' | 'connection'>;
|
|
16
|
+
/**
|
|
17
|
+
* A client with the exact same API as the "normal" client with 1 exception,
|
|
18
|
+
* When this client waits on a Workflow's result, it will enable time skipping
|
|
19
|
+
* in the test server.
|
|
20
|
+
*/
|
|
21
|
+
export declare class TimeSkippingWorkflowClient extends WorkflowClient {
|
|
22
|
+
protected readonly testService: TestService;
|
|
23
|
+
protected readonly enableTimeSkipping: boolean;
|
|
24
|
+
constructor(options: TimeSkippingWorkflowClientOptions);
|
|
25
|
+
/**
|
|
26
|
+
* Gets the result of a Workflow execution.
|
|
27
|
+
*
|
|
28
|
+
* @see {@link WorkflowClient.result}
|
|
29
|
+
*/
|
|
30
|
+
result<T>(workflowId: string, runId?: string | undefined, opts?: WorkflowResultOptions | undefined): Promise<T>;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* A client with the exact same API as the "normal" client with one exception:
|
|
34
|
+
* when `TestEnvClient.workflow` (an instance of {@link TimeSkippingWorkflowClient}) waits on a Workflow's result, it will enable time skipping
|
|
35
|
+
* in the Test Server.
|
|
36
|
+
*/
|
|
37
|
+
export declare class TestEnvClient extends Client {
|
|
38
|
+
constructor(options: TestEnvClientOptions);
|
|
39
|
+
}
|
package/lib/client.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TestEnvClient = exports.TimeSkippingWorkflowClient = void 0;
|
|
4
|
+
require("abort-controller/polyfill"); // eslint-disable-line import/no-unassigned-import
|
|
5
|
+
const client_1 = require("@temporalio/client");
|
|
6
|
+
/**
|
|
7
|
+
* A client with the exact same API as the "normal" client with 1 exception,
|
|
8
|
+
* When this client waits on a Workflow's result, it will enable time skipping
|
|
9
|
+
* in the test server.
|
|
10
|
+
*/
|
|
11
|
+
class TimeSkippingWorkflowClient extends client_1.WorkflowClient {
|
|
12
|
+
testService;
|
|
13
|
+
enableTimeSkipping;
|
|
14
|
+
constructor(options) {
|
|
15
|
+
super(options);
|
|
16
|
+
this.enableTimeSkipping = options.enableTimeSkipping;
|
|
17
|
+
this.testService = options.connection.testService;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Gets the result of a Workflow execution.
|
|
21
|
+
*
|
|
22
|
+
* @see {@link WorkflowClient.result}
|
|
23
|
+
*/
|
|
24
|
+
async result(workflowId, runId, opts) {
|
|
25
|
+
if (this.enableTimeSkipping) {
|
|
26
|
+
await this.testService.unlockTimeSkipping({});
|
|
27
|
+
try {
|
|
28
|
+
return await super.result(workflowId, runId, opts);
|
|
29
|
+
}
|
|
30
|
+
finally {
|
|
31
|
+
await this.testService.lockTimeSkipping({});
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
return await super.result(workflowId, runId, opts);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
exports.TimeSkippingWorkflowClient = TimeSkippingWorkflowClient;
|
|
40
|
+
/**
|
|
41
|
+
* A client with the exact same API as the "normal" client with one exception:
|
|
42
|
+
* when `TestEnvClient.workflow` (an instance of {@link TimeSkippingWorkflowClient}) waits on a Workflow's result, it will enable time skipping
|
|
43
|
+
* in the Test Server.
|
|
44
|
+
*/
|
|
45
|
+
class TestEnvClient extends client_1.Client {
|
|
46
|
+
constructor(options) {
|
|
47
|
+
super(options);
|
|
48
|
+
// Recreate the client (this isn't optimal but it's better than adding public methods just for testing).
|
|
49
|
+
// NOTE: we cast to "any" to work around `workflow` being a readonly attribute.
|
|
50
|
+
this.workflow = new TimeSkippingWorkflowClient({
|
|
51
|
+
...this.workflow.options,
|
|
52
|
+
connection: options.connection,
|
|
53
|
+
enableTimeSkipping: options.enableTimeSkipping,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
exports.TestEnvClient = TestEnvClient;
|
|
58
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":";;;AAAA,qCAAmC,CAAC,kDAAkD;AACtF,+CAM4B;AAkB5B;;;;GAIG;AACH,MAAa,0BAA2B,SAAQ,uBAAc;IACzC,WAAW,CAAc;IACzB,kBAAkB,CAAU;IAE/C,YAAY,OAA0C;QACpD,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,kBAAkB,GAAG,OAAO,CAAC,kBAAkB,CAAC;QACrD,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC;IACpD,CAAC;IAED;;;;OAIG;IACM,KAAK,CAAC,MAAM,CACnB,UAAkB,EAClB,KAA0B,EAC1B,IAAwC;QAExC,IAAI,IAAI,CAAC,kBAAkB,EAAE,CAAC;YAC5B,MAAM,IAAI,CAAC,WAAW,CAAC,kBAAkB,CAAC,EAAE,CAAC,CAAC;YAC9C,IAAI,CAAC;gBACH,OAAO,MAAM,KAAK,CAAC,MAAM,CAAC,UAAU,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;YACrD,CAAC;oBAAS,CAAC;gBACT,MAAM,IAAI,CAAC,WAAW,CAAC,gBAAgB,CAAC,EAAE,CAAC,CAAC;YAC9C,CAAC;QACH,CAAC;aAAM,CAAC;YACN,OAAO,MAAM,KAAK,CAAC,MAAM,CAAC,UAAU,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;QACrD,CAAC;IACH,CAAC;CACF;AA/BD,gEA+BC;AAED;;;;GAIG;AACH,MAAa,aAAc,SAAQ,eAAM;IACvC,YAAY,OAA6B;QACvC,KAAK,CAAC,OAAO,CAAC,CAAC;QAEf,wGAAwG;QACxG,+EAA+E;QAC9E,IAAY,CAAC,QAAQ,GAAG,IAAI,0BAA0B,CAAC;YACtD,GAAG,IAAI,CAAC,QAAQ,CAAC,OAAO;YACxB,UAAU,EAAE,OAAO,CAAC,UAAU;YAC9B,kBAAkB,EAAE,OAAO,CAAC,kBAAkB;SAC/C,CAAC,CAAC;IACL,CAAC;CACF;AAZD,sCAYC"}
|
package/lib/connection.js
CHANGED
|
@@ -8,6 +8,7 @@ exports.TestService = proto_1.temporal.api.testservice.v1.TestService;
|
|
|
8
8
|
* A Connection class that can be used to interact with both the test server's TestService and WorkflowService
|
|
9
9
|
*/
|
|
10
10
|
class Connection extends client_1.Connection {
|
|
11
|
+
testService;
|
|
11
12
|
static createCtorOptions(options) {
|
|
12
13
|
const ctorOptions = client_1.Connection.createCtorOptions(options);
|
|
13
14
|
const rpcImpl = this.generateRPCImplementation({
|
package/lib/connection.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connection.js","sourceRoot":"","sources":["../src/connection.ts"],"names":[],"mappings":";;;AAAA,+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,+CAAqF;AAErF,6CAA6C;AAG9B,mBAAW,GAAK,gBAAQ,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,aAAC;AAM3D;;GAEG;AACH,MAAa,UAAW,SAAQ,mBAAc;IAC5B,WAAW,CAAc;IAE/B,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;YAC5C,WAAW,EAAE,EAAE;SAChB,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;IAED,YAAsB,OAA8B;QAClD,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;IACzC,CAAC;CACF;AAhCD,gCAgCC"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import 'abort-controller/polyfill';
|
|
2
|
+
import { Duration, SearchAttributeType } from '@temporalio/common';
|
|
3
|
+
import { native } from '@temporalio/core-bridge';
|
|
4
|
+
import { SearchAttributeKey } from '@temporalio/common/lib/search-attributes';
|
|
5
|
+
/**
|
|
6
|
+
* Configuration for the Temporal CLI Dev Server.
|
|
7
|
+
*/
|
|
8
|
+
export interface DevServerConfig {
|
|
9
|
+
type: 'dev-server';
|
|
10
|
+
executable?: EphemeralServerExecutable;
|
|
11
|
+
/**
|
|
12
|
+
* Sqlite DB filename if persisting or non-persistent if none (default).
|
|
13
|
+
*/
|
|
14
|
+
dbFilename?: string;
|
|
15
|
+
/**
|
|
16
|
+
* Namespace to use - created at startup.
|
|
17
|
+
*
|
|
18
|
+
* @default "default"
|
|
19
|
+
*/
|
|
20
|
+
namespace?: string;
|
|
21
|
+
/**
|
|
22
|
+
* IP to bind to.
|
|
23
|
+
*
|
|
24
|
+
* @default localhost
|
|
25
|
+
*/
|
|
26
|
+
ip?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Port to listen on; defaults to find a random free port.
|
|
29
|
+
*/
|
|
30
|
+
port?: number;
|
|
31
|
+
/**
|
|
32
|
+
* Whether to enable the UI.
|
|
33
|
+
*
|
|
34
|
+
* @default true if `uiPort` is set; defaults to `false` otherwise.
|
|
35
|
+
*/
|
|
36
|
+
ui?: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Port to listen on for the UI; if `ui` is true, defaults to `port + 1000`.
|
|
39
|
+
*/
|
|
40
|
+
uiPort?: number;
|
|
41
|
+
/**
|
|
42
|
+
* Log format and level
|
|
43
|
+
* @default { format: "pretty", level" "warn" }
|
|
44
|
+
*/
|
|
45
|
+
log?: {
|
|
46
|
+
format: string;
|
|
47
|
+
level: string;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Extra args to pass to the executable command.
|
|
51
|
+
*
|
|
52
|
+
* Note that the Dev Server implementation may be changed to another one in the future. Therefore, there is no
|
|
53
|
+
* guarantee that Dev Server options, and particularly those provided through the `extraArgs` array, will continue to
|
|
54
|
+
* be supported in the future.
|
|
55
|
+
*/
|
|
56
|
+
extraArgs?: string[];
|
|
57
|
+
/**
|
|
58
|
+
* Search attributes to be registered with the dev server.
|
|
59
|
+
*/
|
|
60
|
+
searchAttributes?: SearchAttributeKey<SearchAttributeType>[];
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Configuration for the time-skipping test server.
|
|
64
|
+
*/
|
|
65
|
+
export interface TimeSkippingServerConfig {
|
|
66
|
+
type: 'time-skipping';
|
|
67
|
+
executable?: EphemeralServerExecutable;
|
|
68
|
+
/**
|
|
69
|
+
* Optional port to listen on, defaults to find a random free port.
|
|
70
|
+
*/
|
|
71
|
+
port?: number;
|
|
72
|
+
/**
|
|
73
|
+
* Extra args to pass to the executable command.
|
|
74
|
+
*
|
|
75
|
+
* Note that the Test Server implementation may be changed to another one in the future. Therefore, there is
|
|
76
|
+
* no guarantee that server options, and particularly those provided through the `extraArgs` array, will continue to
|
|
77
|
+
* be supported in the future.
|
|
78
|
+
*/
|
|
79
|
+
extraArgs?: string[];
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Which version of the executable to run.
|
|
83
|
+
*/
|
|
84
|
+
export type EphemeralServerExecutable = {
|
|
85
|
+
type: 'cached-download';
|
|
86
|
+
/**
|
|
87
|
+
* Download destination directory or the system's temp directory if none set.
|
|
88
|
+
*/
|
|
89
|
+
downloadDir?: string;
|
|
90
|
+
/**
|
|
91
|
+
* Optional version, can be set to a specific server release or "default" or "latest".
|
|
92
|
+
*
|
|
93
|
+
* At the time of writing the the server is released as part of the
|
|
94
|
+
* Java SDK - (https://github.com/temporalio/sdk-java/releases).
|
|
95
|
+
*
|
|
96
|
+
* @default "default" - get the best version for the current SDK version.
|
|
97
|
+
*/
|
|
98
|
+
version?: string;
|
|
99
|
+
/** How long to cache the download for. Default to 1 day. */
|
|
100
|
+
ttl?: Duration;
|
|
101
|
+
} | {
|
|
102
|
+
type: 'existing-path';
|
|
103
|
+
/** Path to executable */
|
|
104
|
+
path: string;
|
|
105
|
+
};
|
|
106
|
+
/**
|
|
107
|
+
* @internal
|
|
108
|
+
*/
|
|
109
|
+
export declare function toNativeEphemeralServerConfig(server: DevServerConfig | TimeSkippingServerConfig): native.EphemeralServerConfig;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.toNativeEphemeralServerConfig = toNativeEphemeralServerConfig;
|
|
7
|
+
require("abort-controller/polyfill"); // eslint-disable-line import/no-unassigned-import
|
|
8
|
+
const time_1 = require("@temporalio/common/lib/time");
|
|
9
|
+
const pkg_1 = __importDefault(require("./pkg"));
|
|
10
|
+
/**
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
function toNativeEphemeralServerConfig(server) {
|
|
14
|
+
switch (server.type) {
|
|
15
|
+
case 'dev-server':
|
|
16
|
+
return {
|
|
17
|
+
type: 'dev-server',
|
|
18
|
+
exe: toNativeEphemeralServerExecutableConfig(server.executable),
|
|
19
|
+
ip: server.ip ?? '127.0.0.1',
|
|
20
|
+
port: server.port ?? null,
|
|
21
|
+
ui: server.ui ?? false,
|
|
22
|
+
uiPort: server.uiPort ?? null,
|
|
23
|
+
namespace: server.namespace ?? 'default',
|
|
24
|
+
dbFilename: server.dbFilename ?? null,
|
|
25
|
+
log: server.log ?? { format: 'pretty', level: 'warn' },
|
|
26
|
+
extraArgs: server.extraArgs ?? [],
|
|
27
|
+
};
|
|
28
|
+
case 'time-skipping':
|
|
29
|
+
return {
|
|
30
|
+
type: 'time-skipping',
|
|
31
|
+
exe: toNativeEphemeralServerExecutableConfig(server.executable),
|
|
32
|
+
port: server.port ?? null,
|
|
33
|
+
extraArgs: server.extraArgs ?? [],
|
|
34
|
+
};
|
|
35
|
+
default:
|
|
36
|
+
throw new TypeError(`Unsupported server type: ${String(server.type)}`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* @internal
|
|
41
|
+
*/
|
|
42
|
+
function toNativeEphemeralServerExecutableConfig(executable = { type: 'cached-download' }) {
|
|
43
|
+
switch (executable.type) {
|
|
44
|
+
case 'cached-download':
|
|
45
|
+
return {
|
|
46
|
+
type: 'cached-download',
|
|
47
|
+
downloadDir: executable.downloadDir ?? null,
|
|
48
|
+
version: executable.version ?? 'default',
|
|
49
|
+
ttl: (0, time_1.msToNumber)(executable.ttl ?? '1d'),
|
|
50
|
+
sdkName: 'sdk-typescript',
|
|
51
|
+
sdkVersion: pkg_1.default.version,
|
|
52
|
+
};
|
|
53
|
+
case 'existing-path':
|
|
54
|
+
return {
|
|
55
|
+
type: 'existing-path',
|
|
56
|
+
path: executable.path,
|
|
57
|
+
};
|
|
58
|
+
default:
|
|
59
|
+
throw new TypeError(`Unsupported server executable type: ${String(executable.type)}`);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=ephemeral-server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ephemeral-server.js","sourceRoot":"","sources":["../src/ephemeral-server.ts"],"names":[],"mappings":";;;;;AA+HA,sEA6BC;AA5JD,qCAAmC,CAAC,kDAAkD;AAEtF,sDAAyD;AAGzD,gDAAwB;AAuHxB;;GAEG;AACH,SAAgB,6BAA6B,CAC3C,MAAkD;IAElD,QAAQ,MAAM,CAAC,IAAI,EAAE,CAAC;QACpB,KAAK,YAAY;YACf,OAAO;gBACL,IAAI,EAAE,YAAY;gBAClB,GAAG,EAAE,uCAAuC,CAAC,MAAM,CAAC,UAAU,CAAC;gBAC/D,EAAE,EAAE,MAAM,CAAC,EAAE,IAAI,WAAW;gBAC5B,IAAI,EAAE,MAAM,CAAC,IAAI,IAAI,IAAI;gBACzB,EAAE,EAAE,MAAM,CAAC,EAAE,IAAI,KAAK;gBACtB,MAAM,EAAE,MAAM,CAAC,MAAM,IAAI,IAAI;gBAC7B,SAAS,EAAE,MAAM,CAAC,SAAS,IAAI,SAAS;gBACxC,UAAU,EAAE,MAAM,CAAC,UAAU,IAAI,IAAI;gBACrC,GAAG,EAAE,MAAM,CAAC,GAAG,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE;gBACtD,SAAS,EAAE,MAAM,CAAC,SAAS,IAAI,EAAE;aAClC,CAAC;QAEJ,KAAK,eAAe;YAClB,OAAO;gBACL,IAAI,EAAE,eAAe;gBACrB,GAAG,EAAE,uCAAuC,CAAC,MAAM,CAAC,UAAU,CAAC;gBAC/D,IAAI,EAAE,MAAM,CAAC,IAAI,IAAI,IAAI;gBACzB,SAAS,EAAE,MAAM,CAAC,SAAS,IAAI,EAAE;aAClC,CAAC;QAEJ;YACE,MAAM,IAAI,SAAS,CAAC,4BAA4B,MAAM,CAAE,MAAc,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACpF,CAAC;AACH,CAAC;AAED;;GAEG;AACH,SAAS,uCAAuC,CAC9C,aAAwC,EAAE,IAAI,EAAE,iBAAiB,EAAE;IAEnE,QAAQ,UAAU,CAAC,IAAI,EAAE,CAAC;QACxB,KAAK,iBAAiB;YACpB,OAAO;gBACL,IAAI,EAAE,iBAAiB;gBACvB,WAAW,EAAE,UAAU,CAAC,WAAW,IAAI,IAAI;gBAC3C,OAAO,EAAE,UAAU,CAAC,OAAO,IAAI,SAAS;gBACxC,GAAG,EAAE,IAAA,iBAAU,EAAC,UAAU,CAAC,GAAG,IAAI,IAAI,CAAC;gBACvC,OAAO,EAAE,gBAAgB;gBACzB,UAAU,EAAE,aAAG,CAAC,OAAO;aACxB,CAAC;QAEJ,KAAK,eAAe;YAClB,OAAO;gBACL,IAAI,EAAE,eAAe;gBACrB,IAAI,EAAE,UAAU,CAAC,IAAI;aACtB,CAAC;QAEJ;YACE,MAAM,IAAI,SAAS,CAAC,uCAAuC,MAAM,CAAE,UAAkB,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACnG,CAAC;AACH,CAAC"}
|
package/lib/index.d.ts
CHANGED
|
@@ -7,40 +7,10 @@
|
|
|
7
7
|
*
|
|
8
8
|
* @module
|
|
9
9
|
*/
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
import { ActivityFunction, Duration, Logger } from '@temporalio/common';
|
|
15
|
-
import { ActivityInterceptorsFactory, NativeConnection } from '@temporalio/worker';
|
|
16
|
-
import { EphemeralServer, EphemeralServerConfig, DevServerConfig, TimeSkippingServerConfig } from '@temporalio/core-bridge';
|
|
17
|
-
import { Connection, TestService } from './connection';
|
|
18
|
-
export { TimeSkippingServerConfig, DevServerConfig, EphemeralServerExecutable } from '@temporalio/core-bridge';
|
|
19
|
-
export { EphemeralServerConfig };
|
|
20
|
-
export interface TimeSkippingWorkflowClientOptions extends WorkflowClientOptions {
|
|
21
|
-
connection: Connection;
|
|
22
|
-
enableTimeSkipping: boolean;
|
|
23
|
-
}
|
|
24
|
-
export interface TestEnvClientOptions extends ClientOptions {
|
|
25
|
-
connection: Connection;
|
|
26
|
-
enableTimeSkipping: boolean;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* A client with the exact same API as the "normal" client with 1 exception,
|
|
30
|
-
* When this client waits on a Workflow's result, it will enable time skipping
|
|
31
|
-
* in the test server.
|
|
32
|
-
*/
|
|
33
|
-
export declare class TimeSkippingWorkflowClient extends WorkflowClient {
|
|
34
|
-
protected readonly testService: TestService;
|
|
35
|
-
protected readonly enableTimeSkipping: boolean;
|
|
36
|
-
constructor(options: TimeSkippingWorkflowClientOptions);
|
|
37
|
-
/**
|
|
38
|
-
* Gets the result of a Workflow execution.
|
|
39
|
-
*
|
|
40
|
-
* @see {@link WorkflowClient.result}
|
|
41
|
-
*/
|
|
42
|
-
result<T>(workflowId: string, runId?: string | undefined, opts?: WorkflowResultOptions | undefined): Promise<T>;
|
|
43
|
-
}
|
|
10
|
+
export { TestWorkflowEnvironment, type LocalTestWorkflowEnvironmentOptions, type TimeSkippingTestWorkflowEnvironmentOptions, type ExistingServerTestWorkflowEnvironmentOptions, } from './testing-workflow-environment';
|
|
11
|
+
export { type DevServerConfig, type TimeSkippingServerConfig, type EphemeralServerExecutable, } from './ephemeral-server';
|
|
12
|
+
export { type ClientOptionsForTestEnv, type TestEnvClientOptions, type TimeSkippingWorkflowClientOptions, TestEnvClient, TimeSkippingWorkflowClient, } from './client';
|
|
13
|
+
export { type MockActivityEnvironmentOptions, MockActivityEnvironment, defaultActivityInfo, } from './mocking-activity-environment';
|
|
44
14
|
/**
|
|
45
15
|
* Convenience workflow interceptors
|
|
46
16
|
*
|
|
@@ -48,211 +18,3 @@ export declare class TimeSkippingWorkflowClient extends WorkflowClient {
|
|
|
48
18
|
* retryable `ApplicationFailure`s.
|
|
49
19
|
*/
|
|
50
20
|
export declare const workflowInterceptorModules: string[];
|
|
51
|
-
/**
|
|
52
|
-
* Subset of the "normal" client options that are used to create a client for the test environment.
|
|
53
|
-
*/
|
|
54
|
-
export type ClientOptionsForTestEnv = Omit<ClientOptions, 'namespace' | 'connection'>;
|
|
55
|
-
/**
|
|
56
|
-
* Options for {@link TestWorkflowEnvironment.create}
|
|
57
|
-
*/
|
|
58
|
-
export type TestWorkflowEnvironmentOptions = {
|
|
59
|
-
server: EphemeralServerConfig;
|
|
60
|
-
client?: ClientOptionsForTestEnv;
|
|
61
|
-
};
|
|
62
|
-
/**
|
|
63
|
-
* Options for {@link TestWorkflowEnvironment.createTimeSkipping}
|
|
64
|
-
*/
|
|
65
|
-
export type TimeSkippingTestWorkflowEnvironmentOptions = {
|
|
66
|
-
server?: Omit<TimeSkippingServerConfig, 'type'>;
|
|
67
|
-
client?: ClientOptionsForTestEnv;
|
|
68
|
-
};
|
|
69
|
-
/**
|
|
70
|
-
* Options for {@link TestWorkflowEnvironment.createLocal}
|
|
71
|
-
*/
|
|
72
|
-
export type LocalTestWorkflowEnvironmentOptions = {
|
|
73
|
-
server?: Omit<DevServerConfig, 'type'>;
|
|
74
|
-
client?: ClientOptionsForTestEnv;
|
|
75
|
-
};
|
|
76
|
-
export type TestWorkflowEnvironmentOptionsWithDefaults = Required<TestWorkflowEnvironmentOptions>;
|
|
77
|
-
/**
|
|
78
|
-
* An execution environment for running Workflow integration tests.
|
|
79
|
-
*
|
|
80
|
-
* Runs an external server.
|
|
81
|
-
* By default, the Java test server is used which supports time skipping.
|
|
82
|
-
*/
|
|
83
|
-
export declare class TestWorkflowEnvironment {
|
|
84
|
-
readonly options: TestWorkflowEnvironmentOptionsWithDefaults;
|
|
85
|
-
readonly supportsTimeSkipping: boolean;
|
|
86
|
-
protected readonly server: EphemeralServer;
|
|
87
|
-
/**
|
|
88
|
-
* Namespace used in this environment (taken from {@link TestWorkflowEnvironmentOptions})
|
|
89
|
-
*/
|
|
90
|
-
readonly namespace?: string;
|
|
91
|
-
/**
|
|
92
|
-
* Get an established {@link Connection} to the ephemeral server
|
|
93
|
-
*/
|
|
94
|
-
readonly connection: Connection;
|
|
95
|
-
/**
|
|
96
|
-
* A {@link TestEnvClient} for interacting with the ephemeral server
|
|
97
|
-
*/
|
|
98
|
-
readonly client: Client;
|
|
99
|
-
/**
|
|
100
|
-
* An {@link AsyncCompletionClient} for interacting with the test server
|
|
101
|
-
*
|
|
102
|
-
* @deprecated - use `client.activity` instead
|
|
103
|
-
*/
|
|
104
|
-
readonly asyncCompletionClient: AsyncCompletionClient;
|
|
105
|
-
/**
|
|
106
|
-
* A {@link TimeSkippingWorkflowClient} for interacting with the test server
|
|
107
|
-
*
|
|
108
|
-
* @deprecated - use `client.workflow` instead
|
|
109
|
-
*/
|
|
110
|
-
readonly workflowClient: WorkflowClient;
|
|
111
|
-
/**
|
|
112
|
-
* A {@link NativeConnection} for interacting with the test server.
|
|
113
|
-
*
|
|
114
|
-
* Use this connection when creating Workers for testing.
|
|
115
|
-
*/
|
|
116
|
-
readonly nativeConnection: NativeConnection;
|
|
117
|
-
protected constructor(options: TestWorkflowEnvironmentOptionsWithDefaults, supportsTimeSkipping: boolean, server: EphemeralServer, connection: Connection, nativeConnection: NativeConnection, namespace: string | undefined);
|
|
118
|
-
/**
|
|
119
|
-
* Start a time skipping workflow environment.
|
|
120
|
-
*
|
|
121
|
-
* This environment automatically skips to the next events in time when a workflow handle's `result` is awaited on
|
|
122
|
-
* (which includes {@link WorkflowClient.execute}). Before the result is awaited on, time can be manually skipped
|
|
123
|
-
* forward using {@link sleep}. The currently known time can be obtained via {@link currentTimeMs}.
|
|
124
|
-
*
|
|
125
|
-
* This environment will be powered by the Temporal Time Skipping Test Server (part of the [Java SDK](https://github.com/temporalio/sdk-java)).
|
|
126
|
-
* Note that the Time Skipping Test Server does not support full capabilities of the regular Temporal Server, and may
|
|
127
|
-
* occasionally present different behaviors. For general Workflow testing, it is generally preferable to use {@link createLocal}
|
|
128
|
-
* instead.
|
|
129
|
-
*
|
|
130
|
-
* Users can reuse this environment for testing multiple independent workflows, but not concurrently. Time skipping,
|
|
131
|
-
* which is automatically done when awaiting a workflow result and manually done on sleep, is global to the
|
|
132
|
-
* environment, not to the workflow under test. We highly recommend running tests serially when using a single
|
|
133
|
-
* environment or creating a separate environment per test.
|
|
134
|
-
*
|
|
135
|
-
* By default, the latest release of the Test Serveer will be downloaded and cached to a temporary directory
|
|
136
|
-
* (e.g. `$TMPDIR/temporal-test-server-sdk-typescript-*` or `%TEMP%/temporal-test-server-sdk-typescript-*.exe`). Note
|
|
137
|
-
* that existing cached binairies will be reused without validation that they are still up-to-date, until the SDK
|
|
138
|
-
* itself is updated. Alternatively, a specific version number of the Test Server may be provided, or the path to an
|
|
139
|
-
* existing Test Server binary may be supplied; see {@link LocalTestWorkflowEnvironmentOptions.server.executable}.
|
|
140
|
-
*
|
|
141
|
-
* Note that the Test Server implementation may be changed to another one in the future. Therefore, there is no
|
|
142
|
-
* guarantee that Test Server options, and particularly those provided through the `extraArgs` array, will continue to
|
|
143
|
-
* be supported in the future.
|
|
144
|
-
*
|
|
145
|
-
* IMPORTANT: At this time, the Time Skipping Test Server is not supported on ARM platforms. Execution on Apple
|
|
146
|
-
* silicon Macs will work if Rosetta 2 is installed.
|
|
147
|
-
*/
|
|
148
|
-
static createTimeSkipping(opts?: TimeSkippingTestWorkflowEnvironmentOptions): Promise<TestWorkflowEnvironment>;
|
|
149
|
-
/**
|
|
150
|
-
* Start a full Temporal server locally.
|
|
151
|
-
*
|
|
152
|
-
* This environment is good for testing full server capabilities, but does not support time skipping like
|
|
153
|
-
* {@link createTimeSkipping} does. {@link supportsTimeSkipping} will always return `false` for this environment.
|
|
154
|
-
* {@link sleep} will sleep the actual amount of time and {@link currentTimeMs} will return the current time.
|
|
155
|
-
*
|
|
156
|
-
* This local environment will be powered by [Temporal CLI](https://github.com/temporalio/cli), which is a
|
|
157
|
-
* self-contained executable for Temporal. By default, Temporal's database will not be persisted to disk, and no UI
|
|
158
|
-
* will be launched.
|
|
159
|
-
*
|
|
160
|
-
* By default, the latest release of the CLI will be downloaded and cached to a temporary directory
|
|
161
|
-
* (e.g. `$TMPDIR/temporal-sdk-typescript-*` or `%TEMP%/temporal-sdk-typescript-*.exe`). Note that existing cached
|
|
162
|
-
* binairies will be reused without validation that they are still up-to-date, until the SDK itself is updated.
|
|
163
|
-
* Alternatively, a specific version number of the CLI may be provided, or the path to an existing CLI binary may be
|
|
164
|
-
* supplied; see {@link LocalTestWorkflowEnvironmentOptions.server.executable}.
|
|
165
|
-
*
|
|
166
|
-
* Note that the Dev Server implementation may be changed to another one in the future. Therefore, there is no
|
|
167
|
-
* guarantee that Dev Server options, and particularly those provided through the `extraArgs` array, will continue to
|
|
168
|
-
* be supported in the future.
|
|
169
|
-
*/
|
|
170
|
-
static createLocal(opts?: LocalTestWorkflowEnvironmentOptions): Promise<TestWorkflowEnvironment>;
|
|
171
|
-
/**
|
|
172
|
-
* Create a new test environment
|
|
173
|
-
*/
|
|
174
|
-
private static create;
|
|
175
|
-
/**
|
|
176
|
-
* Kill the test server process and close the connection to it
|
|
177
|
-
*/
|
|
178
|
-
teardown(): Promise<void>;
|
|
179
|
-
/**
|
|
180
|
-
* Wait for `durationMs` in "server time".
|
|
181
|
-
*
|
|
182
|
-
* This awaits using regular setTimeout in regular environments, or manually skips time in time-skipping environments.
|
|
183
|
-
*
|
|
184
|
-
* Useful for simulating events far into the future like completion of long running activities.
|
|
185
|
-
*
|
|
186
|
-
* **Time skippping**:
|
|
187
|
-
*
|
|
188
|
-
* The time skippping server toggles between skipped time and normal time depending on what it needs to execute.
|
|
189
|
-
*
|
|
190
|
-
* This method is _likely_ to resolve in less than `durationMs` of "real time".
|
|
191
|
-
*
|
|
192
|
-
* @param durationMs number of milliseconds or {@link https://www.npmjs.com/package/ms | ms-formatted string}
|
|
193
|
-
*
|
|
194
|
-
* @example
|
|
195
|
-
*
|
|
196
|
-
* `workflow.ts`
|
|
197
|
-
*
|
|
198
|
-
* ```ts
|
|
199
|
-
* const activities = proxyActivities({ startToCloseTimeout: 2_000_000 });
|
|
200
|
-
*
|
|
201
|
-
* export async function raceActivityAndTimer(): Promise<string> {
|
|
202
|
-
* return await Promise.race([
|
|
203
|
-
* wf.sleep(500_000).then(() => 'timer'),
|
|
204
|
-
* activities.longRunning().then(() => 'activity'),
|
|
205
|
-
* ]);
|
|
206
|
-
* }
|
|
207
|
-
* ```
|
|
208
|
-
*
|
|
209
|
-
* `test.ts`
|
|
210
|
-
*
|
|
211
|
-
* ```ts
|
|
212
|
-
* const worker = await Worker.create({
|
|
213
|
-
* connection: testEnv.nativeConnection,
|
|
214
|
-
* activities: {
|
|
215
|
-
* async longRunning() {
|
|
216
|
-
* await testEnv.sleep(1_000_000); // <-- sleep called here
|
|
217
|
-
* },
|
|
218
|
-
* },
|
|
219
|
-
* // ...
|
|
220
|
-
* });
|
|
221
|
-
* ```
|
|
222
|
-
*/
|
|
223
|
-
sleep: (durationMs: Duration) => Promise<void>;
|
|
224
|
-
/**
|
|
225
|
-
* Get the current time known to this environment.
|
|
226
|
-
*
|
|
227
|
-
* For non-time-skipping environments this is simply the system time. For time-skipping environments this is whatever
|
|
228
|
-
* time has been skipped to.
|
|
229
|
-
*/
|
|
230
|
-
currentTimeMs(): Promise<number>;
|
|
231
|
-
}
|
|
232
|
-
export interface MockActivityEnvironmentOptions {
|
|
233
|
-
interceptors?: ActivityInterceptorsFactory[];
|
|
234
|
-
logger?: Logger;
|
|
235
|
-
}
|
|
236
|
-
/**
|
|
237
|
-
* Used as the default activity info for Activities executed in the {@link MockActivityEnvironment}
|
|
238
|
-
*/
|
|
239
|
-
export declare const defaultActivityInfo: activity.Info;
|
|
240
|
-
/**
|
|
241
|
-
* An execution environment for testing Activities.
|
|
242
|
-
*
|
|
243
|
-
* Mocks Activity {@link Context | activity.Context} and exposes hooks for cancellation and heartbeats.
|
|
244
|
-
*
|
|
245
|
-
* Note that the `Context` object used by this environment will be reused for all activities that are run in this
|
|
246
|
-
* environment. Consequently, once `cancel()` is called, any further activity that gets executed in this environment
|
|
247
|
-
* will immediately be in a cancelled state.
|
|
248
|
-
*/
|
|
249
|
-
export declare class MockActivityEnvironment extends events.EventEmitter {
|
|
250
|
-
cancel: (reason?: any) => void;
|
|
251
|
-
readonly context: activity.Context;
|
|
252
|
-
private readonly activity;
|
|
253
|
-
constructor(info?: Partial<activity.Info>, opts?: MockActivityEnvironmentOptions);
|
|
254
|
-
/**
|
|
255
|
-
* Run a function in Activity Context
|
|
256
|
-
*/
|
|
257
|
-
run<P extends any[], R, F extends ActivityFunction<P, R>>(fn: F, ...args: P): Promise<R>;
|
|
258
|
-
}
|