vitalets / playwright-bdd

BDD testing with Playwright runner
https://vitalets.github.io/playwright-bdd/
MIT License
302 stars 36 forks source link

Question: Decorator Steps Jump to Definition #168

Open helmutchecker opened 3 months ago

helmutchecker commented 3 months ago

Following the documentation regarding decorators, I have set this configuration properties for VSCode Cucumber autocomplete:

    "cucumberautocomplete.steps": ["test-features-steps/*.ts", "pages/**/*.ts"],
    "cucumberautocomplete.syncfeatures": "test-features/*.feature",
    "cucumberautocomplete.strictGherkinCompletion": false,

I defined @Fixture decorator on the Page Object and @Given decorator for a step. The step is correctly found via autocompletion when modifying the feature, but unfortunately jumping from there to the implementation of the step is failing and leading to a different file on a comment line which is not really connected to the decorated step. Jumping to the definition is working for "regular" step definitions with old notation, but for those defined by decorators it does not work.

Am I missing some additional setting, or is there a limitation with jump to definition?

vitalets commented 3 months ago

The setup is correct, it should work. Could you check, maybe you have another Cucumber extension enabled, e.g. this one?

helmutchecker commented 3 months ago

Indeed, there was another previous extension installed for syntax highlighting. After removal, it works for simple decorator steps, but not for ones using a parameter:

  @Given("page is opened for ID {int}")
  async navigate(id: number) {
    await this._navigate(`/id/${id}`);
  }

I noticed the limitation for custom parameters, but this native param int should be working, right?

vitalets commented 3 months ago

Yes, it should work for steps with parameters as well. I've checked with exactly the same step name - works for me. My settings.json:

{
  "cucumberautocomplete.steps": ["steps/**/*.ts"]
}

Suggestions:

For multiple extensions conflict I will update the docs.

helmutchecker commented 3 months ago

It is very strange. I have one page object that is working fully for navigation to decorated steps with and without parameters. Another page object in the same directory is not working at all for decorated steps.

I also tested the example which is also working as expected.

Maybe this could also be an issue of the Gherkin extension itself.

vitalets commented 3 months ago

If possible - could you try to reproduce your code structure on decorators branch in example? I will check in my vscode setup.

helmutchecker commented 3 months ago

I tracked the issue down in my project, but I am unable to reproduce it for your example so I am unsure about the root cause. In one of my page objects, I have TSDoc in following format:

  /**
   * Description
   *
   * @example
   * // Comment for example
   * const void= await waitForX();
   * @example
   * // Comment y
   * const void= await  waitForX();
   */
  async waitForX() {}

The parsing issue is caused by the // after the @example decorator. When I delete those two lines or even only the //, all steps are correctly found and navigated to. If I keep them, all steps from all page objects in all previous positions in that directory and in previous directories cannot be jumped to. All following page objects are working as expected.

Strange that I cannot reproduce it in your example, but maybe this description can be a hint where / in which extension or code the root cause might be.

vitalets commented 3 months ago

@helmutchecker did you try to use that Cucumber extension instead of cucumberautocomplete? maybe it will handle tsdoc properly.

Meanwhile I've updated docs on conflicting VSCode extensions, thanks for highlighting that.