@dev-blinq/cucumber_client 1.0.1547-dev → 1.0.1549-dev

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.
@@ -144,7 +144,7 @@ class BVTRecorder {
144
144
  getAction: (e) => {
145
145
  this.eventUtils.consumeEvent(e);
146
146
  },
147
- getInterestedElement: () => { },
147
+ getInterestedElement: () => {},
148
148
  hoverOutlineStyle: "",
149
149
  });
150
150
 
@@ -159,7 +159,7 @@ class BVTRecorder {
159
159
  };
160
160
  },
161
161
  getAction: () => null,
162
- getInterestedElement: () => { },
162
+ getInterestedElement: () => {},
163
163
  hoverOutlineStyle: "",
164
164
  });
165
165
 
@@ -174,7 +174,7 @@ class BVTRecorder {
174
174
  };
175
175
  },
176
176
  getAction: () => null,
177
- getInterestedElement: () => { },
177
+ getInterestedElement: () => {},
178
178
  hoverOutlineStyle: "",
179
179
  });
180
180
 
@@ -684,7 +684,7 @@ class BVTRecorder {
684
684
  this.PW.roleUtils.getElementAccessibleName(el, true) ||
685
685
  "";
686
686
  const result = this.getElementProperties(el);
687
- const elText = this.PW.selectorUtils.elementText(new Map(), el)
687
+ const elText = this.PW.selectorUtils.elementText(new Map(), el);
688
688
  return {
689
689
  role,
690
690
  label,
@@ -1,15 +1,30 @@
1
+ /**
2
+ * Validates that a CLI argument is provided.
3
+ * @param {string | undefined | null} arg - The argument value.
4
+ * @param {string} name - The name of the argument.
5
+ * @throws {Error} If the argument is missing.
6
+ */
1
7
  const validateCLIArg = (arg, name) => {
2
- if (!arg) {
3
- throw new Error(`${name} is required`);
4
- }
8
+ if (!arg) {
9
+ throw new Error(`${name} is required`);
10
+ }
5
11
  };
12
+ /**
13
+ * Displays usage information and exits the process.
14
+ * @param {Error} error - The error to display.
15
+ * @param {string} usage - The usage information.
16
+ */
6
17
  const showUsage = (error, usage) => {
7
- console.error(error.message);
8
- console.info(usage);
9
- process.exit(1);
18
+ console.error(error.message);
19
+ console.info(usage);
20
+ process.exit(1);
10
21
  };
22
+ /**
23
+ * Loads CLI arguments.
24
+ * @returns {string[]} The array of CLI arguments.
25
+ */
11
26
  const loadArgs = () => {
12
- const args = process.argv.slice(2);
13
- return args;
27
+ const args = process.argv.slice(2);
28
+ return args;
14
29
  };
15
30
  export { validateCLIArg, loadArgs, showUsage };
@@ -1,5 +1,6 @@
1
1
  import { io } from "socket.io-client";
2
- import { BVTRecorderInit } from "./bvt_init";
2
+ import { BVTRecorderInit } from "./bvt_init.js";
3
+ import { loadArgs, showUsage, validateCLIArg } from "../cli_helpers.js";
3
4
  const requiredEnvVars = ["PROJECT_ID", "BLINQ_TOKEN", "SESSION_ID", "WORKER_WS_SERVER_URL"];
4
5
  function validateEnvVariables() {
5
6
  const missingVars = requiredEnvVars.filter((varName) => !process.env[varName]);
@@ -7,23 +8,48 @@ function validateEnvVariables() {
7
8
  throw new Error(`Missing required environment variables: ${missingVars.join(", ")}`);
8
9
  }
9
10
  }
10
- const socket = io(process.env.WORKER_WS_SERVER_URL, {
11
- path: "/ws",
12
- transports: ["websocket", "polling"],
13
- reconnection: true,
14
- });
15
- function initWebBVTRecorder(socket) {
16
- validateEnvVariables();
17
- const WORKER_WS_SERVER_URL = process.env.WORKER_WS_SERVER_URL;
18
- const PROJECT_ID = process.env.PROJECT_ID;
11
+ function getEnvironmentConfig() {
12
+ const args = loadArgs();
13
+ const projectDir = args[0] || process.env.PROJECT_ID;
14
+ const envName = args[1]?.split("=")[1] || process.env.ENV_NAME;
15
+ const roomId = args[2] || process.env.SESSION_ID;
16
+ const shouldTakeScreenshot = args[3] || process.env.SHOULD_TAKE_SCREENSHOT;
19
17
  const TOKEN = process.env.BLINQ_TOKEN;
20
- const ROOM_ID = process.env.SESSION_ID;
18
+ try {
19
+ validateCLIArg(projectDir, "projectDir");
20
+ validateCLIArg(envName, "envName");
21
+ validateCLIArg(roomId, "roomId");
22
+ validateCLIArg(shouldTakeScreenshot, "shouldTakeScreenshot");
23
+ if (!TOKEN) {
24
+ throw new Error("BLINQ_TOKEN env variable not set");
25
+ }
26
+ }
27
+ catch (error) {
28
+ const usage = `Usage: node bvt_recorder.js <projectDir> <envName> <roomId>`;
29
+ if (error instanceof Error) {
30
+ showUsage(error, usage);
31
+ }
32
+ else {
33
+ const unknownError = new Error("An unknown error occurred");
34
+ showUsage(unknownError, usage);
35
+ }
36
+ }
37
+ return { envName, projectDir, roomId, TOKEN };
38
+ }
39
+ function initWebBVTRecorder() {
40
+ const socket = io(process.env.WORKER_WS_SERVER_URL, {
41
+ path: "/ws",
42
+ transports: ["websocket", "polling"],
43
+ reconnection: true,
44
+ });
45
+ validateEnvVariables();
46
+ const { envName, projectDir, roomId, TOKEN } = getEnvironmentConfig();
21
47
  BVTRecorderInit({
22
- envName: WORKER_WS_SERVER_URL,
23
- projectDir: PROJECT_ID,
24
- roomId: ROOM_ID,
25
- TOKEN: TOKEN,
48
+ envName: envName,
49
+ projectDir,
50
+ roomId,
51
+ TOKEN,
26
52
  socket: socket,
27
53
  });
28
54
  }
29
- initWebBVTRecorder(socket);
55
+ initWebBVTRecorder();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dev-blinq/cucumber_client",
3
- "version": "1.0.1547-dev",
3
+ "version": "1.0.1549-dev",
4
4
  "description": " ",
5
5
  "main": "bin/index.js",
6
6
  "types": "bin/index.d.ts",