@dev-blinq/cucumber_client 1.0.1312-dev → 1.0.1313-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.
@@ -1,4 +1,4 @@
1
- import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
1
+ import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "fs";
2
2
  import path from "path";
3
3
  import url from "url";
4
4
  import logger from "../../logger.js";
@@ -9,6 +9,8 @@ import { Step } from "../cucumber/feature.js";
9
9
  import { locateDefinitionPath, StepsDefinitions } from "../cucumber/steps_definitions.js";
10
10
  import { Recording } from "../recording.js";
11
11
  import { generateApiCode } from "../code_gen/api_codegen.js";
12
+ import { tmpdir } from "os";
13
+ import { createHash } from "crypto";
12
14
 
13
15
  const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
14
16
 
@@ -69,10 +71,35 @@ function makeStepTextUnique(step, stepsDefinitions) {
69
71
  }
70
72
 
71
73
  export async function saveRecording({ step, cucumberStep, codePage, projectDir, stepsDefinitions }) {
72
- // console.log("saveRecording", step.text);
74
+ let routesPath = path.join(tmpdir(), "blinq_temp_routes");
75
+
76
+ if (process.env.TEMP_RUN) {
77
+ if (existsSync(routesPath)) {
78
+ rmSync(routesPath, { recursive: true });
79
+ }
80
+ mkdirSync(routesPath, { recursive: true });
81
+ saveRoutes({ step, folderPath: routesPath });
82
+ } else {
83
+ if (existsSync(routesPath)) {
84
+ // remove the folder
85
+ try {
86
+ rmSync(routesPath, { recursive: true });
87
+ console.log("Removed temp_routes_folder:", routesPath);
88
+ } catch (error) {
89
+ console.error("Error removing temp_routes folder", error);
90
+ }
91
+ routesPath = path.join(projectDir, "data", "routes");
92
+ if (!existsSync(routesPath)) {
93
+ mkdirSync(routesPath, { recursive: true });
94
+ }
95
+ saveRoutes({ step, folderPath: routesPath });
96
+ }
97
+ }
98
+
73
99
  if (step.isImplementedWhileRecording && !process.env.TEMP_RUN) {
74
100
  return;
75
101
  }
102
+
76
103
  if (step.isImplemented && step.shouldOverride) {
77
104
  let stepDef = stepsDefinitions.findMatchingStep(step.text);
78
105
  codePage = getCodePage(stepDef.file);
@@ -82,6 +109,7 @@ export async function saveRecording({ step, cucumberStep, codePage, projectDir,
82
109
  return;
83
110
  }
84
111
  }
112
+
85
113
  cucumberStep.text = step.text;
86
114
  const recording = new Recording();
87
115
  const steps = step.commands;
@@ -108,6 +136,7 @@ export async function saveRecording({ step, cucumberStep, codePage, projectDir,
108
136
  isStaticToken,
109
137
  status,
110
138
  } = step.commands[0].value;
139
+
111
140
  const result = await generateApiCode(
112
141
  {
113
142
  url,
@@ -132,6 +161,7 @@ export async function saveRecording({ step, cucumberStep, codePage, projectDir,
132
161
  step.keyword,
133
162
  stepsDefinitions
134
163
  );
164
+
135
165
  if (!step.isImplemented) {
136
166
  stepsDefinitions.addStep({
137
167
  name: step.text,
@@ -139,6 +169,7 @@ export async function saveRecording({ step, cucumberStep, codePage, projectDir,
139
169
  source: "recorder",
140
170
  });
141
171
  }
172
+
142
173
  cucumberStep.methodName = result.methodName;
143
174
  return result.codePage;
144
175
  } else {
@@ -345,3 +376,40 @@ export async function updateStepDefinitions({ scenario, featureName, projectDir
345
376
  }
346
377
  writeFileSync(utilsFilePath, utilsContent, "utf8");
347
378
  }
379
+
380
+ export function saveRoutes({ step, folderPath }) {
381
+ const routeItems = step.routeItems;
382
+ if (!routeItems || routeItems.length === 0) {
383
+ return;
384
+ }
385
+ const cucumberStep = getCucumberStep({ step });
386
+ const template = cucumberStep.getTemplate();
387
+ const stepNameHash = createHash("sha256").update(template).digest("hex");
388
+ const routeItemsWithFilters = routeItems.map((routeItem) => {
389
+ const oldFilters = routeItem.filters;
390
+ const queryParamsObject = {};
391
+ oldFilters.queryParams.forEach((queryParam) => {
392
+ queryParamsObject[queryParam.key] = queryParam.value;
393
+ });
394
+ const newFilters = { path: oldFilters.path, method: oldFilters.method, queryParams: queryParamsObject };
395
+ return {
396
+ ...routeItem,
397
+ filters: newFilters,
398
+ };
399
+ });
400
+
401
+ const routesFilePath = path.join(folderPath, stepNameHash + ".json");
402
+ const routesData = {
403
+ template,
404
+ routes: routeItemsWithFilters,
405
+ };
406
+ if (!existsSync(folderPath)) {
407
+ mkdirSync(folderPath, { recursive: true });
408
+ }
409
+ try {
410
+ writeFileSync(routesFilePath, JSON.stringify(routesData, null, 2), "utf8");
411
+ console.log("Saved routes to", routesFilePath);
412
+ } catch (error) {
413
+ console.error("Failed to save routes to", routesFilePath, "Error:", error);
414
+ }
415
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dev-blinq/cucumber_client",
3
- "version": "1.0.1312-dev",
3
+ "version": "1.0.1313-dev",
4
4
  "description": "",
5
5
  "main": "bin/index.js",
6
6
  "types": "bin/index.d.ts",
@@ -32,7 +32,7 @@
32
32
  "@cucumber/tag-expressions": "^6.1.1",
33
33
  "@dev-blinq/cucumber-js": "1.0.177-dev",
34
34
  "@faker-js/faker": "^8.1.0",
35
- "automation_model": "1.0.773-dev",
35
+ "automation_model": "1.0.774-dev",
36
36
  "axios": "^1.7.4",
37
37
  "chokidar": "^3.6.0",
38
38
  "create-require": "^1.1.1",