@dev-blinq/cucumber_client 1.0.1196-dev → 1.0.1197-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.
@@ -289,7 +289,7 @@ class Feature {
289
289
  }
290
290
  return scenarios;
291
291
  }
292
- generateStracture(stepsDefinitions, fileName, scenarioName = null) {
292
+ generateStracture(stepsDefinitions, fileName, scenarioName = null, errorsInParsing = [], parseFailedFiles = false) {
293
293
  const document = {};
294
294
  document.featureName = this.feature.name;
295
295
  document.fileName = fileName;
@@ -311,6 +311,29 @@ class Feature {
311
311
  stepInfo.template = step.getTemplate();
312
312
  scenarioInfo.steps.push(stepInfo);
313
313
  const stepDef = stepsDefinitions.findMatchingStep(stepInfo.template);
314
+ if (!stepDef && parseFailedFiles) {
315
+ //Check if the stepName exists in one of the failedToParseFiles
316
+ try {
317
+ const stepName = stepsDefinitions._stepNameToTemplate(stepInfo.template);
318
+ if (errorsInParsing && errorsInParsing.length > 0) {
319
+ for (let k = 0; k < errorsInParsing.length; k++) {
320
+ const failedFile = errorsInParsing[k].file;
321
+ //Read File content, and check if the stepName exists in the file
322
+ const fileContent = fs.readFileSync(failedFile, "utf8");
323
+ if (fileContent.includes(stepName)) {
324
+ stepInfo.implemented = true;
325
+ stepInfo.mjsFile = failedFile;
326
+ stepInfo.functionName = stepName;
327
+ stepInfo.error = errorsInParsing[k].error;
328
+ console.log(JSON.stringify(stepInfo));
329
+ break;
330
+ }
331
+ }
332
+ }
333
+ } catch (e) {
334
+ console.error(`Error while checking step ${stepInfo.template} in failed files:`, e);
335
+ }
336
+ }
314
337
  stepInfo.implemented = stepDef ? true : false;
315
338
  if (stepDef) {
316
339
  stepInfo.mjsFile = stepDef.file;
@@ -4,14 +4,14 @@ import { AstBuilder, GherkinClassicTokenMatcher, Parser } from "@cucumber/gherki
4
4
  import { Feature } from "./feature.js";
5
5
  import { StepsDefinitions } from "./steps_definitions.js";
6
6
 
7
- export const projectDocument = (folder, featureName = null, scenarioName = null) => {
7
+ export const projectDocument = (folder, featureName = null, scenarioName = null, supressErrors = false, errors = []) => {
8
8
  const uuidFn = () => (23212).toString(16);
9
9
  const builder = new AstBuilder(uuidFn);
10
10
  const matcher = new GherkinClassicTokenMatcher();
11
11
  const parser = new Parser(builder, matcher);
12
- const stepDefinition = new StepsDefinitions(folder);
13
- stepDefinition.load(false);
14
-
12
+ // load the step definitions from the project folder under steps folder
13
+ const stepDefinition = new StepsDefinitions(folder, false);
14
+ stepDefinition.load(false, supressErrors, errors);
15
15
  // read all the feature files in the project folder under features folder
16
16
  let featureFiles = [];
17
17
  const featuresDir = path.join(folder, "features");
@@ -27,7 +27,7 @@ export const projectDocument = (folder, featureName = null, scenarioName = null)
27
27
  if (featureName && feature.feature.name !== featureName && featureFile !== featureName) {
28
28
  continue;
29
29
  }
30
- const document = feature.generateStracture(stepDefinition, featureFile, scenarioName);
30
+ const document = feature.generateStracture(stepDefinition, featureFile, scenarioName, errors, supressErrors);
31
31
  if (scenarioName && document.scenarios.length === 0) {
32
32
  continue;
33
33
  }
@@ -55,7 +55,8 @@ export const projectDocument = (folder, featureName = null, scenarioName = null)
55
55
  // scenarioName = arg.substring(9);
56
56
  // }
57
57
  // }
58
- // const documents = projectDocument(projectDir, featureName, scenarioName);
58
+ // let errors = [];
59
+ // const documents = projectDocument(projectDir, featureName, scenarioName, true, errors);
59
60
  // const args = process.argv.slice(2);
60
61
 
61
- // console.log(JSON.stringify(projectDocument(args[0])));
62
+ // console.log(JSON.stringify(documents));
@@ -54,7 +54,7 @@ class StepsDefinitions {
54
54
  }
55
55
  }
56
56
  }
57
- load(print = true) {
57
+ load(print = true, supressErrors = false, errors = []) {
58
58
  const mjsFiles = findFilesWithExtension(
59
59
  path.join(this.baseFolder, this.isTemp ? process.env.tempFeaturesFolderPath ?? "__temp_features" : "features"),
60
60
  "mjs"
@@ -62,18 +62,25 @@ class StepsDefinitions {
62
62
  // console.log({ mjsFiles });
63
63
  for (let i = 0; i < mjsFiles.length; i++) {
64
64
  const mjsFile = mjsFiles[i];
65
- const codePage = new CodePage(
66
- path.join(
67
- this.baseFolder,
68
- this.isTemp ? process.env.tempFeaturesFolderPath ?? "__temp_features" : "features",
69
- mjsFile
70
- )
71
- );
65
+ console.log("loading step definitions from file", mjsFile);
66
+ const filePath = path.join(
67
+ this.baseFolder,
68
+ this.isTemp ? process.env.tempFeaturesFolderPath ?? "__temp_features" : "features",
69
+ mjsFile);
70
+ const codePage = new CodePage(filePath);
72
71
  try {
73
72
  codePage.generateModel();
74
73
  } catch (error) {
75
74
  logger.info("unable to generate model for file", mjsFile);
76
- throw error;
75
+ if(supressErrors) {
76
+ errors.push({
77
+ file: filePath,
78
+ error: error.message,
79
+ });
80
+ }
81
+ else{
82
+ throw error;
83
+ }
77
84
  }
78
85
  this.initPage(codePage, mjsFile);
79
86
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dev-blinq/cucumber_client",
3
- "version": "1.0.1196-dev",
3
+ "version": "1.0.1197-dev",
4
4
  "description": "",
5
5
  "main": "bin/index.js",
6
6
  "types": "bin/index.d.ts",