Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Diagnostics support for undefined steps in scenario outlines #149

Closed
kieran-ryan opened this issue Sep 5, 2023 · 0 comments · Fixed by #210
Closed

Diagnostics support for undefined steps in scenario outlines #149

kieran-ryan opened this issue Sep 5, 2023 · 0 comments · Fixed by #210
Assignees
Labels
language agnostic ⚡ enhancement Request for new functionality

Comments

@kieran-ryan
Copy link
Member

kieran-ryan commented Sep 5, 2023

🤔 What's the problem you're trying to solve?

The Cucumber Language Service provides diagnostics support for whether steps in a scenario are 'undefined'. This support does not extend to scenario outlines. This is a result of the challenges associated with defining 'undefined steps' for scenario outlines in the context of parameters that reference examples table values (captured below).

Scenario with diagnostic for undefined step:

scenario_diagnostic

Scenario outline without diagnostic for undefined step:

scenario_outline_no_diagnostic

✨ What's your proposed solution?

Substitute examples table values into steps, before passing the steps to the undefined step validation function - this ensures no change is required to that logic. Additionally to ensure clear behaviour, to provide diagnostics for:

  • table value outliers that do not match the step definition
  • steps with parameters that do not have an associated header in the examples table

⛏ Have you considered any alternatives or workarounds?

The language service is embedded into tools used by editors such as Monaco and Visual Studio Code and thus there does not appear to be a workaround available for end users.

📚 Any additional context?

Challenges

Parameters may not be considered a match of a step definition

If we were to remove the scenario outline check, we would incorrectly observe that our defined step ("I have {int} cukes in my belly"), would be marked as 'undefined'. This is a result of the raw <qty> parameter not matching the regular expression for the type int itself, rather than for the values of <qty> in the examples table itself.

parameter_undefined_step

Ignoring steps with parameters may lead to unclear behaviour

We could modify the check that prevents checking the test for undefined steps if it is a scenario outline, to instead prevent checking test steps that have parameters only...

step: function (step, diagnostics) {
  const parameters = step.text.match(/<.*?>/g);
  if (parameters) {
    return diagnostics;
  }

  ...

  return diagnostics;
}

....This would ensure that steps without parameters are correctly checked whether they are undefined. However this may create unclear behaviour: defined steps and steps without parameters will both appear without diagnostics; as if they are both defined - which is not the case. Though one might argue that with the present solution, it could be misinterpreted that all steps in a scenario outline are defined, as they will not appear with any diagnostics.

ignore_parameters

Substituting values may lead to unclear behaviour until the examples table is populated

Alternatively, for steps with parameters, we could iterate through the parameter's example table values, substituting them into the test, and running it against the 'undefined' step validation function - which would not require modification.

If the step was considered defined with any data, then we can overall consider the step defined and do not need to assign it a diagnostic. Though we would need to mark any 'undefined' values within the examples table itself.

This would only work once the examples table has content and has a matching parameter. This again presents unclear behaviour where a step with parameters could be misinterpreted as defined until its associated examples table value is in place. To rectify this, a diagnostic could be applied to the parameter that it 'requires an associated header in an examples table' until it is authored. This would ensure it is appropriately annotated and prompt the user to populate the table, at which point it would be checked whether it's undefined.

@kieran-ryan kieran-ryan self-assigned this Sep 25, 2023
@kieran-ryan kieran-ryan changed the title Provide diagnostics support for undefined steps in scenario outlines Diagnostics support for undefined steps in scenario outlines Jan 7, 2024
@kieran-ryan kieran-ryan added the ⚡ enhancement Request for new functionality label Jan 7, 2024
@kieran-ryan kieran-ryan pinned this issue Mar 30, 2024
@kieran-ryan kieran-ryan removed their assignment Apr 23, 2024
@kieran-ryan kieran-ryan self-assigned this May 9, 2024
@kieran-ryan kieran-ryan unpinned this issue May 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
language agnostic ⚡ enhancement Request for new functionality
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant