@temporalio/testing 0.19.2

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/LICENSE.md ADDED
@@ -0,0 +1,23 @@
1
+ Temporal TypeScript SDK
2
+
3
+ MIT License
4
+
5
+ Copyright (c) 2021 Temporal Technologies, Inc. All Rights Reserved
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ of this software and associated documentation files (the "Software"), to deal
9
+ in the Software without restriction, including without limitation the rights
10
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ copies of the Software, and to permit persons to whom the Software is
12
+ furnished to do so, subject to the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be included in all
15
+ copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ SOFTWARE.
@@ -0,0 +1,14 @@
1
+ /// <reference types="node" />
2
+ import { ChildProcess } from 'child_process';
3
+ export declare class ChildProcessError extends Error {
4
+ readonly code: number | null;
5
+ readonly signal: NodeJS.Signals | null;
6
+ readonly name = "ChildProcessError";
7
+ constructor(message: string, code: number | null, signal: NodeJS.Signals | null);
8
+ }
9
+ export interface WaitOptions {
10
+ validReturnCodes: number[];
11
+ }
12
+ export declare function waitOnChild(child: ChildProcess, opts?: WaitOptions): Promise<void>;
13
+ export declare function kill(child: ChildProcess, signal?: NodeJS.Signals, opts?: WaitOptions): Promise<void>;
14
+ export declare const shell: boolean;
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.shell = exports.kill = exports.waitOnChild = exports.ChildProcessError = void 0;
4
+ class ChildProcessError extends Error {
5
+ constructor(message, code, signal) {
6
+ super(message);
7
+ this.code = code;
8
+ this.signal = signal;
9
+ this.name = 'ChildProcessError';
10
+ }
11
+ }
12
+ exports.ChildProcessError = ChildProcessError;
13
+ async function waitOnChild(child, opts) {
14
+ return new Promise((resolve, reject) => {
15
+ child.on('exit', (code, signal) => {
16
+ if (code !== null && (opts?.validReturnCodes ?? [0]).includes(code)) {
17
+ resolve();
18
+ }
19
+ else {
20
+ reject(new ChildProcessError('Process failed', code, signal));
21
+ }
22
+ });
23
+ child.on('error', reject);
24
+ });
25
+ }
26
+ exports.waitOnChild = waitOnChild;
27
+ async function kill(child, signal = 'SIGINT', opts) {
28
+ if (child.pid === undefined) {
29
+ throw new TypeError('Expected child with pid');
30
+ }
31
+ process.kill(child.pid, signal);
32
+ try {
33
+ await waitOnChild(child, opts);
34
+ }
35
+ catch (err) {
36
+ // Should error if the error is not a child process error or it is a child
37
+ // process and either the platform is Windows or the signal matches.
38
+ const shouldError = !(err instanceof ChildProcessError) || (process.platform !== 'win32' && err.signal !== signal);
39
+ if (shouldError) {
40
+ throw err;
41
+ }
42
+ }
43
+ }
44
+ exports.kill = kill;
45
+ exports.shell = process.platform === 'win32';
46
+ //# sourceMappingURL=child-process.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"child-process.js","sourceRoot":"","sources":["../src/child-process.ts"],"names":[],"mappings":";;;AAGA,MAAa,iBAAkB,SAAQ,KAAK;IAG1C,YAAY,OAAe,EAAkB,IAAmB,EAAkB,MAA6B;QAC7G,KAAK,CAAC,OAAO,CAAC,CAAC;QAD4B,SAAI,GAAJ,IAAI,CAAe;QAAkB,WAAM,GAAN,MAAM,CAAuB;QAF/F,SAAI,GAAG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fD,oBAeC;AAEY,QAAA,KAAK,GAAG,OAAO,CAAC,QAAQ,KAAK,OAAO,CAAC"}
package/lib/index.d.ts ADDED
@@ -0,0 +1,64 @@
1
+ /// <reference types="node" />
2
+ import * as activity from '@temporalio/activity';
3
+ import { AsyncCompletionClient, Connection, WorkflowClient } from '@temporalio/client';
4
+ import { ActivityFunction } from '@temporalio/common';
5
+ import { Logger } from '@temporalio/worker';
6
+ import { ChildProcess, StdioOptions } from 'child_process';
7
+ import events from 'events';
8
+ /**
9
+ * Options for {@link TestWorkflowEnvironment.create}
10
+ */
11
+ export interface TestWorkflowEnvironmentOptions {
12
+ /**
13
+ * If `testServerSpawner` is not provided, use this value for child process stdio
14
+ */
15
+ testServerStdio?: StdioOptions;
16
+ testServerSpawner?(port: number): ChildProcess;
17
+ logger?: Logger;
18
+ }
19
+ /**
20
+ * An execution environment for running Workflow integration tests.
21
+ *
22
+ * Runs an external server.
23
+ * By default, the Java test server is used which supports time skipping.
24
+ */
25
+ export declare class TestWorkflowEnvironment {
26
+ protected readonly serverProc: ChildProcess;
27
+ /**
28
+ * Get an extablished {@link Connection} to the test server
29
+ */
30
+ readonly connection: Connection;
31
+ /**
32
+ * An {@link AsyncCompletionClient} for interacting with the test server
33
+ */
34
+ readonly asyncCompletionClient: AsyncCompletionClient;
35
+ /**
36
+ * A {@link WorkflowClient} for interacting with the test server
37
+ */
38
+ readonly workflowClient: WorkflowClient;
39
+ protected constructor(serverProc: ChildProcess, connection: Connection);
40
+ /**
41
+ * Create a new test environment
42
+ */
43
+ static create(opts?: TestWorkflowEnvironmentOptions): Promise<TestWorkflowEnvironment>;
44
+ /**
45
+ * Kill the test server process and close the connection to it
46
+ */
47
+ teardown(): Promise<void>;
48
+ }
49
+ export declare const defaultActivityInfo: activity.Info;
50
+ /**
51
+ * An execution environment for testing Activities.
52
+ *
53
+ * Mocks Activity {@link Context | activity.Context} and exposes hooks for
54
+ * cancellation and heartbeats.
55
+ */
56
+ export declare class MockActivityEnvironment extends events.EventEmitter {
57
+ cancel: (reason?: any) => void;
58
+ readonly context: activity.Context;
59
+ constructor(info?: Partial<activity.Info>);
60
+ /**
61
+ * Run a function in Activity Context
62
+ */
63
+ run<P extends any[], R, F extends ActivityFunction<P, R>>(fn: F, ...args: P): Promise<R>;
64
+ }
package/lib/index.js ADDED
@@ -0,0 +1,153 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.MockActivityEnvironment = exports.defaultActivityInfo = exports.TestWorkflowEnvironment = void 0;
30
+ const activity = __importStar(require("@temporalio/activity"));
31
+ const client_1 = require("@temporalio/client");
32
+ const common_1 = require("@temporalio/common");
33
+ const worker_1 = require("@temporalio/worker");
34
+ const path_1 = __importDefault(require("path"));
35
+ const os_1 = __importDefault(require("os"));
36
+ const abort_controller_1 = require("abort-controller");
37
+ const child_process_1 = require("child_process");
38
+ const events_1 = __importDefault(require("events"));
39
+ const child_process_2 = require("./child-process");
40
+ const TEST_SERVER_EXECUTABLE_NAME = os_1.default.platform() === 'win32' ? 'test-server.exe' : 'test-server';
41
+ function addDefaults({ testServerStdio = 'ignore', testServerSpawner, logger, }) {
42
+ return {
43
+ testServerSpawner: testServerSpawner ??
44
+ ((port) => (0, child_process_1.spawn)(path_1.default.join(__dirname, `../${TEST_SERVER_EXECUTABLE_NAME}`), [`${port}`], {
45
+ stdio: testServerStdio,
46
+ })),
47
+ logger: logger ?? new worker_1.DefaultLogger('INFO'),
48
+ testServerStdio,
49
+ };
50
+ }
51
+ // TS transforms `import` statements into `require`s, this is a workaround until
52
+ // tsconfig module nodenext is stable.
53
+ const _importDynamic = new Function('modulePath', 'return import(modulePath)');
54
+ /**
55
+ * An execution environment for running Workflow integration tests.
56
+ *
57
+ * Runs an external server.
58
+ * By default, the Java test server is used which supports time skipping.
59
+ */
60
+ class TestWorkflowEnvironment {
61
+ constructor(serverProc, connection) {
62
+ this.serverProc = serverProc;
63
+ this.connection = connection;
64
+ this.workflowClient = new client_1.WorkflowClient(this.connection.service);
65
+ this.asyncCompletionClient = new client_1.AsyncCompletionClient(this.connection.service);
66
+ }
67
+ /**
68
+ * Create a new test environment
69
+ */
70
+ static async create(opts) {
71
+ // No, we're not going to compile this to ESM for one dependency
72
+ const getPort = (await _importDynamic('get-port')).default;
73
+ const port = await getPort();
74
+ const { testServerSpawner, logger } = addDefaults(opts ?? {});
75
+ const child = testServerSpawner(port);
76
+ const address = `127.0.0.1:${port}`;
77
+ const conn = new client_1.Connection({ address });
78
+ try {
79
+ await Promise.race([
80
+ conn.untilReady(),
81
+ (0, child_process_2.waitOnChild)(child).then(() => {
82
+ throw new Error('Test server child process exited prematurely');
83
+ }),
84
+ ]);
85
+ }
86
+ catch (err) {
87
+ try {
88
+ await (0, child_process_2.kill)(child);
89
+ }
90
+ catch (error) {
91
+ logger.error('Failed to kill test server child process', { error });
92
+ }
93
+ throw err;
94
+ }
95
+ // TODO: Core is a singleton at the moment, once the bridge is refactored this will change.
96
+ await worker_1.Core.install({ serverOptions: { address } });
97
+ return new this(child, conn);
98
+ }
99
+ /**
100
+ * Kill the test server process and close the connection to it
101
+ */
102
+ async teardown() {
103
+ this.connection.client.close();
104
+ // TODO: the server should return exit code 0
105
+ await (0, child_process_2.kill)(this.serverProc, 'SIGINT', { validReturnCodes: [0, 130] });
106
+ }
107
+ }
108
+ exports.TestWorkflowEnvironment = TestWorkflowEnvironment;
109
+ exports.defaultActivityInfo = {
110
+ attempt: 1,
111
+ isLocal: false,
112
+ taskToken: Buffer.from('test'),
113
+ activityId: 'test',
114
+ activityType: 'unknown',
115
+ workflowType: 'test',
116
+ base64TaskToken: Buffer.from('test').toString('base64'),
117
+ heartbeatDetails: undefined,
118
+ activityNamespace: 'default',
119
+ workflowNamespace: 'default',
120
+ workflowExecution: { workflowId: 'test', runId: 'dead-beef' },
121
+ scheduledTimestampMs: 1,
122
+ startToCloseTimeoutMs: 1000,
123
+ scheduleToCloseTimeoutMs: 1000,
124
+ };
125
+ /**
126
+ * An execution environment for testing Activities.
127
+ *
128
+ * Mocks Activity {@link Context | activity.Context} and exposes hooks for
129
+ * cancellation and heartbeats.
130
+ */
131
+ class MockActivityEnvironment extends events_1.default.EventEmitter {
132
+ constructor(info) {
133
+ super();
134
+ this.cancel = () => undefined;
135
+ const abortController = new abort_controller_1.AbortController();
136
+ const promise = new Promise((_, reject) => {
137
+ this.cancel = (reason) => {
138
+ abortController.abort();
139
+ reject(new common_1.CancelledFailure(reason));
140
+ };
141
+ });
142
+ const heartbeatCallback = (details) => this.emit('heartbeat', details);
143
+ this.context = new activity.Context({ ...exports.defaultActivityInfo, ...info }, promise, abortController.signal, heartbeatCallback);
144
+ }
145
+ /**
146
+ * Run a function in Activity Context
147
+ */
148
+ run(fn, ...args) {
149
+ return activity.asyncLocalStorage.run(this.context, fn, ...args);
150
+ }
151
+ }
152
+ exports.MockActivityEnvironment = MockActivityEnvironment;
153
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+DAAiD;AACjD,+CAAuF;AACvF,+CAAwE;AACxE,+CAAiE;AACjE,gDAAwB;AACxB,4CAAoB;AACpB,uDAAmD;AACnD,iDAAkE;AAClE,oDAA4B;AAC5B,mDAAoD;AAGpD,MAAM,2BAA2B,GAAG,YAAE,CAAC,QAAQ,EAAE,KAAK,OAAO,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC,aAAa,CAAC;AAclG,SAAS,WAAW,CAAC,EACnB,eAAe,GAAG,QAAQ,EAC1B,iBAAiB,EACjB,MAAM,GACyB;IAC/B,OAAO;QACL,iBAAiB,EACf,iBAAiB;YACjB,CAAC,CAAC,IAAY,EAAE,EAAE,CAChB,IAAA,qBAAK,EAAC,cAAI,CAAC,IAAI,CAAC,SAAS,EAAE,MAAM,2BAA2B,EAAE,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,EAAE;gBAC5E,KAAK,EAAE,eAAe;aACvB,CAAC,CAAC;QACP,MAAM,EAAE,MAAM,IAAI,IAAI,sBAAa,CAAC,MAAM,CAAC;QAC3C,eAAe;KAChB,CAAC;AACJ,CAAC;AAED,gFAAgF;AAChF,sCAAsC;AACtC,MAAM,cAAc,GAAG,IAAI,QAAQ,CAAC,YAAY,EAAE,2BAA2B,CAAC,CAAC;AAE/E;;;;;GAKG;AACH,MAAa,uBAAuB;IAgBlC,YAAyC,UAAwB,EAAE,UAAsB;QAAhD,eAAU,GAAV,UAAU,CAAc;QAC/D,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,cAAc,GAAG,IAAI,uBAAc,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;QAClE,IAAI,CAAC,qBA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AAC,CAAC,CAAC;YACvC,CAAC,CAAC;QACJ,CAAC,CAAC,CAAC;QACH,MAAM,iBAAiB,GAAG,CAAC,OAAiB,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;QACjF,IAAI,CAAC,OAAO,GAAG,IAAI,QAAQ,CAAC,OAAO,CACjC,EAAE,GAAG,2BAAmB,EAAE,GAAG,IAAI,EAAE,EACnC,OAAO,EACP,eAAe,CAAC,MAAM,EACtB,iBAAiB,CAClB,CAAC;IACJ,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;AA5BD,0DA4BC"}
package/lib/utils.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ import { Connection } from '@temporalio/client';
2
+ export declare function waitOnNamespace(connection: Connection, namespace: string, maxAttempts?: number, retryIntervalSecs?: number): Promise<void>;
3
+ export declare function createNamespace(connection: Connection, namespace: string, maxAttempts?: number, retryIntervalSecs?: number): Promise<void>;
package/lib/utils.js ADDED
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createNamespace = exports.waitOnNamespace = void 0;
4
+ const internal_workflow_common_1 = require("@temporalio/internal-workflow-common");
5
+ async function waitOnNamespace(connection, namespace, maxAttempts = 100, retryIntervalSecs = 1) {
6
+ const runId = '12345678-dead-beef-1234-1234567890ab';
7
+ for (let attempt = 1; attempt <= maxAttempts; ++attempt) {
8
+ try {
9
+ await connection.service.getWorkflowExecutionHistory({
10
+ namespace,
11
+ execution: { workflowId: 'fake', runId },
12
+ });
13
+ }
14
+ catch (err) {
15
+ console.log(err);
16
+ if (err.details.includes('workflow history not found') || err.details.includes(runId)) {
17
+ break;
18
+ }
19
+ if (attempt === maxAttempts) {
20
+ throw err;
21
+ }
22
+ await new Promise((resolve) => setTimeout(resolve, retryIntervalSecs * 1000));
23
+ }
24
+ }
25
+ }
26
+ exports.waitOnNamespace = waitOnNamespace;
27
+ async function createNamespace(connection, namespace, maxAttempts = 100, retryIntervalSecs = 1) {
28
+ for (let attempt = 1; attempt <= maxAttempts; ++attempt) {
29
+ try {
30
+ await connection.service.registerNamespace({ namespace, workflowExecutionRetentionPeriod: (0, internal_workflow_common_1.msToTs)('1 day') });
31
+ break;
32
+ }
33
+ catch (err) {
34
+ if (err.details === 'Namespace already exists.') {
35
+ break;
36
+ }
37
+ if (attempt === maxAttempts) {
38
+ throw err;
39
+ }
40
+ await new Promise((resolve) => setTimeout(resolve, retryIntervalSecs * 1000));
41
+ }
42
+ }
43
+ }
44
+ exports.createNamespace = createNamespace;
45
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AACA,mFAA8D;AAEvD,KAAK,UAAU,eAAe,CACnC,UAAsB,EACtB,SAAiB,EACjB,WAAW,GAAG,GAAG,EACjB,iBAAiB,GAAG,CAAC;IAErB,MAAM,KAAK,GAAG,sCAAsC,CAAC;IACrD,KAAK,IAAI,OAAO,GAAG,CAAC,EAAE,OAAO,IAAI,WAAW,EAAE,EAAE,OAAO,EAAE;QACvD,IAAI;YACF,MAAM,UAAU,CAAC,OAAO,CAAC,2BAA2B,CAAC;gBACnD,SAAS;gBACT,SAAS,EAAE,EAAE,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE;aACzC,CAAC,CAAC;SACJ;QAAC,OAAO,GAAQ,EAAE;YACjB,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YACjB,IAAI,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC,4BAA4B,CAAC,IAAI,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE;gBACrF,MAAM;aACP;YACD,IAAI,OAAO,KAAK,WAAW,EAAE;gBAC3B,MAAM,GAAG,CAAC;aACX;YACD,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,iBAAiB,GAAG,IAAI,CAAC,CAAC,CAAC;SAC/E;KACF;AACH,CAAC;AAxBD,0CAwBC;AAEM,KAAK,UAAU,eAAe,CACnC,UAAsB,EACtB,SAAiB,EACjB,WAAW,GAAG,GAAG,EACjB,iBAAiB,GAAG,CAAC;IAErB,KAAK,IAAI,OAAO,GAAG,CAAC,EAAE,OAAO,IAAI,WAAW,EAAE,EAAE,OAAO,EAAE;QACvD,IAAI;YACF,MAAM,UAAU,CAAC,OAAO,CAAC,iBAAiB,CAAC,EAAE,SAAS,EAAE,gCAAgC,EAAE,IAAA,iCAAM,EAAC,OAAO,CAAC,EAAE,CAAC,CAAC;YAC7G,MAAM;SACP;QAAC,OAAO,GAAQ,EAAE;YACjB,IAAI,GAAG,CAAC,OAAO,KAAK,2BAA2B,EAAE;gBAC/C,MAAM;aACP;YACD,IAAI,OAAO,KAAK,WAAW,EAAE;gBAC3B,MAAM,GAAG,CAAC;aACX;YACD,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,iBAAiB,GAAG,IAAI,CAAC,CAAC,CAAC;SAC/E;KACF;AACH,CAAC;AApBD,0CAoBC"}
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "@temporalio/testing",
3
+ "version": "0.19.2",
4
+ "description": "Temporal.io SDK Testing sub-package",
5
+ "main": "lib/index.js",
6
+ "types": "./lib/index.d.ts",
7
+ "keywords": [
8
+ "temporal",
9
+ "workflow",
10
+ "testing"
11
+ ],
12
+ "scripts": {
13
+ "install": "node ./scripts/download-test-server.mjs",
14
+ "build": "node ./scripts/download-test-server.mjs"
15
+ },
16
+ "author": "Temporal Technologies Inc. <sdk@temporal.io>",
17
+ "license": "MIT",
18
+ "dependencies": {
19
+ "@temporalio/activity": "^0.19.2",
20
+ "@temporalio/client": "^0.19.2",
21
+ "@temporalio/worker": "^0.19.2",
22
+ "abort-controller": "^3.0.0",
23
+ "get-port": "^6.1.2",
24
+ "got": "^12.0.1",
25
+ "tar-stream": "^2.2.0",
26
+ "unzipper": "^0.10.11"
27
+ },
28
+ "bugs": {
29
+ "url": "https://github.com/temporalio/sdk-typescript/issues"
30
+ },
31
+ "homepage": "https://github.com/temporalio/sdk-typescript/tree/main/packages/testing",
32
+ "files": [
33
+ "lib"
34
+ ],
35
+ "publishConfig": {
36
+ "access": "public"
37
+ },
38
+ "gitHead": "57172075a1eb3f2292a1188d260fab0ee155349f"
39
+ }