@temporalio/testing 1.2.0 → 1.3.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.
@@ -1,18 +0,0 @@
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));
@@ -1,91 +0,0 @@
1
- import { createRequire } from 'module';
2
- import { resolve, dirname } from 'path';
3
- import { fileURLToPath } from 'url';
4
- import { promisify } from 'util';
5
- import dedent from 'dedent';
6
- import glob from 'glob';
7
- import { statSync, mkdirSync, readFileSync, writeFileSync } from 'fs';
8
- import pbjs from 'protobufjs-cli/pbjs.js';
9
- import pbts from 'protobufjs-cli/pbts.js';
10
-
11
- const require = createRequire(import.meta.url);
12
- const __dirname = dirname(fileURLToPath(import.meta.url));
13
- const outputDir = resolve(__dirname, '../generated-protos');
14
- const outputFile = resolve(outputDir, 'index.js');
15
- const protoBaseDir = resolve(__dirname, '../proto');
16
-
17
- const serviceProtoPath = resolve(protoBaseDir, 'temporal/api/testservice/v1/service.proto');
18
-
19
- function mtime(path) {
20
- try {
21
- return statSync(path).mtimeMs;
22
- } catch (err) {
23
- if (err.code === 'ENOENT') {
24
- return 0;
25
- }
26
- throw err;
27
- }
28
- }
29
-
30
- async function compileProtos(protoPath, jsOutputFile, dtsOutputFile, ...args) {
31
- console.log(`Creating protobuf JS definitions from ${protoPath}`);
32
-
33
- const pbjsArgs = [
34
- ...args,
35
- '--wrap',
36
- 'commonjs',
37
- '--target',
38
- 'static-module',
39
- '--force-long',
40
- '--no-verify',
41
- '--root',
42
- '__temporal_testing',
43
- '--out',
44
- jsOutputFile,
45
- resolve(require.resolve('protobufjs'), '../google/protobuf/descriptor.proto'),
46
- protoPath,
47
- ];
48
- await promisify(pbjs.main)(pbjsArgs);
49
-
50
- // Workaround an issue that prevents protobufjs from loading 'long' in Yarn 3 PnP
51
- // https://github.com/protobufjs/protobuf.js/issues/1745#issuecomment-1200319399
52
- const pbjsOutput = readFileSync(jsOutputFile, 'utf8');
53
- writeFileSync(
54
- jsOutputFile,
55
- pbjsOutput.replace(
56
- /(require\("protobufjs\/minimal"\);)$/m,
57
- `$1
58
- $protobuf.util.Long = require('long');
59
- $protobuf.configure();
60
- `
61
- )
62
- );
63
-
64
- console.log(`Creating protobuf TS definitions from ${protoPath}`);
65
- await promisify(pbts.main)(['--out', dtsOutputFile, jsOutputFile]);
66
-
67
- // Fix issue where Long is not found in TS definitions (https://github.com/protobufjs/protobuf.js/issues/1533)
68
- const pbtsOutput = readFileSync(dtsOutputFile, 'utf8');
69
- writeFileSync(
70
- dtsOutputFile,
71
- dedent`
72
- import Long from "long";
73
- ${pbtsOutput}
74
- `
75
- );
76
- }
77
-
78
- mkdirSync(outputDir, { recursive: true });
79
-
80
- const protoFiles = glob.sync(resolve(protoBaseDir, '**/*.proto'));
81
- const protosMTime = Math.max(...protoFiles.map(mtime));
82
- const genMTime = mtime(outputFile);
83
-
84
- if (protosMTime < genMTime) {
85
- console.log('Assuming protos are up to date');
86
- process.exit(0);
87
- }
88
-
89
- await compileProtos(serviceProtoPath, outputFile, resolve(outputDir, 'index.d.ts'), '--path', resolve(protoBaseDir));
90
-
91
- console.log('Done');
@@ -1,91 +0,0 @@
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
- }
@@ -1,60 +0,0 @@
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';
@@ -1,2 +0,0 @@
1
- // Reexports the contents of this package under the "testing" namespace for better docs generation
2
- export * as testing from './index';