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

hooks: Add BeforeStep and AfterStep Hooks #1416

Merged
merged 123 commits into from Nov 16, 2020

Conversation

Adam-ARK
Copy link
Contributor

Another PR attempt to get BeforeStep/AfterStep hooks (#1058) promoted into the project (hopefully for the 7.0.0 release), since the current open PR(#997) hasn't been touched since May. This PR used PR #997 as the base, fixing all existing issues to get all unit/feature tests passing, and fixed merge conflicts with latest code. Then used the feature files from PR #1058 to add tests for functionality.

Also updated files under /docs/ to describe the new hook usage.

Not sure what all is still required before this attempted solution can be merged, besides possibly more unit tests?

@Adam-ARK
Copy link
Contributor Author

Adam-ARK commented Sep 2, 2020

@charlierudolph Could you take a look at this PR when you get the chance?

@davidjgoss Is there a possibility of getting this into the 7.0.0 release?

@mpkorstanje
Copy link
Contributor

@aslakhellesoy can you review this or find some one to review it?

@aslakhellesoy
Copy link
Contributor

I’ll try to get it done this week

@davidjgoss
Copy link
Contributor

I should be able to review tonight - sorry for delay

Copy link
Contributor

@davidjgoss davidjgoss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you mentioned we should add appropriate unit test coverage for pickle_runner and support_code_library_builder.

Also a recent addition is that we emit messages for support code definitions that can be picked up by formatters - could you follow this pattern for these new hooks? See https://github.com/cucumber/cucumber-js/blob/master/src/cli/helpers.ts#L246

src/runtime/pickle_runner.ts Outdated Show resolved Hide resolved
docs/support_files/api_reference.md Outdated Show resolved Hide resolved
docs/support_files/hooks.md Outdated Show resolved Hide resolved
docs/support_files/hooks.md Outdated Show resolved Hide resolved
src/support_code_library_builder/types.ts Outdated Show resolved Hide resolved
@Adam-ARK
Copy link
Contributor Author

@davidjgoss I've finished addressing all your code review comments and adding unit tests where appropriate. Please let me know of any other changes/updates I still need to make to this pull request.

@Adam-ARK
Copy link
Contributor Author

Adam-ARK commented Oct 21, 2020

@charlierudolph Apologies for the bad commit history, accidentally did a merge instead of rebase with master.

Got everything working again with your changes, and did the changes you requested. Now there's just 1 runStepHooks function, and removed isSkippingStep(), and returns the array

For the runStep function, I still have it not run the step itself if any of the beforeStep hooks fail, as this is in-line with how the Before Scenario hooks won't run a scenario if they fail, unless we want them to be different? (or my use of Before Scenario hooks in my projects just makes me think this is how they work. I can easily change this if we want.)

Otherwise I refactored the function with this workflow:
// Run before hooks, step and after hooks
// Set the final result to be the stepDef result since it has the messages data
// get the worst status from the step/hooks and update the final result with it
// sum all the durations together into the final result

I feel like this is good?

@davidjgoss davidjgoss mentioned this pull request Oct 25, 2020
5 tasks
@Adam-ARK
Copy link
Contributor Author

@charlierudolph @davidjgoss Any other comments / review for this PR? Or are we good to finally merge this?

@charlierudolph
Copy link
Member

I agree with not running the step if a beforeStepHook fails but we should always run afterStepHooks.

@Adam-ARK
Copy link
Contributor Author

Adam-ARK commented Nov 2, 2020

@charlierudolph Updated the variable names, and made the change so that the only thing that won't happen if the beforeStep Hooks fail, is that the step itself won't run, but afterStep Hooks / sum duration will.

@charlierudolph charlierudolph merged commit 4e6a9ee into cucumber:master Nov 16, 2020
@aslakhellesoy
Copy link
Contributor

Hi @Adam-ARK,

Thanks for your making your first contribution to Cucumber, and welcome to the Cucumber committers team! You can now push directly to this repo and all other repos under the cucumber organization! 🍾

In return for this generous offer we hope you will:

  • ✅ Continue to use branches and pull requests. When someone on the core team approves a pull request (yours or someone else's), you're welcome to merge it yourself.
  • 💚 Commit to setting a good example by following and upholding our code of conduct in your interactions with other collaborators and users.
  • 💬 Join the community Slack channel to meet the rest of the team and make yourself at home.
  • ℹ️ Don't feel obliged to help, just do what you can if you have the time and the energy.
  • 🙋 Ask if you need anything. We're looking for feedback about how to make the project more welcoming, so please tell us!

On behalf of the Cucumber core team,
Aslak Hellesøy
Creator of Cucumber

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants