@dev-blinq/cucumber_client 1.0.1362-stage → 1.0.1363-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.
@@ -5,6 +5,8 @@ import path from "path";
5
5
  import { CodePage } from "./page_reflection.js";
6
6
  import { convertToIdentifier, escapeNonPrintables } from "./utils.js";
7
7
  import socketLogger from "../utils/socket_logger.js";
8
+ import fs from "fs";
9
+
8
10
  const findElementIdentifier = (node, step, userData, elements) => {
9
11
  if (node.key) {
10
12
  // incase of rerunning implemented steps
@@ -366,7 +368,7 @@ const _generateCodeFromCommand = (step, elements, userData) => {
366
368
  codeLines.push(line);
367
369
  break;
368
370
  }
369
- case Types.VERIFY_PAGE_SNAPSHOT:
371
+ case Types.VERIFY_PAGE_SNAPSHOT: {
370
372
  comment = step.nestFrmLoc
371
373
  ? `// Verify page snapshot ${step.parameters[0]} in the frame ${step.selectors.iframe_src}`
372
374
  : `// Verify page snapshot ${step.parameters[0]}`;
@@ -375,7 +377,24 @@ const _generateCodeFromCommand = (step, elements, userData) => {
375
377
  codeLines.push(line);
376
378
  line = `await context.web.snapshotValidation(frameLocator, _param_0 , _params, ${JSON.stringify(options)}, this);`;
377
379
  codeLines.push(line);
380
+
381
+ const data = step.data;
382
+ if (data) {
383
+ try {
384
+ const { snapshot, fileName, filePath } = data;
385
+ const folderPath = process.env.BVT_TEMP_SNAPSHOTS_FOLDER ?? filePath;
386
+ const filePathWithName = path.join(folderPath, fileName);
387
+ if (!fs.existsSync(folderPath)) {
388
+ fs.mkdirSync(folderPath, { recursive: true });
389
+ }
390
+ fs.writeFileSync(filePathWithName, snapshot, "utf-8");
391
+ } catch (e) {
392
+ console.log(`Error saving snapshot file: ${e}`);
393
+ throw e;
394
+ }
395
+ }
378
396
  break;
397
+ }
379
398
  case Types.VERIFY_PAGE_CONTAINS_TEXT:
380
399
  line = "await context.web.verifyTextExistInPage( ";
381
400
  input = `${escapeNonPrintables(JSON.stringify(step.parameters[0]))}`;
@@ -4,7 +4,7 @@ import { existsSync, readdirSync, readFileSync, rmSync } from "fs";
4
4
  import path from "path";
5
5
  import url from "url";
6
6
  import { getImplementedSteps, parseRouteFiles } from "./implemented_steps.js";
7
- import { NamesService } from "./services.js";
7
+ import { NamesService, PublishService } from "./services.js";
8
8
  import { BVTStepRunner } from "./step_runner.js";
9
9
  import { readFile, writeFile } from "fs/promises";
10
10
  import { updateStepDefinitions, loadStepDefinitions, getCommandsForImplementedStep } from "./step_utils.js";
@@ -197,6 +197,7 @@ export class BVTRecorder {
197
197
  projectDir: this.projectDir,
198
198
  logger: this.logger,
199
199
  });
200
+ this.workspaceService = new PublishService(this.TOKEN);
200
201
  this.pageSet = new Set();
201
202
  this.pageMetaDataSet = new Set();
202
203
  this.lastKnownUrlPath = "";
@@ -204,6 +205,10 @@ export class BVTRecorder {
204
205
  this.shouldTakeScreenshot = true;
205
206
  this.watcher = null;
206
207
  this.networkEventsFolder = path.join(tmpdir(), "blinq_network_events");
208
+
209
+ this.tempProjectFolder = `${tmpdir()}/bvt_temp_project_${Math.floor(Math.random() * 1000000)}`;
210
+ this.tempSnapshotsFolder = path.join(this.tempProjectFolder, "data/snapshots");
211
+
207
212
  if (existsSync(this.networkEventsFolder)) {
208
213
  rmSync(this.networkEventsFolder, { recursive: true, force: true });
209
214
  }
@@ -912,6 +917,8 @@ export class BVTRecorder {
912
917
  TEMP_RUN: true,
913
918
  REPORT_FOLDER: this.bvtContext.reportFolder,
914
919
  BLINQ_ENV: this.envName,
920
+ DEBUG: "blinq:route",
921
+ BVT_TEMP_SNAPSHOTS_FOLDER: this.tempSnapshotsFolder,
915
922
  };
916
923
 
917
924
  this.bvtContext.navigate = true;
@@ -958,10 +965,23 @@ export class BVTRecorder {
958
965
  this.bvtContext.navigate = false;
959
966
  }
960
967
  }
961
- async saveScenario({ scenario, featureName, override, isSingleStep }) {
962
- await updateStepDefinitions({ scenario, featureName, projectDir: this.projectDir }); // updates mjs files
963
- if (!isSingleStep) await updateFeatureFile({ featureName, scenario, override, projectDir: this.projectDir }); // updates gherkin files
964
- await this.cleanup({ tags: scenario.tags });
968
+ async saveScenario({ scenario, featureName, override, isSingleStep, branch, isEditing }) {
969
+ // await updateStepDefinitions({ scenario, featureName, projectDir: this.projectDir }); // updates mjs files
970
+ // if (!isSingleStep) await updateFeatureFile({ featureName, scenario, override, projectDir: this.projectDir }); // updates gherkin files
971
+ const res = await this.workspaceService.saveScenario({
972
+ scenario,
973
+ featureName,
974
+ override,
975
+ isSingleStep,
976
+ branch,
977
+ isEditing,
978
+ projectId: path.basename(this.projectDir),
979
+ });
980
+ if (res.success) {
981
+ await this.cleanup({ tags: scenario.tags });
982
+ } else {
983
+ throw new Error(res.message || "Error saving scenario");
984
+ }
965
985
  }
966
986
  async getImplementedSteps() {
967
987
  const stepsAndScenarios = await getImplementedSteps(this.projectDir);
@@ -149,3 +149,65 @@ export class NamesService {
149
149
  return result.data;
150
150
  }
151
151
  }
152
+ export class PublishService {
153
+ constructor(TOKEN) {
154
+ this.TOKEN = TOKEN;
155
+ }
156
+ async saveScenario({ scenario, featureName, override, branch, isEditing, projectId }) {
157
+ const url = path.join(`${getRunsServiceBaseURL()}`, "..", "workspace/publish-recording");
158
+ const result = await axiosClient({
159
+ url,
160
+ method: "POST",
161
+ data: {
162
+ scenario,
163
+ featureName,
164
+ override,
165
+ },
166
+ params: {
167
+ branch,
168
+ },
169
+ headers: {
170
+ Authorization: `Bearer ${this.TOKEN}`,
171
+ "X-Source": "recorder",
172
+ },
173
+ });
174
+ if (result.status !== 200) {
175
+ return { success: false, message: "Error while saving scenario" };
176
+ }
177
+ try {
178
+ this.updateProjectMetadata({
179
+ featureName,
180
+ scenarioName: scenario.name,
181
+ projectId,
182
+ branch,
183
+ isEditing,
184
+ });
185
+ } catch (error) {
186
+ // log the error but do not block the scenario saving
187
+ }
188
+ return { success: true, data: result.data };
189
+ }
190
+ async updateProjectMetadata({ featureName, scenarioName, projectId, branch, isEditing }) {
191
+ try {
192
+ await axiosClient({
193
+ method: "POST",
194
+ url: `${getRunsServiceBaseURL()}/project/updateProjectMetadata`,
195
+ data: {
196
+ featureName,
197
+ scenarioName,
198
+ eventType: isEditing ? "editScenario" : "createScenario",
199
+ projectId,
200
+ branch: branch,
201
+ },
202
+ headers: {
203
+ Authorization: `Bearer ${this.TOKEN}`,
204
+ "X-Source": "recorder",
205
+ },
206
+ });
207
+ } catch (error) {
208
+ // logger.error("Failed to update project metadata: " + error.message);
209
+ // @ts-ignore
210
+ console.error("run_recorder", `Failed to update project metadata: ${error.message ?? error}`);
211
+ }
212
+ }
213
+ }
@@ -296,6 +296,7 @@ const _toRecordingStep = (cmd) => {
296
296
  type: "verify_page_snapshot",
297
297
  parameters: [cmd.value],
298
298
  selectors: cmd.selectors,
299
+ data: cmd.data,
299
300
  };
300
301
  }
301
302
  default: {
@@ -73,7 +73,7 @@ const SocketLogger = (function () {
73
73
  {
74
74
  level: level,
75
75
  context: context || defaultContext,
76
- data: data,
76
+ data: JSON.stringify(data),
77
77
  timestamp: new Date().toISOString(),
78
78
  dataSize: dataSize,
79
79
  },
package/bin/index.js CHANGED
@@ -16,3 +16,6 @@ export * from "./client/profiler.js";
16
16
  export * from "./client/code_cleanup/utils.js";
17
17
 
18
18
  export * from "./client/code_cleanup/find_step_definition_references.js";
19
+
20
+ export * from "./client/recorderv3/step_utils.js";
21
+ export * from "./client/recorderv3/update_feature.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dev-blinq/cucumber_client",
3
- "version": "1.0.1362-stage",
3
+ "version": "1.0.1363-stage",
4
4
  "description": " ",
5
5
  "main": "bin/index.js",
6
6
  "types": "bin/index.d.ts",