@dev-blinq/cucumber_client 1.0.1464-stage → 1.0.1465-stage

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.
@@ -4,8 +4,10 @@ import { compareWithScenario } from "../code_gen/duplication_analysis.js";
4
4
  import { getAppDataDir } from "../utils/app_dir.js";
5
5
  import { readdir } from "fs/promises";
6
6
  import socketLogger, { getErrorMessage, responseSize } from "../utils/socket_logger.js";
7
+ import { MIXPANEL_EVENTS, mixpanelTrackEvent } from "./mixpanel.js";
7
8
  const port = process.env.EDITOR_PORT || 3003;
8
9
  const WS_URL = process.env.WORKER_WS_SERVER_URL || "http://localhost:" + port;
10
+ const userId = process.env.USER_ID || "";
9
11
  const SocketIOEvents = {
10
12
  REQUEST: "request",
11
13
  RESPONSE: "response",
@@ -94,6 +96,7 @@ async function BVTRecorderInit({ envName, projectDir, roomId, TOKEN, socket = nu
94
96
  socket.emit(event, data, roomId);
95
97
  },
96
98
  logger: socketLogger,
99
+ userId,
97
100
  });
98
101
  // emit connected event for every 50 ms until connection_ack message is recieved
99
102
  let connected = false;
@@ -106,6 +109,7 @@ async function BVTRecorderInit({ envName, projectDir, roomId, TOKEN, socket = nu
106
109
  }, 50);
107
110
  const promisifiedSocketServer = new PromisifiedSocketServer(socket, {
108
111
  "recorderWindow.connectionAck": async (input) => {
112
+ mixpanelTrackEvent(MIXPANEL_EVENTS.RECORDER_CONNECTED, userId);
109
113
  connected = true;
110
114
  clearInterval(interval);
111
115
  },
@@ -113,6 +117,7 @@ async function BVTRecorderInit({ envName, projectDir, roomId, TOKEN, socket = nu
113
117
  return recorder
114
118
  .openBrowser(input)
115
119
  .then(() => {
120
+ mixpanelTrackEvent(MIXPANEL_EVENTS.CHROMIUM_LOADED, userId);
116
121
  socketLogger.info("BVTRecorder.browserOpened");
117
122
  socket.emit("BVTRecorder.browserOpened", { roomId, window: "cucumber_client/bvt_recorder" });
118
123
  })
@@ -295,7 +300,7 @@ async function BVTRecorderInit({ envName, projectDir, roomId, TOKEN, socket = nu
295
300
  },
296
301
  "recorderWindow.generateLocatorSummaries": async (input) => {
297
302
  return await recorder.generateLocatorSummaries(input);
298
- }
303
+ },
299
304
  });
300
305
  socket.on("targetBrowser.command.event", async (input) => {
301
306
  return recorder.onAction(input);
@@ -7,7 +7,7 @@ import { getImplementedSteps, parseRouteFiles } from "./implemented_steps.js";
7
7
  import { NamesService, PublishService } from "./services.js";
8
8
  import { BVTStepRunner } from "./step_runner.js";
9
9
  import { readFile, rm, writeFile } from "node:fs/promises";
10
- import { loadStepDefinitions, getCommandsForImplementedStep, _toRecordingStep, getCucumberStep, getCodePage, toMethodName } from "./step_utils.js";
10
+ import { loadStepDefinitions, getCommandsForImplementedStep, _toRecordingStep, getCucumberStep, getCodePage, toMethodName, } from "./step_utils.js";
11
11
  import { parseStepTextParameters } from "../cucumber/utils.js";
12
12
  import { AstBuilder, GherkinClassicTokenMatcher, Parser } from "@cucumber/gherkin";
13
13
  import chokidar from "chokidar";
@@ -20,6 +20,7 @@ import { chromium } from "playwright-core";
20
20
  import { axiosClient } from "../utils/axiosClient.js";
21
21
  import { _generateCodeFromCommand } from "../code_gen/playwright_codeget.js";
22
22
  import { Recording } from "../recording.js";
23
+ import { MIXPANEL_EVENTS, mixpanelTrackEvent } from "./mixpanel.js";
23
24
  const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
24
25
  const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
25
26
  export function getInitScript(config, options) {
@@ -188,6 +189,7 @@ export class BVTRecorder {
188
189
  TOKEN;
189
190
  sendEvent;
190
191
  logger;
192
+ userId;
191
193
  screenshotMap = new Map();
192
194
  snapshotMap = new Map();
193
195
  scenariosStepsMap = new Map();
@@ -232,6 +234,7 @@ export class BVTRecorder {
232
234
  this.TOKEN = initialState.TOKEN;
233
235
  this.sendEvent = initialState.sendEvent;
234
236
  this.logger = initialState.logger;
237
+ this.userId = initialState.userId;
235
238
  this.namesService = new NamesService({
236
239
  screenshotMap: this.screenshotMap,
237
240
  TOKEN: this.TOKEN,
@@ -801,6 +804,7 @@ export class BVTRecorder {
801
804
  // const
802
805
  }
803
806
  async onAction(event) {
807
+ mixpanelTrackEvent(MIXPANEL_EVENTS.STEP_IN_SCENARIO, this.userId);
804
808
  this._updateUrlPath();
805
809
  // const locators = this.overlayLocators(event);
806
810
  const cmdEvent = {
@@ -978,7 +982,7 @@ export class BVTRecorder {
978
982
  envPath: this.envName,
979
983
  tags,
980
984
  config: this.config,
981
- AICode
985
+ AICode,
982
986
  }, this.bvtContext, {
983
987
  skipAfter,
984
988
  skipBefore,
@@ -1227,9 +1231,9 @@ export class BVTRecorder {
1227
1231
  datasets,
1228
1232
  };
1229
1233
  }
1230
- async generateLocatorSummaries({ allStrategyLocators, element_name }) {
1234
+ async generateLocatorSummaries({ allStrategyLocators, element_name, }) {
1231
1235
  const input = {
1232
- [element_name ?? "element"]: allStrategyLocators
1236
+ [element_name ?? "element"]: allStrategyLocators,
1233
1237
  };
1234
1238
  const result = await this.namesService.generateLocatorDescriptions({ locatorsObj: input });
1235
1239
  return result[element_name ?? "element"];
@@ -0,0 +1,39 @@
1
+ import mixpanel from "mixpanel";
2
+ let mixpanelClient = null;
3
+ let mixPaneltoken = getMixpanelToken();
4
+ function getMixpanelToken() {
5
+ if (process.env.MIXPANEL_TOKEN) {
6
+ const token = process.env.MIXPANEL_TOKEN;
7
+ delete process.env.MIXPANEL_TOKEN;
8
+ return token;
9
+ }
10
+ return null;
11
+ }
12
+ if (mixPaneltoken && process.env.NODE_ENV_BLINQ === "prod") {
13
+ mixpanelClient = mixpanel.init(mixPaneltoken, {
14
+ debug: true,
15
+ });
16
+ console.log("✅Mixpanel client initialized.");
17
+ }
18
+ else {
19
+ console.info("MIXPANEL_TOKEN is not defined.");
20
+ }
21
+ export function mixpanelTrackEvent(event, distinctId, properties = {}) {
22
+ if (mixpanelClient === null)
23
+ return;
24
+ mixpanelClient.track(event, {
25
+ distinct_id: distinctId,
26
+ env: process.env.NODE_ENV_BLINQ || "local",
27
+ ...properties,
28
+ });
29
+ }
30
+ export function mixpanelTrackEventIdentifyUser(distinctId, properties = {}) {
31
+ if (mixpanelClient === null)
32
+ return;
33
+ mixpanelClient.people.set(distinctId, properties);
34
+ }
35
+ export const MIXPANEL_EVENTS = {
36
+ STEP_IN_SCENARIO: "There is a step in the scenario",
37
+ RECORDER_CONNECTED: "Recorder session initiated",
38
+ CHROMIUM_LOADED: "Chromium loaded",
39
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dev-blinq/cucumber_client",
3
- "version": "1.0.1464-stage",
3
+ "version": "1.0.1465-stage",
4
4
  "description": " ",
5
5
  "main": "bin/index.js",
6
6
  "types": "bin/index.d.ts",
@@ -50,6 +50,7 @@
50
50
  "http-proxy-agent": "^7.0.0",
51
51
  "https-proxy-agent": "^7.0.2",
52
52
  "jszip": "^3.10.1",
53
+ "mixpanel": "^0.20.0",
53
54
  "node-source-walk": "^6.0.2",
54
55
  "object-path": "^0.11.8",
55
56
  "open": "^10.1.0",