@temporalio/testing 0.23.0 → 0.23.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@temporalio/testing",
3
- "version": "0.23.0",
3
+ "version": "0.23.3",
4
4
  "description": "Temporal.io SDK Testing sub-package",
5
5
  "main": "lib/index.js",
6
6
  "types": "./lib/index.d.ts",
@@ -21,7 +21,7 @@
21
21
  "@temporalio/activity": "^0.23.0",
22
22
  "@temporalio/client": "^0.23.0",
23
23
  "@temporalio/common": "^0.23.0",
24
- "@temporalio/worker": "^0.23.0",
24
+ "@temporalio/worker": "^0.23.2",
25
25
  "@types/long": "^4.0.1",
26
26
  "abort-controller": "^3.0.0",
27
27
  "get-port": "^6.1.2",
@@ -37,10 +37,11 @@
37
37
  "homepage": "https://github.com/temporalio/sdk-typescript/tree/main/packages/testing",
38
38
  "files": [
39
39
  "lib",
40
- "generated-protos"
40
+ "generated-protos",
41
+ "scripts"
41
42
  ],
42
43
  "publishConfig": {
43
44
  "access": "public"
44
45
  },
45
- "gitHead": "81ee3fd09c2fd866b31b1dbfabce7ef221e338ea"
46
+ "gitHead": "2c7ed196ac2379c06419a3c98a7e7eddf1a53b01"
46
47
  }
@@ -0,0 +1,18 @@
1
+ import os from 'node:os';
2
+ import { URL, fileURLToPath } from 'node:url';
3
+
4
+ const platformMapping = { darwin: 'macOS', linux: 'linux', win32: 'windows' };
5
+ const archAlias = { x64: 'amd64', arm64: 'aarch64' };
6
+
7
+ export const systemPlatform = platformMapping[os.platform()];
8
+ if (!systemPlatform) {
9
+ throw new Error(`Unsupported platform ${os.platform()}`);
10
+ }
11
+
12
+ export const systemArch = archAlias[os.arch()];
13
+ if (!systemArch) {
14
+ throw new Error(`Unsupported architecture ${os.arch()}`);
15
+ }
16
+
17
+ const ext = systemPlatform === 'windows' ? '.exe' : '';
18
+ export const outputPath = fileURLToPath(new URL(`../test-server${ext}`, import.meta.url));
@@ -0,0 +1,81 @@
1
+ import { resolve, dirname } from 'path';
2
+ import { fileURLToPath } from 'url';
3
+ import { promisify } from 'util';
4
+ import dedent from 'dedent';
5
+ import glob from 'glob';
6
+ import { statSync, mkdirSync, readFileSync, writeFileSync } from 'fs';
7
+ import pbjs from 'protobufjs/cli/pbjs.js';
8
+ import pbts from 'protobufjs/cli/pbts.js';
9
+
10
+ const __dirname = dirname(fileURLToPath(import.meta.url));
11
+ const outputDir = resolve(__dirname, '../generated-protos');
12
+ const outputFile = resolve(outputDir, 'index.js');
13
+ const protoBaseDir = resolve(__dirname, '../proto');
14
+
15
+ const serviceProtoPath = resolve(protoBaseDir, 'temporal/api/testservice/v1/service.proto');
16
+
17
+ function mtime(path) {
18
+ try {
19
+ return statSync(path).mtimeMs;
20
+ } catch (err) {
21
+ if (err.code === 'ENOENT') {
22
+ return 0;
23
+ }
24
+ throw err;
25
+ }
26
+ }
27
+
28
+ async function compileProtos(protoPath, jsOutputFile, dtsOutputFile, ...args) {
29
+ console.log(`Creating protobuf JS definitions from ${protoPath}`);
30
+
31
+ const pbjsArgs = [
32
+ ...args,
33
+ '--wrap',
34
+ 'commonjs',
35
+ '--target',
36
+ 'static-module',
37
+ '--force-long',
38
+ '--no-verify',
39
+ '--root',
40
+ '__temporal_testing',
41
+ '--out',
42
+ jsOutputFile,
43
+ protoPath,
44
+ ];
45
+ await promisify(pbjs.main)(pbjsArgs);
46
+
47
+ console.log(`Creating protobuf TS definitions from ${protoPath}`);
48
+ await promisify(pbts.main)(['--out', dtsOutputFile, jsOutputFile]);
49
+
50
+ // Fix issue where Long is not found in TS definitions (https://github.com/protobufjs/protobuf.js/issues/1533)
51
+ const pbtsOutput = readFileSync(dtsOutputFile, 'utf8');
52
+ writeFileSync(
53
+ dtsOutputFile,
54
+ dedent`
55
+ import Long from "long";
56
+ ${pbtsOutput}
57
+ `
58
+ );
59
+ }
60
+
61
+ async function main() {
62
+ mkdirSync(outputDir, { recursive: true });
63
+
64
+ const protoFiles = glob.sync(resolve(protoBaseDir, '**/*.proto'));
65
+ const protosMTime = Math.max(...protoFiles.map(mtime));
66
+ const genMTime = mtime(outputFile);
67
+
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');
76
+ }
77
+
78
+ main().catch((err) => {
79
+ console.error(err);
80
+ process.exit(1);
81
+ });
@@ -0,0 +1,91 @@
1
+ import stream from 'node:stream';
2
+ import util from 'node:util';
3
+ import zlib from 'node:zlib';
4
+ import fs from 'node:fs';
5
+ import got from 'got';
6
+ import tar from 'tar-stream';
7
+ import unzipper from 'unzipper';
8
+ import { outputPath, systemArch, systemPlatform } from './common.mjs';
9
+
10
+ try {
11
+ if (fs.statSync(outputPath).isFile) {
12
+ console.log('Found existing test server executable', { path: outputPath });
13
+ process.exit(0);
14
+ }
15
+ } catch (err) {
16
+ if (err.code !== 'ENOENT') {
17
+ throw err;
18
+ }
19
+ }
20
+
21
+ const pipeline = util.promisify(stream.pipeline);
22
+
23
+ const defaultHeaders = {
24
+ 'User-Agent': '@temporalio/testing installer',
25
+ };
26
+
27
+ const { GITHUB_TOKEN } = process.env;
28
+
29
+ if (GITHUB_TOKEN) {
30
+ console.log(`Using GITHUB_TOKEN`);
31
+ defaultHeaders['Authorization'] = `Bearer ${GITHUB_TOKEN}`;
32
+ }
33
+
34
+ const latestReleaseRes = await got('https://api.github.com/repos/temporalio/sdk-java/releases/latest', {
35
+ headers: {
36
+ ...defaultHeaders,
37
+ Accept: 'application/vnd.github.v3+json',
38
+ },
39
+ }).json();
40
+
41
+ function findTestServerAsset(assets) {
42
+ for (const asset of assets) {
43
+ const m = asset.name.match(/^temporal-test-server_[^_]+_([^_]+)_([^.]+)\.(?:zip|tar.gz)$/);
44
+ if (m) {
45
+ const [_, assetPlatform, _assetArch] = m;
46
+ if (assetPlatform === systemPlatform) {
47
+ // TODO: assetArch === systemArch (no arm builds for test server yet)
48
+ return asset;
49
+ }
50
+ }
51
+ }
52
+ throw new Error(`No prebuilt test server for ${systemPlatform}-${systemArch}`);
53
+ }
54
+
55
+ const asset = findTestServerAsset(latestReleaseRes.assets);
56
+ console.log('Downloading test server', { asset: asset.name, outputPath });
57
+
58
+ if (asset.content_type === 'application/x-gzip' || asset.content_type === 'application/x-gtar') {
59
+ const extract = tar.extract();
60
+ extract.on('entry', (_headers, stream, next) => {
61
+ stream.pipe(fs.createWriteStream(outputPath));
62
+ next();
63
+ });
64
+ await pipeline(
65
+ got.stream(asset.browser_download_url, {
66
+ headers: {
67
+ ...defaultHeaders,
68
+ },
69
+ }),
70
+ zlib.createGunzip(),
71
+ extract
72
+ );
73
+ await fs.promises.chmod(outputPath, 0o755);
74
+ } else if (asset.content_type === 'application/zip') {
75
+ got
76
+ .stream(asset.browser_download_url, {
77
+ headers: {
78
+ ...defaultHeaders,
79
+ },
80
+ })
81
+ .pipe(unzipper.Parse())
82
+ .on('entry', (entry) => {
83
+ if (entry.type === 'File') {
84
+ entry.pipe(fs.createWriteStream(outputPath));
85
+ } else {
86
+ entry.autodrain();
87
+ }
88
+ });
89
+ } else {
90
+ throw new Error(`Unexpected content type for Test server download: ${asset.content_type}`);
91
+ }