@dev-blinq/cucumber_client 1.0.1192-dev → 1.0.1194-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.
@@ -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 pkg from "../../min/injectedScript.min.cjs";
7
- import { getImplementedSteps } from "./implemented_steps.js";
7
+ import { getImplementedSteps, getStepsAndCommandsForScenario } from "./implemented_steps.js";
8
8
  import { NamesService } from "./services.js";
9
9
  import { BVTStepRunner } from "./step_runner.js";
10
10
  import { readFile, writeFile } from "fs/promises";
@@ -756,6 +756,9 @@ export class BVTRecorder {
756
756
  async getImplementedSteps() {
757
757
  return getImplementedSteps(this.projectDir);
758
758
  }
759
+ async getStepsAndCommandsForScenario({ name, featureName }) {
760
+ return getStepsAndCommandsForScenario({ name, featureName, projectDir: this.projectDir });
761
+ }
759
762
  async generateStepName({ commands, stepsNames, parameters, map }) {
760
763
  return await this.namesService.generateStepName({ commands, stepsNames, parameters, map });
761
764
  }
@@ -5,6 +5,8 @@ import url from "url";
5
5
  import { findFilesWithExtension, StepsDefinitions } from "../cucumber/steps_definitions.js";
6
6
  import { Feature } from "../cucumber/feature.js";
7
7
  import { CodePage } from "../code_gen/page_reflection.js";
8
+ import { getCommandsForImplementedStep, loadStepDefinitions } from "./step_utils.js";
9
+ import { parseStepTextParameters } from "../cucumber/utils.js";
8
10
  const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
9
11
  let id = 0;
10
12
  const uuidFn = () => (++id).toString(16);
@@ -231,13 +233,17 @@ export const getImplementedSteps = async (projectDir) => {
231
233
  delete scenario.featureText;
232
234
  delete scenario.scenarioDocument;
233
235
  delete scenario.examples;
234
- const steps = scenario.steps;
235
- for (const step of steps) {
236
- const index = implementedSteps.findIndex((istep) => {
237
- return stepsDefinitions._stepNameToTemplate(step.text) === istep.pattern;
238
- });
239
- step.templateIndex = index;
236
+ delete scenario.steps;
237
+ for (const tag of scenario.tags) {
238
+ delete tag.location;
240
239
  }
240
+ // const steps = scenario.steps;
241
+ // for (const step of steps) {
242
+ // const index = implementedSteps.findIndex((istep) => {
243
+ // return stepsDefinitions._stepNameToTemplate(step.text) === istep.pattern;
244
+ // });
245
+ // step.templateIndex = index;
246
+ // }
241
247
  }
242
248
  if (foundErrors.length > 0) {
243
249
  console.log("foundErrors", foundErrors);
@@ -246,3 +252,42 @@ export const getImplementedSteps = async (projectDir) => {
246
252
  console.log("Size of scenarios", memorySizeOf(scenarios));
247
253
  return { implementedSteps, scenarios };
248
254
  };
255
+
256
+ export const getStepsAndCommandsForScenario = ({ name, featureName, projectDir }) => {
257
+ const stepsDefinitions = new StepsDefinitions(projectDir);
258
+ const step_definitions = loadStepDefinitions(projectDir);
259
+ stepsDefinitions.load();
260
+ const featureFilePath = path.join(projectDir, "features", featureName.trim() + ".feature");
261
+ if (!existsSync(featureFilePath)) {
262
+ throw new Error(`Feature file ${featureFilePath} not found`);
263
+ }
264
+ const content = readFileSync(featureFilePath, "utf8");
265
+ const doc = parser.parse(content);
266
+ const feature = new Feature(doc, content);
267
+ const scenario = feature.getScenario(name);
268
+ if (!scenario) {
269
+ throw new Error(`Scenario ${name} not found in feature ${featureName}`);
270
+ }
271
+
272
+ for (const step of scenario.steps) {
273
+ const stepName = step.text;
274
+ const stepParams = parseStepTextParameters(stepName);
275
+ step.commands = [];
276
+ try {
277
+ const stepDefinition = stepsDefinitions.findMatchingStep(stepName);
278
+ if (stepDefinition) {
279
+ step.isImplemented = true;
280
+ const commands = getCommandsForImplementedStep(stepName, step_definitions, stepParams).commands;
281
+ step.commands = commands;
282
+ } else {
283
+ step.isImplemented = false;
284
+ }
285
+ } catch (error) {
286
+ console.error(`Error getting step definition for ${stepName}`, error);
287
+ step.isImplemented = false;
288
+ }
289
+ }
290
+ console.log("Scenario steps size", memorySizeOf(scenario.steps));
291
+
292
+ return { steps: scenario.steps };
293
+ };
@@ -239,6 +239,9 @@ const init = ({ envName, projectDir, roomId, TOKEN }) => {
239
239
  const mode = input?.mode;
240
240
  return recorder.setMode(mode);
241
241
  },
242
+ "recorderWindow.getStepsAndCommandsForScenario": async (input) => {
243
+ return await recorder.getStepsAndCommandsForScenario(input);
244
+ },
242
245
  });
243
246
  socket.on("targetBrowser.command.event", async (input) => {
244
247
  return recorder.onAction(input);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dev-blinq/cucumber_client",
3
- "version": "1.0.1192-dev",
3
+ "version": "1.0.1194-dev",
4
4
  "description": "",
5
5
  "main": "bin/index.js",
6
6
  "types": "bin/index.d.ts",