@dev-blinq/cucumber_client 1.0.1727-dev → 1.0.1729-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.
@@ -691,7 +691,7 @@ const _generateCodeFromCommand = (step, elements, userData) => {
691
691
  if (step.dataSource === "userData" || step.dataSource === "parameters") {
692
692
  input = "_" + step.dataKey;
693
693
  }
694
- // options = options ?? {};
694
+ options = options ?? {};
695
695
  // options.context = input;
696
696
  line = `await context.web.click(elements["${elementIdentifier}"], _params, ${serializeOptions(options, input)}, this);`;
697
697
  codeLines.push(line);
@@ -716,7 +716,7 @@ const _generateCodeFromCommand = (step, elements, userData) => {
716
716
  if (step.dataSource === "userData" || step.dataSource === "parameters") {
717
717
  input = "_" + step.dataKey;
718
718
  }
719
- // options = options ?? {};
719
+ options = options ?? {};
720
720
  // options.context = input;
721
721
  line = `await context.web.click(elements["${elementIdentifier}"], _params, ${serializeOptions(options, input)}, this);`;
722
722
  codeLines.push(line);
@@ -147,7 +147,7 @@ export class NamesService {
147
147
  }
148
148
  return result.data;
149
149
  }
150
- async generateLocatorDescriptions({ locatorsObj }) {
150
+ async generateLocatorDescriptions({ locatorsObj, }) {
151
151
  const url = `${getRunsServiceBaseURL()}/locate/generate_locator_summaries`;
152
152
  const result = await axiosClient({
153
153
  url,
@@ -172,6 +172,7 @@ export class PublishService {
172
172
  constructor(TOKEN) {
173
173
  this.TOKEN = TOKEN;
174
174
  }
175
+ //! deprecated
175
176
  async saveScenario({ scenario, featureName, override, branch, isEditing, projectId, env, AICode }) {
176
177
  const runsURL = getRunsServiceBaseURL();
177
178
  const workspaceURL = runsURL.replace("/runs", "/workspace");
@@ -863,87 +863,104 @@ export async function executeStep({ stepsDefinitions, cucumberStep, context, cod
863
863
  throw new Error(`Step definition not found for "${cucumberStep.text}"`);
864
864
  }
865
865
  }
866
-
866
+ class DomainError extends Error {
867
+ constructor(message) {
868
+ super(message);
869
+ this.name = this.constructor.name;
870
+ this.statusCode = 500; // default, can override in subclasses
871
+ if (typeof Object.setPrototypeOf === "function") {
872
+ Object.setPrototypeOf(this, new.target.prototype);
873
+ }
874
+ }
875
+ }
867
876
  export async function updateStepDefinitions({ scenario, featureName, projectDir, logger }) {
868
- // set the candidate step definition file name
869
- // set the utils file path
870
- const utilsFilePath = path.join(projectDir, "features", "step_definitions", "utils.mjs");
871
- const stepDefinitionFolderPath = path.join(projectDir, "features", "step_definitions");
872
- if (!existsSync(stepDefinitionFolderPath)) {
873
- mkdirSync(stepDefinitionFolderPath, { recursive: true });
874
- }
875
- const utilsTemplateFilePath = path.join(__dirname, "../../assets", "templates", "utils_template.txt");
876
- const utilsContent = readFileSync(utilsTemplateFilePath, "utf8");
877
- writeFileSync(utilsFilePath, utilsContent, "utf8");
878
- const hooksTemplateFilePath = path.join(__dirname, "../../assets", "templates", "_hooks_template.txt");
879
- if (existsSync(hooksTemplateFilePath)) {
880
- const hooksFilePath = path.join(stepDefinitionFolderPath, "_hooks.mjs");
881
- const hooksContent = readFileSync(hooksTemplateFilePath, "utf8");
882
- writeFileSync(hooksFilePath, hooksContent, "utf8");
883
- }
884
- const steps = scenario.steps;
877
+ try {
878
+ const utilsFilePath = path.join(projectDir, "features", "step_definitions", "utils.mjs");
879
+ const stepDefinitionFolderPath = path.join(projectDir, "features", "step_definitions");
880
+ if (!existsSync(stepDefinitionFolderPath)) {
881
+ mkdirSync(stepDefinitionFolderPath, { recursive: true });
882
+ }
885
883
 
886
- const stepsDefinitions = new StepsDefinitions(projectDir);
887
- const featureFolder = path.join(projectDir, "features");
888
- stepsDefinitions.load(false);
889
- // const parameters = scenario.parameters;
890
- // await saveRecordings({ steps, parameters, codePage, projectDir });
891
- for (const step of steps) {
892
- if (step.internalImplementedStepId) {
893
- const si = steps.findIndex((s) => s.id === step.internalImplementedStepId);
894
- if (si !== -1) {
895
- step.isImplementedWhileRecording = true;
896
- }
884
+ const utilsTemplateFilePath = path.join(__dirname, "../../assets", "templates", "utils_template.txt");
885
+ const utilsContent = readFileSync(utilsTemplateFilePath, "utf8");
886
+ writeFileSync(utilsFilePath, utilsContent, "utf8");
887
+
888
+ const hooksTemplateFilePath = path.join(__dirname, "../../assets", "templates", "_hooks_template.txt");
889
+ if (existsSync(hooksTemplateFilePath)) {
890
+ const hooksFilePath = path.join(stepDefinitionFolderPath, "_hooks.mjs");
891
+ const hooksContent = readFileSync(hooksTemplateFilePath, "utf8");
892
+ writeFileSync(hooksFilePath, hooksContent, "utf8");
897
893
  }
898
- if (!step.isUtilStep && ((step.isImplemented && !step.shouldOverride) || step.commands.length === 0)) {
899
- let routesPath = path.join(tmpdir(), `blinq_temp_routes`);
900
- if (process.env.TEMP_RUN === "true") {
901
- if (existsSync(routesPath)) {
902
- routesPath = path.join(tmpdir(), `blinq_temp_routes`);
903
- rmSync(routesPath, { recursive: true });
894
+
895
+ const steps = scenario.steps;
896
+ const stepsDefinitions = new StepsDefinitions(projectDir);
897
+ const featureFolder = path.join(projectDir, "features");
898
+
899
+ stepsDefinitions.load(false);
900
+
901
+ for (const step of steps) {
902
+ if (step.internalImplementedStepId) {
903
+ const si = steps.findIndex((s) => s.id === step.internalImplementedStepId);
904
+ if (si !== -1) {
905
+ step.isImplementedWhileRecording = true;
904
906
  }
905
- mkdirSync(routesPath, { recursive: true });
906
- saveRoutes({ step, folderPath: routesPath }, logger);
907
- } else {
908
- if (existsSync(routesPath)) {
909
- try {
910
- rmSync(routesPath, { recursive: true });
911
- } catch (error) {
912
- logger.error(`Error removing temp routes folder: ${getErrorMessage(error)}`);
907
+ }
908
+
909
+ if (!step.isUtilStep && ((step.isImplemented && !step.shouldOverride) || step.commands.length === 0)) {
910
+ let routesPath = path.join(tmpdir(), `blinq_temp_routes`);
911
+ if (process.env.TEMP_RUN === "true") {
912
+ if (existsSync(routesPath)) rmSync(routesPath, { recursive: true });
913
+ mkdirSync(routesPath, { recursive: true });
914
+ saveRoutes({ step, folderPath: routesPath }, logger);
915
+ } else {
916
+ if (existsSync(routesPath)) {
917
+ try {
918
+ rmSync(routesPath, { recursive: true });
919
+ } catch (error) {
920
+ logger.error(`❌ Error removing temp routes folder: ${getErrorMessage(error)}`);
921
+ }
913
922
  }
923
+ routesPath = path.join(projectDir, "data", "routes");
924
+ if (!existsSync(routesPath)) mkdirSync(routesPath, { recursive: true });
925
+ saveRoutes({ step, folderPath: routesPath }, logger);
914
926
  }
915
- routesPath = path.join(projectDir, "data", "routes");
916
- if (!existsSync(routesPath)) {
917
- mkdirSync(routesPath, { recursive: true });
927
+
928
+ if (step.commands && Array.isArray(step.commands)) {
929
+ step.commands = step.commands.map((cmd) => toRecordingStep(cmd, scenario.parametersMap));
918
930
  }
919
- saveRoutes({ step, folderPath: routesPath }, logger);
931
+
932
+ continue;
920
933
  }
921
- if (step.commands && Array.isArray(step.commands)) {
922
- step.commands = step.commands.map((cmd) => toRecordingStep(cmd, scenario.parametersMap));
934
+
935
+ const cucumberStep = getCucumberStep({ step });
936
+ const pageName = generatePageName(step.startFrame?.url ?? "default", step.isUtilStep);
937
+ const stepDefsFilePath = locateDefinitionPath(featureFolder, pageName);
938
+ let codePage = getCodePage(stepDefsFilePath);
939
+
940
+ codePage = await saveRecording({
941
+ step,
942
+ cucumberStep,
943
+ codePage,
944
+ projectDir,
945
+ stepsDefinitions,
946
+ parametersMap: scenario.parametersMap,
947
+ });
948
+
949
+ if (!codePage) continue;
950
+
951
+ const res = await codePage.save();
952
+ if (!res) {
953
+ throw new DomainError(
954
+ `Failed to save step definition for "${cucumberStep.text}" in "${codePage.sourceFileName}"`
955
+ );
923
956
  }
924
- continue;
925
- }
926
- const cucumberStep = getCucumberStep({ step });
927
- const pageName = generatePageName(step.startFrame?.url ?? "default", step.isUtilStep);
928
- const stepDefsFilePath = locateDefinitionPath(featureFolder, pageName);
929
- let codePage = getCodePage(stepDefsFilePath);
930
- codePage = await saveRecording({
931
- step,
932
- cucumberStep,
933
- codePage,
934
- projectDir,
935
- stepsDefinitions,
936
- parametersMap: scenario.parametersMap,
937
- });
938
- if (!codePage) {
939
- continue;
940
- }
941
- const res = await codePage.save();
942
- if (!res) {
943
- throw new Error(`Failed to save step definition for "${cucumberStep.text}" in "${codePage.sourceFileName}"`);
944
957
  }
958
+
959
+ writeFileSync(utilsFilePath, utilsContent, "utf8");
960
+ } catch (error) {
961
+ logger.error(`❌ updateStepDefinitions() failed: ${error?.message ?? String(error)}`);
962
+ throw error instanceof DomainError ? error : new DomainError(error?.message ?? "Unknown error");
945
963
  }
946
- writeFileSync(utilsFilePath, utilsContent, "utf8");
947
964
  }
948
965
 
949
966
  export function saveRoutes({ step, folderPath }, logger) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dev-blinq/cucumber_client",
3
- "version": "1.0.1727-dev",
3
+ "version": "1.0.1729-dev",
4
4
  "description": " ",
5
5
  "main": "bin/index.js",
6
6
  "types": "bin/index.d.ts",