2

I am building a Cypress Framework using the @badeball/cypress-cucumber-preprocessor node package and the Cucumber (Gherkin) Full Support vs code extension.

When autocompleting a step that contains {string} I would like to replace {string} with "" instead of ("|')[^\1]*\1 or ("|')\1

My .cypress-cucumber-preprocessorrc.json file is as follows:

{
  "json": {
    "enabled": true
  },
  "stepDefinitions": "**/*.steps.js"
}

My settings.json file is as follows:

{
    "explorer.sortOrder": "filesFirst",
    "cucumberautocomplete.steps": "**/*.steps.js",
    "cucumberautocomplete.syncfeatures": "**/features/*.feature",
    "cucumberautocomplete.strictGherkinCompletion": true,
    "cucumberautocomplete.strictGherkinValidation": true,
    "cucumberautocomplete.smartSnippets": true,
    "cucumberautocomplete.stepsInvariants": true,
    "cucumberautocomplete.skipDocStringsFormat": true,
    "cucumberautocomplete.onTypeFormat": true,
    "editor.quickSuggestions": {
        "comments": false,
        "strings": true,
        "other": true
    },
    "cucumberautocomplete.gherkinDefinitionPart": "(Given|When|Then)\\("
}

For example, I have a step definition as follows:

When("I click the {string}", (element) => {
    //some code
});

With the above settings and smartSnippets set to true I get the following autocompleted step:

When I click the ("|')\1

With the above settings but changing smartSnippets to false I get the following autocompleted step:

When I click the ("|')[^\1]*\1

What I would like to get is this autocompleted step:

When I click the ""
1

1 Answer 1

0

First, you need to install Regexp Explain extension.

Then modify your settings.json file the following way:

{
  "explorer.sortOrder": "filesFirst",
  "cucumberautocomplete.steps": "**/*.steps.js",
  "cucumberautocomplete.syncfeatures": "**/features/*.feature",
  "cucumberautocomplete.strictGherkinCompletion": true,
  "cucumberautocomplete.strictGherkinValidation": true,
  "cucumberautocomplete.smartSnippets": true,
  "cucumberautocomplete.stepsInvariants": true,
  "cucumberautocomplete.skipDocStringsFormat": true,
  "cucumberautocomplete.onTypeFormat": true,
  "editor.quickSuggestions": {
    "comments": false,
    "strings": true,
    "other": true
  },
  "cucumberautocomplete.gherkinDefinitionPart": "(Given|When|Then)\\(",
  "regexp-explain.expressions": {
    "cypress-step-parameter": {
      "expression": "\"(.*?)\"",
      "prefix": "",
      "suffix": ""
    }
  },
  "cucumberautocomplete.gherkinRegEx": "cypress-step-parameter"
}

With this setup once you start entering {string} in single quotes the extension is going to replace it with double quotes.

Let me know if it works for you.

Sign up to request clarification or add additional context in comments.

1 Comment

I have installed the Regexp Explain extension and updated my settings.json file. However, the properties "regexp-explain.expressions" and "cucumberautocomplete.gherkinRegEx" could not be found, and so, the issue still persists. Is there some other configuration required?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.