Repository: TheBrainFamily/cypress-cucumber-preprocessor (js)

Issue:
help with regular expressions
Using version 0.6.0. I can't figure out how to incorporate regular expressions into the step function.

I'm trying to not only make 'exact' an optional word, but have the step function track whether 'exact' is included or not in the gherkin sentence. This is so my step function's logic can act on whether 'exact' was in the sentence or not.
Goal:
"Then I do a exact search" => step function parameter exactParam will store 'exact'
"Then I do a search" => step function parameter exactParam will store either null, undefined, or ''

But the following cause cypress to say "Step implementation missing for: I do a exact search":
then('I do a (exact)? search'), (exactParam) => {.... //rest of code
then('/I do a (exact)? search/'), (exactParam) => {.... //rest of code
then('^/I do a (exact)? search$/'), (exactParam) => {.... //rest of code
then('^/I do a (exact\s+)?search$/'), (exactParam) => {.... //rest of code

I also tried another simple regex example to look for a single digit in the gherkin sentence:
"Then I do 2"

But Cypress still said "step implementation missing for: I do 2"
then('I do (\d)'), (num) => {.... //rest of code
then('I do (\d+)'), (num) => {.... //rest of code
then('/I do (\d+)/'), (num) => {.... //rest of code

Pull request description:
fixed #42 - regular expressions

Patch:
diff --git a/cypress/integration/RegularExpressions.feature b/cypress/integration/RegularExpressions.feature
new file mode 100644
index 0000000..d285073
--- /dev/null
+++ b/cypress/integration/RegularExpressions.feature
@@ -0,0 +1,10 @@
+Feature: Regular Expressions
+  As a pro-developer
+  I want to be able to use the power of regular expression in my step definitions
+  So I can write more sophisticated tests
+
+  Scenario: Regular Expression Example
+    Given I choose Apple
+    Then Apple is chosen
+    When I choose Banana
+    Then Banana is chosen
\ No newline at end of file
diff --git a/cypress/support/step_definitions/regexp.js b/cypress/support/step_definitions/regexp.js
new file mode 100644
index 0000000..856a10a
--- /dev/null
+++ b/cypress/support/step_definitions/regexp.js
@@ -0,0 +1,10 @@
+/* global given then */
+let selectedFruit;
+
+given(/I choose (Apple|Banana)/, selection => {
+  selectedFruit = selection;
+});
+
+then("{word} is chosen", selection => {
+  expect(selectedFruit).to.equal(selection);
+});
diff --git a/resolveStepDefinition.js b/resolveStepDefinition.js
index 160833e..a66f3fb 100644
--- a/resolveStepDefinition.js
+++ b/resolveStepDefinition.js
@@ -1,6 +1,7 @@
 const DataTable = require("cucumber/lib/models/data_table").default;
 const {
   CucumberExpression,
+  RegularExpression,
   ParameterTypeRegistry
 } = require("cucumber-expressions");
 
@@ -10,19 +11,18 @@ class StepDefinitionRegistry {
   constructor() {
     this.definitions = {};
     this.runtime = {};
-    this.latestType = "";
 
     this.definitions = [];
-    this.runtime = (expression, implementation) => {
-      this.definitions.push({
-        implementation,
-        expression: new CucumberExpression(expression, parameterTypeRegistry)
-      });
+    this.runtime = (matcher, implementation) => {
+      let expression;
+      if (matcher instanceof RegExp) {
+        expression = new RegularExpression(matcher, parameterTypeRegistry);
+      } else {
+        expression = new CucumberExpression(matcher, parameterTypeRegistry);
+      }
+      this.definitions.push({ implementation, expression });
     };
 
-    this.load = definitionFactoryFunction =>
-      definitionFactoryFunction(this.runtime);
-
     this.resolve = (type, text) =>
       this.definitions.filter(({ expression }) => expression.match(text))[0];
   }


Test patch:
diff --git a/resolveStepDefinition.test.js b/resolveStepDefinition.test.js
index 60ce319..6cfad73 100644
--- a/resolveStepDefinition.test.js
+++ b/resolveStepDefinition.test.js
@@ -57,3 +57,10 @@ describe("Background section", () => {
     readAndParseFeatureFile("./cypress/integration/BackgroundSection.feature")
   );
 });
+
+describe("Regexp", () => {
+  require("./cypress/support/step_definitions/regexp");
+  createTestsFromFeature(
+    readAndParseFeatureFile("./cypress/integration/RegularExpressions.feature")
+  );
+});