@dev-blinq/cucumber_client 1.0.1728-dev → 1.0.1730-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.
@@ -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,109 @@ 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
+ try {
903
+ if (step.internalImplementedStepId) {
904
+ const si = steps.findIndex((s) => s.id === step.internalImplementedStepId);
905
+ if (si !== -1) {
906
+ step.isImplementedWhileRecording = true;
907
+ }
904
908
  }
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)}`);
909
+
910
+ if (!step.isUtilStep && ((step.isImplemented && !step.shouldOverride) || step.commands.length === 0)) {
911
+ let routesPath = path.join(tmpdir(), `blinq_temp_routes`);
912
+ if (process.env.TEMP_RUN === "true") {
913
+ if (existsSync(routesPath)) rmSync(routesPath, { recursive: true });
914
+ mkdirSync(routesPath, { recursive: true });
915
+ saveRoutes({ step, folderPath: routesPath }, logger);
916
+ } else {
917
+ if (existsSync(routesPath)) {
918
+ try {
919
+ rmSync(routesPath, { recursive: true });
920
+ } catch (error) {
921
+ logger.error(`❌ Error removing temp routes folder: ${getErrorMessage(error)}`);
922
+ }
923
+ }
924
+ routesPath = path.join(projectDir, "data", "routes");
925
+ if (!existsSync(routesPath)) mkdirSync(routesPath, { recursive: true });
926
+ saveRoutes({ step, folderPath: routesPath }, logger);
927
+ }
928
+
929
+ if (step.commands && Array.isArray(step.commands)) {
930
+ step.commands = step.commands.map((cmd) => toRecordingStep(cmd, scenario.parametersMap));
913
931
  }
932
+
933
+ continue;
914
934
  }
915
- routesPath = path.join(projectDir, "data", "routes");
916
- if (!existsSync(routesPath)) {
917
- mkdirSync(routesPath, { recursive: true });
935
+
936
+ const cucumberStep = getCucumberStep({ step });
937
+ const pageName = generatePageName(step.startFrame?.url ?? "default", step.isUtilStep);
938
+ const stepDefsFilePath = locateDefinitionPath(featureFolder, pageName);
939
+ let codePage = getCodePage(stepDefsFilePath);
940
+
941
+ codePage = await saveRecording({
942
+ step,
943
+ cucumberStep,
944
+ codePage,
945
+ projectDir,
946
+ stepsDefinitions,
947
+ parametersMap: scenario.parametersMap,
948
+ });
949
+
950
+ if (!codePage) continue;
951
+
952
+ const res = await codePage.save();
953
+ if (!res) {
954
+ throw new DomainError(
955
+ `Failed to save step definition for "${cucumberStep.text}" in "${codePage.sourceFileName}"`
956
+ );
918
957
  }
919
- saveRoutes({ step, folderPath: routesPath }, logger);
920
- }
921
- if (step.commands && Array.isArray(step.commands)) {
922
- step.commands = step.commands.map((cmd) => toRecordingStep(cmd, scenario.parametersMap));
958
+ } catch (error) {
959
+ logger.error(`❌ Failed to update step definition for step "${step.text}": ${getErrorMessage(error)}`);
960
+ throw new DomainError(`Failed to update step definition for step "${step.text}": ${getErrorMessage(error)}`);
923
961
  }
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
962
  }
963
+
964
+ writeFileSync(utilsFilePath, utilsContent, "utf8");
965
+ } catch (error) {
966
+ logger.error(`❌ updateStepDefinitions() failed: ${error?.message ?? String(error)}`);
967
+ throw error instanceof DomainError ? error : new DomainError(error?.message ?? "Unknown error");
945
968
  }
946
- writeFileSync(utilsFilePath, utilsContent, "utf8");
947
969
  }
948
970
 
949
971
  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.1728-dev",
3
+ "version": "1.0.1730-dev",
4
4
  "description": " ",
5
5
  "main": "bin/index.js",
6
6
  "types": "bin/index.d.ts",