@autifyhq/autify-cli 0.7.1 → 0.9.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/README.md CHANGED
@@ -1,8 +1,10 @@
1
1
  # Autify Command Line Interface (CLI)
2
2
 
3
+ ![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/autifyhq/autify-cli?color=blue&display_name=tag&sort=semver) [![oclif](https://img.shields.io/badge/cli-oclif-brightgreen.svg)](https://oclif.io)
4
+
3
5
  Autify CLI can help your integration with Autify!
4
6
 
5
- [![oclif](https://img.shields.io/badge/cli-oclif-brightgreen.svg)](https://oclif.io)
7
+ ![Autify_CLI_ogp (2)](https://user-images.githubusercontent.com/37822/186738361-4d07c65f-9d3b-4295-ba3c-f2b84a6d9743.png)
6
8
 
7
9
  <!-- toc -->
8
10
  * [Autify Command Line Interface (CLI)](#autify-command-line-interface-cli)
@@ -12,50 +14,14 @@ Autify CLI can help your integration with Autify!
12
14
 
13
15
  # Usage
14
16
 
15
- Note: `npm install` is not available yet. We'll work on publishing to npm.
16
-
17
- <!-- usage -->
18
- ```sh-session
19
- $ npm install -g @autifyhq/autify-cli
20
- $ autify COMMAND
21
- running command...
22
- $ autify (--version)
23
- @autifyhq/autify-cli/0.7.1 linux-x64 node-v16.17.0
24
- $ autify --help [COMMAND]
25
- USAGE
26
- $ autify COMMAND
27
- ...
28
- ```
29
- <!-- usagestop -->
30
-
31
- ## Download Prebuilt package
32
-
33
- We provide prebuilt packages in the forms below (Node.js runtime is included):
34
-
35
- | OS | Architecture | Package type | Download Link | Note |
36
- | :------ | :----------- | :----------- | :--------------------------------------------------------------------------------------------------------------------- | :----------------------- |
37
- | Linux | Intel 64bit | tar.gz | [`stable`](https://autify-cli-assets.s3.us-west-2.amazonaws.com/autify-cli/channels/stable/autify-linux-x64.tar.gz) |
38
- | Linux | Intel 64bit | tar.xz | [`stable`](https://autify-cli-assets.s3.us-west-2.amazonaws.com/autify-cli/channels/stable/autify-linux-x64.tar.xz) |
39
- | Linux | Arm 32bit | tar.gz | [`stable`](https://autify-cli-assets.s3.us-west-2.amazonaws.com/autify-cli/channels/stable/autify-linux-arm.tar.gz) |
40
- | Linux | Arm 32bit | tar.xz | [`stable`](https://autify-cli-assets.s3.us-west-2.amazonaws.com/autify-cli/channels/stable/autify-linux-arm.tar.xz) |
41
- | macOS | Intel 64bit | tar.gz | [`stable`](https://autify-cli-assets.s3.us-west-2.amazonaws.com/autify-cli/channels/stable/autify-darwin-x64.tar.gz) |
42
- | macOS | Intel 64bit | tar.xz | [`stable`](https://autify-cli-assets.s3.us-west-2.amazonaws.com/autify-cli/channels/stable/autify-darwin-x64.tar.xz) |
43
- | macOS | Intel 64bit | Installer | [`stable`](https://autify-cli-assets.s3.us-west-2.amazonaws.com/autify-cli/channels/stable/autify-x64.pkg) | Not properly signed yet. |
44
- | macOS | Arm 64bit | tar.gz | [`stable`](https://autify-cli-assets.s3.us-west-2.amazonaws.com/autify-cli/channels/stable/autify-darwin-arm64.tar.gz) |
45
- | macOS | Arm 64bit | tar.xz | [`stable`](https://autify-cli-assets.s3.us-west-2.amazonaws.com/autify-cli/channels/stable/autify-darwin-arm64.tar.xz) |
46
- | macOS | Arm 64bit | Installer | [`stable`](https://autify-cli-assets.s3.us-west-2.amazonaws.com/autify-cli/channels/stable/autify-arm64.pkg) | Not properly signed yet. |
47
- | Windows | Intel 64bit | tar.gz | [`stable`](https://autify-cli-assets.s3.us-west-2.amazonaws.com/autify-cli/channels/stable/autify-win32-x64.tar.gz) |
48
- | Windows | Intel 64bit | tar.xz | [`stable`](https://autify-cli-assets.s3.us-west-2.amazonaws.com/autify-cli/channels/stable/autify-win32-x64.tar.xz) |
49
- | Windows | Intel 64bit | Installer | [`stable`](https://autify-cli-assets.s3.us-west-2.amazonaws.com/autify-cli/channels/stable/autify-x64.exe) | Not properly signed yet. |
50
- | Windows | Intel 32bit | tar.gz | [`stable`](https://autify-cli-assets.s3.us-west-2.amazonaws.com/autify-cli/channels/stable/autify-win32-x86.tar.gz) |
51
- | Windows | Intel 32bit | tar.xz | [`stable`](https://autify-cli-assets.s3.us-west-2.amazonaws.com/autify-cli/channels/stable/autify-win32-x86.tar.xz) |
52
- | Windows | Intel 32bit | Installer | [`stable`](https://autify-cli-assets.s3.us-west-2.amazonaws.com/autify-cli/channels/stable/autify-x86.exe) | Not properly signed yet. |
53
-
54
- After the installation, you can always get the latest update on `stable` channel automatically, or by running `autify update`.
17
+ See our official document: https://help.autify.com/docs/autify-command-line-interface
55
18
 
56
19
  # Commands
57
20
 
58
21
  <!-- commands -->
22
+ * [`autify connect access-point set`](#autify-connect-access-point-set)
23
+ * [`autify connect client install`](#autify-connect-client-install)
24
+ * [`autify connect client start`](#autify-connect-client-start)
59
25
  * [`autify help [COMMAND]`](#autify-help-command)
60
26
  * [`autify mobile api describe-test-result`](#autify-mobile-api-describe-test-result)
61
27
  * [`autify mobile api list-test-results`](#autify-mobile-api-list-test-results)
@@ -81,6 +47,66 @@ After the installation, you can always get the latest update on `stable` channel
81
47
  * [`autify web test run SCENARIO-OR-TEST-PLAN-URL`](#autify-web-test-run-scenario-or-test-plan-url)
82
48
  * [`autify web test wait TEST-RESULT-URL`](#autify-web-test-wait-test-result-url)
83
49
 
50
+ ## `autify connect access-point set`
51
+
52
+ [Experimental] Set Autify Connect Access Point
53
+
54
+ ```
55
+ USAGE
56
+ $ autify connect access-point set --name <value>
57
+
58
+ FLAGS
59
+ --name=<value> (required) Name of the Autify Connect Access Point already created
60
+
61
+ DESCRIPTION
62
+ [Experimental] Set Autify Connect Access Point
63
+
64
+ EXAMPLES
65
+ Start interactive setup:
66
+
67
+ $ autify connect access-point set --name=NAME
68
+
69
+ Reading the key from file:
70
+
71
+ $ autify connect access-point set --name=NAME < key.txt
72
+ ```
73
+
74
+ ## `autify connect client install`
75
+
76
+ [Experimental] Install the latest stable version of Autify Connect Client
77
+
78
+ ```
79
+ USAGE
80
+ $ autify connect client install
81
+
82
+ DESCRIPTION
83
+ [Experimental] Install the latest stable version of Autify Connect Client
84
+
85
+ EXAMPLES
86
+ $ autify connect client install
87
+ ```
88
+
89
+ ## `autify connect client start`
90
+
91
+ [Experimental] Start Autify Connect Client
92
+
93
+ ```
94
+ USAGE
95
+ $ autify connect client start [--verbose] [--file-logging] [--web-workspace-id <value>]
96
+
97
+ FLAGS
98
+ --file-logging Logging Autify Connect Client log to a file instead of console.
99
+ --verbose Make the operation more talkative.
100
+ --web-workspace-id=<value> Workspace ID of Autify for Web to create an ephemeral Access Point. If not specified, it
101
+ will use the one configured by `autify connect access-point set`, instead.
102
+
103
+ DESCRIPTION
104
+ [Experimental] Start Autify Connect Client
105
+
106
+ EXAMPLES
107
+ $ autify connect client start
108
+ ```
109
+
84
110
  ## `autify help [COMMAND]`
85
111
 
86
112
  Display help for autify.
@@ -240,16 +266,18 @@ Run a test plan.
240
266
  ```
241
267
  USAGE
242
268
  $ autify mobile test run [TEST-PLAN-URL] [--build-id <value> | --build-path <value>] [-w] [-t <value>] [-v]
269
+ [--max-retry-count <value>]
243
270
 
244
271
  ARGUMENTS
245
272
  TEST-PLAN-URL Test plan URL e.g. https://mobile-app.autify.com/projects/<ID>/test_plans/<ID>
246
273
 
247
274
  FLAGS
248
- -t, --timeout=<value> [default: 300] Timeout seconds when waiting for the finish of the test execution.
249
- -v, --verbose Verbose output
250
- -w, --wait Wait until the test finishes.
251
- --build-id=<value> ID of the already uploaded build.
252
- --build-path=<value> File path to the iOS app (*.app) or Android app (*.apk).
275
+ -t, --timeout=<value> [default: 300] Timeout seconds when waiting for the finish of the test execution.
276
+ -v, --verbose Verbose output
277
+ -w, --wait Wait until the test finishes.
278
+ --build-id=<value> ID of the already uploaded build.
279
+ --build-path=<value> File path to the iOS app (*.app) or Android app (*.apk).
280
+ --max-retry-count=<value> Maximum retry count. The command can take up to timeout * (max-retry-count + 1).
253
281
 
254
282
  DESCRIPTION
255
283
  Run a test plan.
@@ -575,26 +603,33 @@ Run a scenario or test plan.
575
603
 
576
604
  ```
577
605
  USAGE
578
- $ autify web test run [SCENARIO-OR-TEST-PLAN-URL] [-n <value>] [-r <value>] [--autify-connect <value>] [--os
579
- <value>] [--os-version <value>] [--browser <value>] [--device <value>] [--device-type <value>] [-w] [-t <value>]
580
- [-v]
606
+ $ autify web test run [SCENARIO-OR-TEST-PLAN-URL] [-n <value>] [-r <value>] [--autify-connect <value> |
607
+ --autify-connect-client] [--autify-connect-client-verbose ] [--autify-connect-client-file-logging ] [--os <value>]
608
+ [--os-version <value>] [--browser <value>] [--device <value>] [--device-type <value>] [-w] [-t <value>] [-v]
609
+ [--max-retry-count <value>]
581
610
 
582
611
  ARGUMENTS
583
612
  SCENARIO-OR-TEST-PLAN-URL Scenario URL or Test plan URL e.g.
584
613
  https://app.autify.com/projects/<ID>/(scenarios|test_plans)/<ID>
585
614
 
586
615
  FLAGS
587
- -n, --name=<value> Name of the test execution. (Only for test scenario execution.)
588
- -r, --url-replacements=<value>... URL replacements. Example: http://example.com=http://example.net
589
- -t, --timeout=<value> [default: 300] Timeout seconds when waiting for the finish of the test execution.
590
- -v, --verbose Verbose output
591
- -w, --wait Wait until the test finishes.
592
- --autify-connect=<value> Name of the Autify Connect Access Point (Only for test scenario execution.)
593
- --browser=<value> Browser to run the test
594
- --device=<value> Device to run the test
595
- --device-type=<value> Device type to run the test
596
- --os=<value> OS to run the test
597
- --os-version=<value> OS version to run the test
616
+ -n, --name=<value> Name of the test execution. (Only for test scenario execution.)
617
+ -r, --url-replacements=<value>... URL replacements. Example: http://example.com=http://example.net
618
+ -t, --timeout=<value> [default: 300] Timeout seconds when waiting for the finish of the test
619
+ execution.
620
+ -v, --verbose Verbose output
621
+ -w, --wait Wait until the test finishes.
622
+ --autify-connect=<value> Name of the Autify Connect Access Point (Only for test scenario execution.)
623
+ --autify-connect-client [Experimental] Start Autify Connect Client (Only for test scenario execution.)
624
+ --autify-connect-client-file-logging [Experimental] Logging Autify Connect Client log to a file instead of console.
625
+ --autify-connect-client-verbose [Experimental] Verbose output for Autify Connect Client (Only for test scenario
626
+ execution.)
627
+ --browser=<value> Browser to run the test
628
+ --device=<value> Device to run the test
629
+ --device-type=<value> Device type to run the test
630
+ --max-retry-count=<value> Maximum retry count. The command can take up to timeout * (max-retry-count + 1).
631
+ --os=<value> OS to run the test
632
+ --os-version=<value> OS version to run the test
598
633
 
599
634
  DESCRIPTION
600
635
  Run a scenario or test plan.
@@ -0,0 +1,6 @@
1
+ export declare const getInstallPath: (cacheDir: string) => string;
2
+ export declare const getInstallVersion: (path: string) => Promise<string>;
3
+ export declare const installClient: (cacheDir: string) => Promise<{
4
+ version: string;
5
+ path: string;
6
+ }>;
@@ -0,0 +1,117 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.installClient = exports.getInstallVersion = exports.getInstallPath = void 0;
4
+ const tslib_1 = require("tslib");
5
+ /* eslint-disable unicorn/filename-case */
6
+ const errors_1 = require("@oclif/errors");
7
+ const node_process_1 = require("node:process");
8
+ const node_fetch_1 = tslib_1.__importDefault(require("node-fetch"));
9
+ const node_fs_1 = require("node:fs");
10
+ const node_stream_1 = require("node:stream");
11
+ const node_util_1 = require("node:util");
12
+ const node_path_1 = require("node:path");
13
+ const node_child_process_1 = require("node:child_process");
14
+ const unzip_stream_1 = require("unzip-stream");
15
+ const getOs = () => {
16
+ const os = node_process_1.platform;
17
+ if (os === "linux")
18
+ return "linux";
19
+ if (os === "darwin")
20
+ return "darwin";
21
+ if (os === "win32")
22
+ return "windows";
23
+ throw new errors_1.CLIError(`Unsupported OS: ${os}`);
24
+ };
25
+ const getArch = () => {
26
+ if (node_process_1.arch === "ia32")
27
+ return "386";
28
+ if (node_process_1.arch === "x64")
29
+ return "amd64";
30
+ if (node_process_1.arch === "arm64")
31
+ return "arm64";
32
+ throw new errors_1.CLIError(`Unsupported Architecture: ${node_process_1.arch}`);
33
+ };
34
+ const getExt = () => (getOs() === "windows" ? "zip" : "tar.gz");
35
+ const baseUrl = "https://autifyconnect.s3.ap-northeast-1.amazonaws.com/autifyconnect/versions/stable";
36
+ const getUrl = () => {
37
+ const os = getOs();
38
+ const arch = getArch();
39
+ const ext = getExt();
40
+ return new URL(`${baseUrl}/autifyconnect_${os}_${arch}.${ext}`);
41
+ };
42
+ const download = async (workspaceDir) => {
43
+ const url = getUrl();
44
+ const downloadPath = (0, node_path_1.join)(workspaceDir, (0, node_path_1.basename)(url.pathname));
45
+ const response = await (0, node_fetch_1.default)(url);
46
+ if (!response.ok)
47
+ throw new errors_1.CLIError(`Failed to fetch ${url}: ${response.status}`);
48
+ const streamPipeline = (0, node_util_1.promisify)(node_stream_1.pipeline);
49
+ await streamPipeline(response.body, (0, node_fs_1.createWriteStream)(downloadPath));
50
+ return downloadPath;
51
+ };
52
+ const extract = async (downloadPath) => {
53
+ const file = (0, node_path_1.basename)(downloadPath);
54
+ const dir = (0, node_path_1.dirname)(downloadPath);
55
+ if (file.endsWith(".tar.gz")) {
56
+ const command = `tar xvzf ${file}`;
57
+ (0, node_child_process_1.execSync)(command, { cwd: dir });
58
+ return (0, node_path_1.join)(dir, "autifyconnect");
59
+ }
60
+ if (file.endsWith(".zip")) {
61
+ const streamPipeline = (0, node_util_1.promisify)(node_stream_1.pipeline);
62
+ await streamPipeline((0, node_fs_1.createReadStream)(downloadPath),
63
+ // eslint-disable-next-line new-cap
64
+ (0, unzip_stream_1.Extract)({ path: dir }));
65
+ return (0, node_path_1.join)(dir, "autifyconnect.exe");
66
+ }
67
+ throw new errors_1.CLIError(`Unsupported file format: ${downloadPath}`);
68
+ };
69
+ const validateVersion = async (path) => {
70
+ try {
71
+ return await (0, exports.getInstallVersion)(path);
72
+ }
73
+ catch (error) {
74
+ throw new errors_1.CLIError(`Autify Connect Client binary doesn't work properly (path: ${path}, error: ${error})`);
75
+ }
76
+ };
77
+ const getWorkspaceDir = (cacheDir) => (0, node_path_1.join)(cacheDir, "autifyconnect-install-workspace");
78
+ const getInstallPath = (cacheDir) => getOs() === "windows"
79
+ ? (0, node_path_1.join)(cacheDir, "autifyconnect.exe")
80
+ : (0, node_path_1.join)(cacheDir, "autifyconnect");
81
+ exports.getInstallPath = getInstallPath;
82
+ const getInstallVersion = async (path) => {
83
+ if (!(0, node_fs_1.existsSync)(path))
84
+ throw new errors_1.CLIError(`Autify Connect Client isn't installed yet at ${path}. Run \`autify connect client install\` first.`);
85
+ const { stderr } = await (0, node_util_1.promisify)(node_child_process_1.exec)(`${path} --version`);
86
+ const version = stderr.trim();
87
+ if (version === "")
88
+ throw new errors_1.CLIError("Version is empty");
89
+ return version;
90
+ };
91
+ exports.getInstallVersion = getInstallVersion;
92
+ const installClient = async (cacheDir) => {
93
+ const workspaceDir = getWorkspaceDir(cacheDir);
94
+ // Clean up workspace in case something is left by previous command.
95
+ if ((0, node_fs_1.existsSync)(workspaceDir))
96
+ (0, node_fs_1.rmSync)(workspaceDir, { recursive: true, force: true });
97
+ (0, node_fs_1.mkdirSync)(workspaceDir);
98
+ const downloadPath = await download(workspaceDir);
99
+ const extractPath = await extract(downloadPath);
100
+ // Pre-install validation
101
+ await validateVersion(extractPath);
102
+ const installPath = (0, exports.getInstallPath)(cacheDir);
103
+ (0, node_fs_1.renameSync)(extractPath, installPath);
104
+ const version = await validateVersion(installPath);
105
+ // Clean up workspace. Ignore any exception as install is already done.
106
+ try {
107
+ (0, node_fs_1.rmSync)(workspaceDir, { recursive: true, force: true });
108
+ }
109
+ catch (error) {
110
+ console.error(`Workspace clean up failed. Ignoring because already installed. (error: ${error})`);
111
+ }
112
+ return {
113
+ version,
114
+ path: installPath,
115
+ };
116
+ };
117
+ exports.installClient = installClient;
@@ -0,0 +1,25 @@
1
+ /// <reference types="node" />
2
+ import { WebClient } from "@autifyhq/autify-sdk";
3
+ declare type EphemeralAccessPoint = Readonly<{
4
+ webClient: WebClient;
5
+ workspaceId: number;
6
+ }>;
7
+ declare type ProcessExit = [code: number | null, signal: NodeJS.Signals | null];
8
+ export declare type AutifyConnectClient = Readonly<{
9
+ version: string;
10
+ logFile?: string;
11
+ accessPointName: string;
12
+ kill: () => void;
13
+ waitReady: () => Promise<any[]>;
14
+ waitExit: () => Promise<[
15
+ ...ProcessExit,
16
+ ...[deletedAccessPointName?: string]
17
+ ]>;
18
+ }>;
19
+ declare type SpawnClientOptions = Readonly<{
20
+ verbose?: boolean;
21
+ fileLogging?: boolean;
22
+ ephemeralAccessPoint?: EphemeralAccessPoint;
23
+ }>;
24
+ export declare const spawnClient: (configDir: string, cacheDir: string, { verbose, fileLogging, ephemeralAccessPoint }: SpawnClientOptions) => Promise<AutifyConnectClient>;
25
+ export {};
@@ -0,0 +1,115 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.spawnClient = void 0;
4
+ /* eslint-disable unicorn/filename-case */
5
+ const errors_1 = require("@oclif/errors");
6
+ const node_child_process_1 = require("node:child_process");
7
+ const installClient_1 = require("./installClient");
8
+ const node_readline_1 = require("node:readline");
9
+ const node_events_1 = require("node:events");
10
+ const winston_1 = require("winston");
11
+ const node_path_1 = require("node:path");
12
+ const config_1 = require("../../config");
13
+ const uuid_1 = require("uuid");
14
+ const EPHEMERAL_ACCESS_POINT_NAME_PREFIX = "autify-cli-";
15
+ const logger = (0, winston_1.createLogger)({
16
+ level: "debug",
17
+ });
18
+ const getOrCreateAccessPoint = async (configDir, ephemeralAccessPoint) => {
19
+ if (!ephemeralAccessPoint) {
20
+ const accessPointName = (0, config_1.get)(configDir, "AUTIFY_CONNECT_ACCESS_POINT_NAME");
21
+ const accessPointKey = (0, config_1.get)(configDir, "AUTIFY_CONNECT_ACCESS_POINT_KEY");
22
+ if (!accessPointName || !accessPointKey)
23
+ throw new errors_1.CLIError("Access Point is not set. Run `autify connect access-point set` first.");
24
+ return { accessPointName, accessPointKey };
25
+ }
26
+ const { webClient, workspaceId } = ephemeralAccessPoint;
27
+ const accessPointName = `${EPHEMERAL_ACCESS_POINT_NAME_PREFIX}${(0, uuid_1.v4)()}`;
28
+ const accessPointKey = (await webClient.createAccessPoint(workspaceId, { name: accessPointName })).data.key;
29
+ return { accessPointName, accessPointKey };
30
+ };
31
+ const deleteAccessPointIfPossible = async (accessPointName, ephemeralAccessPoint) => {
32
+ if (!ephemeralAccessPoint)
33
+ return;
34
+ if (!accessPointName.startsWith(EPHEMERAL_ACCESS_POINT_NAME_PREFIX))
35
+ return;
36
+ const { webClient, workspaceId } = ephemeralAccessPoint;
37
+ try {
38
+ await webClient.deleteAccessPoint(workspaceId, { name: accessPointName });
39
+ return accessPointName;
40
+ }
41
+ catch {
42
+ // Ignore errors since this is best effort.
43
+ }
44
+ };
45
+ const logFormat = (prefix) => winston_1.format.combine(winston_1.format.colorize(), winston_1.format.timestamp(), winston_1.format.align(), winston_1.format.printf(({ timestamp, level, message }) => `${prefix !== null && prefix !== void 0 ? prefix : ""}${timestamp} ${level} ${message}`));
46
+ const setupLogger = (logFile) => {
47
+ if (logFile) {
48
+ logger.add(new winston_1.transports.File({
49
+ filename: logFile,
50
+ format: logFormat(),
51
+ }));
52
+ }
53
+ else {
54
+ logger.add(new winston_1.transports.Console({
55
+ format: logFormat("[Autify Connect Client] "),
56
+ }));
57
+ }
58
+ };
59
+ const onLogMsg = (input, handler) => {
60
+ return (0, node_readline_1.createInterface)({
61
+ input,
62
+ crlfDelay: Number.POSITIVE_INFINITY,
63
+ }).on("line", (line) => {
64
+ let msg = line;
65
+ try {
66
+ const log = JSON.parse(line);
67
+ msg = log.msg;
68
+ logger.log(log.level, log.msg);
69
+ }
70
+ finally {
71
+ handler(msg);
72
+ }
73
+ });
74
+ };
75
+ const spawnClient = async (configDir, cacheDir, { verbose, fileLogging, ephemeralAccessPoint }) => {
76
+ const state = new node_events_1.EventEmitter();
77
+ const clientPath = (0, installClient_1.getInstallPath)(cacheDir);
78
+ const args = ["--log-format", "json"];
79
+ if (verbose)
80
+ args.push("--verbose");
81
+ const version = await (0, installClient_1.getInstallVersion)(clientPath);
82
+ const { accessPointName, accessPointKey } = await getOrCreateAccessPoint(configDir, ephemeralAccessPoint);
83
+ const childProcess = (0, node_child_process_1.spawn)(clientPath, args, {
84
+ env: {
85
+ AUTIFY_CONNECT_KEY: accessPointKey,
86
+ },
87
+ });
88
+ const logFile = fileLogging
89
+ ? (0, node_path_1.join)(cacheDir, `autifyconnect-${Date.now()}-${childProcess.pid}.log`)
90
+ : undefined;
91
+ setupLogger(logFile);
92
+ process.on("SIGINT", childProcess.kill);
93
+ process.on("SIGTERM", childProcess.kill);
94
+ const clientReady = (0, node_events_1.once)(state, "ready");
95
+ const childProcessExit = (0, node_events_1.once)(childProcess, "exit");
96
+ childProcess.stderr.pipe(process.stderr);
97
+ onLogMsg(childProcess.stdout, (msg) => {
98
+ if (msg.includes("Successfully connected")) {
99
+ state.emit("ready");
100
+ }
101
+ });
102
+ return {
103
+ version,
104
+ logFile,
105
+ accessPointName,
106
+ kill: () => childProcess.kill(),
107
+ waitReady: async () => clientReady,
108
+ waitExit: async () => {
109
+ const [code, signal] = await childProcessExit;
110
+ const deletedAccessPointName = await deleteAccessPointIfPossible(accessPointName, ephemeralAccessPoint);
111
+ return [code, signal, deletedAccessPointName];
112
+ },
113
+ };
114
+ };
115
+ exports.spawnClient = spawnClient;
@@ -6,17 +6,12 @@ const tslib_1 = require("tslib");
6
6
  const errors_1 = require("@oclif/errors");
7
7
  const node_child_process_1 = require("node:child_process");
8
8
  const node_fs_1 = require("node:fs");
9
- const node_os_1 = require("node:os");
10
9
  const node_path_1 = require("node:path");
11
10
  const which_1 = tslib_1.__importDefault(require("which"));
12
11
  const tsimportlib_1 = require("tsimportlib");
13
- const checkPlatform = () => {
14
- const supportedPlatforms = ["linux", "darwin"];
15
- const p = (0, node_os_1.platform)();
16
- if (!supportedPlatforms.includes(p)) {
17
- throw new errors_1.CLIError(`${p} is not supported to zip file. Only supports: ${supportedPlatforms}`);
18
- }
19
- };
12
+ const archiver_1 = tslib_1.__importDefault(require("archiver"));
13
+ const node_events_1 = require("node:events");
14
+ const node_stream_zip_1 = tslib_1.__importDefault(require("node-stream-zip"));
20
15
  const checkBuildPath = (buildPath) => {
21
16
  if (!(0, node_fs_1.lstatSync)(buildPath).isDirectory()) {
22
17
  throw new errors_1.CLIError(`Build path (${buildPath}) is expected to directory.`);
@@ -25,23 +20,35 @@ const checkBuildPath = (buildPath) => {
25
20
  const name = (0, node_path_1.basename)(buildPath);
26
21
  return [parentPath, name];
27
22
  };
28
- const findZip = () => {
29
- const zip = which_1.default.sync("zip", { nothrow: true });
30
- if (!zip) {
31
- throw new errors_1.CLIError("Can't find zip command in PATH.");
32
- }
33
- return zip;
34
- };
23
+ const findZip = () => which_1.default.sync("zip", { nothrow: true });
35
24
  const createZip = async (buildPath) => {
36
- checkPlatform();
37
25
  const [parentPath, name] = checkBuildPath(buildPath);
38
- const zip = findZip();
39
26
  const { temporaryFile } = (await (0, tsimportlib_1.dynamicImport)("tempy",
40
27
  // eslint-disable-next-line unicorn/prefer-module
41
28
  module));
42
29
  const zipFile = temporaryFile({ name: "build.zip" });
43
- // TODO: Use JSZip.
44
- (0, node_child_process_1.execFileSync)(zip, ["-r", zipFile, name], { cwd: parentPath });
30
+ const zip = findZip();
31
+ if (zip) {
32
+ (0, node_child_process_1.execFileSync)(zip, ["-r", zipFile, name], { cwd: parentPath });
33
+ }
34
+ else {
35
+ const archive = (0, archiver_1.default)("zip");
36
+ const output = (0, node_fs_1.createWriteStream)(zipFile);
37
+ const close = (0, node_events_1.once)(output, "close");
38
+ archive.pipe(output);
39
+ archive.directory(buildPath, name);
40
+ await archive.finalize();
41
+ await close;
42
+ }
43
+ // Ensure zip file is valid.
44
+ try {
45
+ // eslint-disable-next-line new-cap
46
+ const zipStream = new node_stream_zip_1.default.async({ file: zipFile });
47
+ await zipStream.close();
48
+ }
49
+ catch (error) {
50
+ throw new errors_1.CLIError(`Failed to create a valid zip file (${zipFile}): ${error}`);
51
+ }
45
52
  return zipFile;
46
53
  };
47
54
  exports.createZip = createZip;
@@ -0,0 +1,11 @@
1
+ export declare type TestScenario = Readonly<{
2
+ workspaceId: number;
3
+ testScenarioId: number;
4
+ testPlanId?: never;
5
+ }>;
6
+ export declare type TestPlan = Readonly<{
7
+ workspaceId: number;
8
+ testScenarioId?: never;
9
+ testPlanId: number;
10
+ }>;
11
+ export declare const parseAutifyTestUrl: (url: string) => TestScenario | TestPlan;
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseAutifyTestUrl = void 0;
4
+ /* eslint-disable unicorn/filename-case */
5
+ const errors_1 = require("@oclif/errors");
6
+ const parseTestScenarioUrl = (url) => {
7
+ var _a, _b, _c, _d;
8
+ const { pathname } = new URL(url);
9
+ const scenarioUrlPathRegExp = /\/projects\/(?<workspaceId>\d+)\/scenarios\/(?<scenarioId>\d+)/;
10
+ const match = scenarioUrlPathRegExp.exec(pathname);
11
+ const workspaceId = Number.parseInt((_b = (_a = match === null || match === void 0 ? void 0 : match.groups) === null || _a === void 0 ? void 0 : _a.workspaceId) !== null && _b !== void 0 ? _b : "", 10);
12
+ const testScenarioId = Number.parseInt((_d = (_c = match === null || match === void 0 ? void 0 : match.groups) === null || _c === void 0 ? void 0 : _c.scenarioId) !== null && _d !== void 0 ? _d : "", 10);
13
+ if (!workspaceId || !testScenarioId)
14
+ return;
15
+ return { workspaceId, testScenarioId };
16
+ };
17
+ const parseTestPlanUrl = (url) => {
18
+ var _a, _b, _c, _d;
19
+ const { pathname } = new URL(url);
20
+ const testPlanUrlPathRegExp = /\/projects\/(?<workspaceId>\d+)\/test_plans\/(?<testPlanId>\d+)/;
21
+ const match = testPlanUrlPathRegExp.exec(pathname);
22
+ const workspaceId = Number.parseInt((_b = (_a = match === null || match === void 0 ? void 0 : match.groups) === null || _a === void 0 ? void 0 : _a.workspaceId) !== null && _b !== void 0 ? _b : "", 10);
23
+ const testPlanId = Number.parseInt((_d = (_c = match === null || match === void 0 ? void 0 : match.groups) === null || _c === void 0 ? void 0 : _c.testPlanId) !== null && _d !== void 0 ? _d : "", 10);
24
+ if (!workspaceId || !testPlanId)
25
+ return;
26
+ return { workspaceId, testPlanId };
27
+ };
28
+ const parseAutifyTestUrl = (url) => {
29
+ const testScenario = parseTestScenarioUrl(url);
30
+ const testPlan = parseTestPlanUrl(url);
31
+ if (testScenario)
32
+ return testScenario;
33
+ if (testPlan)
34
+ return testPlan;
35
+ throw new errors_1.CLIError(`Invalid URL: ${url}`);
36
+ };
37
+ exports.parseAutifyTestUrl = parseAutifyTestUrl;
@@ -1,14 +1,14 @@
1
1
  import { WebClient } from "@autifyhq/autify-sdk";
2
+ import { TestPlan, TestScenario } from "./parseAutifyTestUrl";
2
3
  declare type CapabilityOption = Parameters<WebClient["executeScenarios"]>[1]["capabilities"][number];
3
4
  declare type CreateUrlReplacementRequest = Parameters<WebClient["createUrlReplacement"]>[1];
4
5
  declare type RunTestProps = Readonly<{
5
6
  option: CapabilityOption;
6
7
  name?: string;
7
8
  urlReplacements: CreateUrlReplacementRequest[];
8
- autifyConnect?: string;
9
+ autifyConnectAccessPoint?: string;
9
10
  }>;
10
- export declare const runTest: (client: WebClient, url: string, { option, name, urlReplacements, autifyConnect }: RunTestProps) => Promise<{
11
- workspaceId: number;
11
+ export declare const runTest: (client: WebClient, parsedTest: TestScenario | TestPlan, { option, name, urlReplacements, autifyConnectAccessPoint }: RunTestProps) => Promise<{
12
12
  resultId: number;
13
13
  capability: string;
14
14
  }>;