jonsamwell / flutter_gherkin

A Gherkin parsers and runner for Dart and Flutter which is very similar to cucumber
MIT License
206 stars 110 forks source link

[Bug] onBeforeRunFeature not being called in a specific case #278

Open youssef-t opened 1 year ago

youssef-t commented 1 year ago

Version: 3.0.0-rc.17

Hello,

First of all, I would like to thank you for the package.

The issue is related to calling reporters before running a feature using the following method: https://github.com/jonsamwell/flutter_gherkin/blob/7c8be5f60e987e858d36502cc97af9a4ec7a5c66/lib/src/flutter/runners/gherkin_integration_test_runner.dart#L126

This method is called before running the first scenario, which is equivalent to calling it before the feature generally speaking. But, what if the first scenario was ignored using a tag expression ? In this case, the method onBeforeRunFeature will not be called.

The example using the integration_test package illustrates the issue: For the first scenario, onBeforeRunFeature is called https://github.com/jonsamwell/flutter_gherkin/blob/7c8be5f60e987e858d36502cc97af9a4ec7a5c66/example_with_integration_test/integration_test/gherkin_suite_test.g.dart#L93 But, for the second scenario, the method onBeforeRunFeature is not passed as an argument to it. As a consequence, onBeforeRunFeature cannot be called in any case.

It would be great to use another mechanism to detect the first scenario to run for a feature.

Thank you !

AFASbart commented 1 year ago

This is interesting, we then have to keep track which scenario is the actual first scenario that is being ran. I will take a look at this,

AFASbart commented 1 year ago

This is a bigger problem than I anticipated. We actually have 2 cases here, we have to check multiple things:

  1. Are there even scenario's that are being ran?
  2. If so, we can run the beforeFeature.
  3. Which scenario is the last scenario that is ran?
  4. The RunFeature function does not have any knowledge about any scenario's.

Bottom line, this is a bit more difficult to manage than I anticipated if I am honest.

youssef-t commented 1 year ago

I have been thinking about a clean solution. One way is to put the logic about the scenarios that will be run in the generated code gherkin_suite_test.g.dart. But, this will add some complexity. Furthermore , I don't know if it is not a bad practice to put some 'advanced logic' in the generated code.

The issue is also valid for the onAfterRunFeature method as it is run after the last scenario of a feature (which can be not run because of a tag expression).

If you think that this issue is worth fixing and adding some logic in the generated code to determine the scenarios that will be run is a clean solution, I can submit a PR in the near future.