You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
At first, this extension doesn't seem to work with Codeception, as reported in this issue: #324
It turns out it's just a small Regex gimmick.
I've adapted gserver/src/steps.handler.js's getStepRegExp to run on Developer Tools for easier debugging. You can just copy and paste this on your Developer tools:
//Actually, we dont care what the symbols are before our 'Gherkin' word//But they shouldn't end with letterconststartPart='^((?:[^\'"\/]*?[^\\w])|.{0})';//All the steps should be declared using any gherkin keyword. We should get first 'gherkin' wordconstgherkinPart=`(Given|When|Then)`;//All the symbols, except of symbols, using as step start and letters, could be between gherkin word and our stepconstnonStepStartSymbols=`[^\/'"\`\\w]*?`;// Step part gettingconststepRegExSymbol='/';// Step text could be placed between '/' symbols (ex. in JS) or between quotes, like in JavaconststepStart=stepRegExSymbol ? `(${stepRegExSymbol})` : `(\/|'|"|\`)`;// ref to RegEx Example: https://regex101.com/r/mS1zJ8/1// Use a RegEx that peeks ahead to ensure escape character can still work, like `\'`.conststepBody=`((?:(?=(?:\\\\)*)\\\\.|.)*?)`;//Step should be ended with same symbol it beginsconststepEnd=stepRegExSymbol ? stepRegExSymbol : '\\3';//Our RegExp will be case-insensitive to support cases like TypeScript (...@when...)constr=newRegExp(startPart+gherkinPart+nonStepStartSymbols+stepStart+stepBody+stepEnd,'i');
Then run:
'@Then /I should see :arg1/'.match(r); // Match.
'@Then I should see :arg1'.match(r); // No Match.
It expects to find the step definition wrapped in JS or Java-style regex delimitators, which are / or backticks. However, Codeception generates the step definition without regex delimitators:
What it expects:
/** * @Then /I should see :arg1/ */
How Codeception generates step definitions:
/** * @Then I should see :arg1 */
Is it possible to update that Regex to accept a step definition without a Regex delimitator? If you're afraid it could lead to false positives, maybe it could be a opt-in setting that those using Codeception should enable?
The text was updated successfully, but these errors were encountered:
This works for me for single-line step definitions:
gserver/src/steps.handler.ts
if(this.settings.cucumberautocomplete.requireDelimiters){// Step part gettingconst{ stepRegExSymbol }=this.settings.cucumberautocomplete;// Step text could be placed between '/' symbols (ex. in JS) or between quotes, like in JavaconststepStart=stepRegExSymbol ? `(${stepRegExSymbol})` : `(\/|'|"|\`)`;// ref to RegEx Example: https://regex101.com/r/mS1zJ8/1// Use a RegEx that peeks ahead to ensure escape character can still work, like `\'`.conststepBody=`((?:(?=(?:\\\\)*)\\\\.|.)*?)`;//Step should be ended with same symbol it beginsconststepEnd=stepRegExSymbol ? stepRegExSymbol : '\\3';//Our RegExp will be case-insensitive to support cases like TypeScript (...@when...)constr=newRegExp(startPart+gherkinPart+nonStepStartSymbols+stepStart+stepBody+stepEnd,'i');}else{conststepBody=`((?:(?=(?:\\\\)*)\\\\.|.)*?)`;// Without delimiters, the step should be ended with a new line.conststepEnd='\n';//Our RegExp will be case-insensitive to support cases like TypeScript (...@when...)constr=newRegExp(startPart+gherkinPart+nonStepStartSymbols+stepBody+stepEnd,'i');}
"cucumberautocomplete.requireDelimiters": {
"description": "Whether the step definitions should have regex delimiters.",
"type": "boolean",
"required": false,
"default": true
},
If you'd like I could open a PR with this approach. Based on your experience, is it fine to use \n as a delimiter for the step definition, or should it support multi-lines?
If it's possible to come up with a regex that matches with/without delimiters that'd be ideal, but I'm not sure what are the other use-cases to cover, so I was just playing with it
Describe the bug
At first, this extension doesn't seem to work with Codeception, as reported in this issue: #324
It turns out it's just a small Regex gimmick.
I've adapted
gserver/src/steps.handler.js
's getStepRegExp to run on Developer Tools for easier debugging. You can just copy and paste this on your Developer tools:Then run:
'@Then /I should see :arg1/'.match(r); // Match.
'@Then I should see :arg1'.match(r); // No Match.
It expects to find the step definition wrapped in JS or Java-style regex delimitators, which are
/
or backticks. However, Codeception generates the step definition without regex delimitators:What it expects:
How Codeception generates step definitions:
Is it possible to update that Regex to accept a step definition without a Regex delimitator? If you're afraid it could lead to false positives, maybe it could be a opt-in setting that those using Codeception should enable?
The text was updated successfully, but these errors were encountered: