cucumber / vscode

Official Visual Studio Code Extension for Cucumber
MIT License
65 stars 16 forks source link

Steps highlighting shows "Undefined step" warning on Fedora Linux #120

Closed Kolobamanacas closed 6 months ago

Kolobamanacas commented 1 year ago

šŸ‘“ What did you see?

"Undefined step" error occurs when creating scenario with data tables for each step of given/when/then. Also params are not highlighted properly.

āœ… What did you expect to see?

No error. All params to be highlighted.

šŸ“¦ Which tool/library version are you using?

Fedora Linux 36 Kernel Version 6.0.5-200.fc36.x86_64 (64-bit) KDE Plasma 5.25.5

Visual Studio Code 1.73.0 | Dark+ (default dark) Cucumber 1.5.1 TypeScript 4.6.2 jest 27.5.1 jest-cucumber 3.0.1

šŸ”¬ How could we reproduce it?

  1. Install stable release of Fedora 36.
  2. Install Visual Studio Code 1.73.0.
  3. Install Cucumber 1.5.1 extension.
  4. Set path to your feature folder.
  5. Create a file "do-stuff.feature" in that folder.
  6. Put The following code in file:
Feature: Do CCC stuff

  Scenario: Get "<AAA>" for given "<BBB>", "<CCC>" and "<DDD>"
    Given Record with "<BBB>" and "<EEE>"
      | BBB    | EEE    |
      | Value1 | Value2 |
    When Run command "do-stuff --DDD <DDD> --CCC <CCC>"
      | DDD    | CCC    |
      | Value3 | Value4 |
    Then "CCC" table contains record with "<CCC>"
      | CCC    |
      | Value4 |
    And "CCC-sub" table contains record with "<DDD>", "<CCC>", "<BBB>" and "<AAA>"
      | DDD    | CCC    | BBB    | AAA    |
      | Value3 | Value4 | Value1 | Value5 |
  1. See the error. All keywords of given/when/then/and will be highlighted with:
Undefined step: Record with "BBB" and "EEE"

HighlightError

šŸ“š Any additional context?

I've noticed that if I add "Examples:" section, then all errors are gone and params are highlighted correctly. Even when examples section is empty.

NoErrors

aslakhellesoy commented 1 year ago

From your use of <AAA> etc it looks like your intention is to use an Examples: section underneath.

Could you please share the expressions of your step definitions as well?

The-BDD-Coach commented 1 year ago

I also see this error; here I have three uses of 'Given these books in the catalog':

Feature: Library book searches and book delivery

    Scenario: The catalog can be searched by author's name.
    Given these books in the catalog

    Scenario Outline: Author name searches match if the searched string appears anywhere in the author's name.
    Given these books in the catalog

    Examples:

    Scenario: Author name searches are case insensitive.
    Given these books in the catalog

    Examples:

Here are my step definitions:


  @given(/these books in the catalog/)
  public givenTheseBooksInTheCatalog(table: any) {
    this._scenarioContext.catalog = new Catalog([]);
    const creationHelperMethods = new CreationHelperMethods();
    creationHelperMethods.ReadBooksAndAddToCatalog(this._scenarioContext.catalog, table);
  }
schwaerz commented 1 year ago

Same here. As soon as I am adding Examples: the yellow underlineing vanishes. However, even when underlined, the goto step definition works, as well as the autocomplete.

grafik

Maybe I should mention that those steps are parameterized. Using Version 1.7.0 of the plugin.

kieran-ryan commented 10 months ago

"Undefined step" error occurs when creating scenario with data tables for each step of given/when/then. Also params are not highlighted properly.

@Kolobamanacas, delimited parameters (< >) are intended as a template for scenario outline tables and are thus only highlighted in the presence of an examples table (specifically the Examples: keyword). Would you be able to provide a step definition for one of the steps you have outlined above to understand usage? See gherkin reference on scenario outlines:

Scenario outlines allow us to more concisely express these scenarios through the use of a template with < >-delimited parameters:

@Kolobamanacas, @The-BDD-Coach and @schwaerz, diagnostics (underlining) for undefined steps is currently unsupported with Scenario Outlines (see cucumber/language-service#149 for some of the challenges to resolve that). Thus, when the Examples: keyword is introduced, underlining of undefined steps is disabled.

However, even when underlined, the goto step definition works, as well as the autocomplete.

@schwaerz, completions will appear for gherkin steps included in existing feature files, even if there is no matching step definition. However, would be interested to see an example where a step is marked 'undefined', but the 'go to step definition' functionality is working; would you be able to provide one?

kieran-ryan commented 6 months ago

Original comment on No error. and all subsequent comments relate to lack of support for highlighting undefined steps with Scenario Outlines (inclusion of Examples:) - covered by #90.

In relation to All params to be highlighted., no MRE provided with step definitions so whether intention was to use a Scenario Outline is presently indeterminate.

From your use of <AAA> etc it looks like your intention is to use an Examples: section underneath.

Could you please share the expressions of your step definitions as well?

Issue will be reopened if further detail provided that necessitates a fix or feature.

The-BDD-Coach commented 6 months ago

@kieran-ryan you said "subsequent comments relate to lack of support for highlighting undefined steps with Scenario Outlines"; all of my steps are defined. I can run the requirements - all of them - and they pass. I can do this with Behave and with Pytest-BDD-NG; I see the same behavior:

and the V1.8.1 Cucumber plugin.

kieran-ryan commented 6 months ago

@kieran-ryan you said "subsequent comments relate to lack of support for highlighting undefined steps with Scenario Outlines"; all of my steps are defined. I can run the requirements - all of them - and they pass. I can do this with Behave and with Pytest-BDD-NG; I see the same behavior:

  • Step definitions are marked as undefined unless I add 'Examples:' to the Scenario.
  • As soon as I type the ':' the yellow squiggly underlines disappear.

Yes, the comments on this issue relate to a lack of feature support by the Cucumber Language Service for highlighting whether a step is marked undefined with Scenario Outlines (contains Examples:). This is captured under existing issues linked above (cucumber/language-service/issues/149, #90, cucumber/monaco#60). See defensive diagnostics code which returns early if inside a Scenario Outline - instead of progressing to check whether the step is undefined.

The new and separate details relating to Python step definitions can occur for a number of reasons:

Your second pattern is detectable (see below) - but this can be impacted if some of the issues above are present elsewhere in that module or if the extension configuration settings are not checking the location in which you are storing step definitions.

image

The earlier typescript example will fail as the Language Service looks for the capitalised variants of the decorators (@Given, @When, @Then) - as used in the Cucumber documentation - though not sure which framework version is being used with this step definition exactly; and as such won't be detected.

  @given(/these books in the catalog/)
  public givenTheseBooksInTheCatalog(table: any) {
    this._scenarioContext.catalog = new Catalog([]);
    const creationHelperMethods = new CreationHelperMethods();
    creationHelperMethods.ReadBooksAndAddToCatalog(this._scenarioContext.catalog, table);
  }

Doing what I can to find and fix these issues. PRs welcome.

kieran-ryan commented 5 months ago

@The-BDD-Coach, with the latest release of the VSCode extension (v1.10.0), you may be interested in the following changes for Python support:

Looking forward to any feedback šŸ‘

The-BDD-Coach commented 5 months ago

@kieran-ryan I installed the 1.10.0 VSCode extension but am still seeing significant problems: 1) Most (I think All) steps in Scenarios show as undefined, even for plain text matchers 2) Steps in Scenario Outlines show as defined, but 'Go to definition' doesn't work; it just says 'No definition for (the word the cursor is on)'.

This is true for both Behave and Pytest-BDD-NG - and all of the Behave step definitions worked in the past.

If you have any suggestions on the best way to troubleshoot this I would be glad hear them.

kieran-ryan commented 5 months ago

@The-BDD-Coach, would it be possible to create a small minimal reproducible example with a repository containing the step definitions and environment setup? We can then analyse what might be causing the issue.

What version of Visual Studio Code are you using? A copy of the extension output logs (Output -> Cucumber Language Server) would also be great.

This is true for both Behave and Pytest-BDD-NG - and all of the Behave step definitions worked in the past.

From 'Version History' in the Visual Studio Marketplace, if you install an older version of the extension, does the issue persist?

The-BDD-Coach commented 5 months ago

That is a good suggestion; I will work on that.

kieran-ryan commented 5 months ago
  1. Steps in Scenario Outlines show as defined, but 'Go to definition' doesn't work; it just says 'No definition for (the word the cursor is on)'.

Please note that marking steps as 'undefined' within Scenario Outlines is presently unsupported. Therefore, rather than being considered 'defined', diagnostics (underlining) and matching the steps against definitions is disabled with Scenario Outlines at this time.

Yes, the comments on this issue relate to a lack of feature support by the Cucumber Language Service for highlighting whether a step is marked undefined with Scenario Outlines (contains Examples:). This is captured under existing issues linked above (cucumber/language-service/issues/149, #90, cucumber/monaco#60). See defensive diagnostics code which returns early if inside a Scenario Outline - instead of progressing to check whether the step is undefined.

The-BDD-Coach commented 5 months ago

@kieran-ryan I created https://github.com/The-BDD-Coach/Step-Definition-Bug/tree/main, and will open a new defect for tracking this.

The-BDD-Coach commented 5 months ago

@kieran-ryan I opened https://github.com/cucumber/vscode/issues/226 and attached the Cucumber Language Server logs. The logs are interesting: [Info - 10:19:21 AM] Found 0 feature file(s) in ["src/test//.feature","features//.feature","tests//.feature","specs//.feature"] [Info - 10:19:21 AM] Found 0 steps in those feature files [Info - 10:19:21 AM] * Found 0 glue file(s) in ["specs//.cs","features/*/.js","features//.jsx","features//.php","features//.py","features//*.rs","features//.rb","features/*/.ts","features//.tsx","features//_test.go","src/test/*/.java","tests//.py","tests//.rs"] [Info - 10:19:21 AM] Found 0 parameter types in those glue files [Info - 10:19:21 AM] * Found 0 step definitions in those glue files