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

Adding ordering in Before hook #1128

Merged
merged 4 commits into from
Nov 26, 2023
Merged

Conversation

VidhiRambhia
Copy link

No description provided.

@VidhiRambhia VidhiRambhia marked this pull request as ready for review November 23, 2023 06:03
lib/registry.ts Outdated
(a: ICaseHook, b: ICaseHook) => {
// If order is not specified, the hook will be executed at the end
if (a.order === undefined) {
a.order = Number.MAX_SAFE_INTEGER;
Copy link
Owner

Choose a reason for hiding this comment

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

Default order should be made to 10000 in order to mimic behavior seen in other implementations, ref. cucumber/cucumber-jvm@1a5e98d.

Copy link
Author

Choose a reason for hiding this comment

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

Done

lib/registry.ts Outdated
@@ -65,6 +65,7 @@ export interface ICaseHook {
position?: Position;
tags?: string;
name?: string;
order?: number;
Copy link
Owner

Choose a reason for hiding this comment

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

Make this required and give it a default value during assignment.

Copy link
Author

Choose a reason for hiding this comment

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

Makes sense, addressed this

@badeball
Copy link
Owner

Order is an option in all hooks in the jvm implementations and should such be added here given the goal is conformity.

@badeball
Copy link
Owner

badeball commented Nov 23, 2023

Each hook deserve more comphrehensive testing than this and requires separate tests (ie. don't mix it with "the big one"). I imagine essentially three scenarios for each hook:

  • Before / Before: in order
  • Before / Before(order: 10000): in order
  • Before / Before(order: 9999): reversed

.. with similar tests for each other type of hook. This can be accomplished using X scenario outlines.

@VidhiRambhia
Copy link
Author

VidhiRambhia commented Nov 23, 2023

Order is an option in all hooks in the jvm implementations and should such be added here given the goal is conformity.

Thanks for your feedback, @badeball! So ordering has to be implemented in all of these - Before, After, BeforeStep, AfterStep, BeforeAll, AfterAll?

Also, I understand we reverse the order of After hooks
public resolveAfterHooks(tags: string[]) { return this.resolveCaseHooks("After", tags).reverse(); }
With the new approach which takes into account ordering, should this stay the same? ie we reverse sorted hooks?

@badeball
Copy link
Owner

Yes, all hooks and yes, reverse sorted in all after-type hooks!

@VidhiRambhia
Copy link
Author

Each hook deserve more comphrehensive testing than this and requires separate tests (ie. don't mix it with "the big one"). I imagine essentially three scenarios for each hook:

  • Before / Before: in order
  • Before / Before(order: 10000): in order
  • Before / Before(order: 9999): reversed

.. with similar tests for each other type of hook. This can be accomplished using X scenario outlines.

Is it a good idea to put all of these tests in the same feature file (hooks_ordering.feature)? Or should I create a separate feature file for each hook?

@badeball
Copy link
Owner

Is it a good idea to put all of these tests in the same feature file (hooks_ordering.feature)?

Yeah, one feature file is fine for this purpose.

@VidhiRambhia
Copy link
Author

Addressed your comments @badeball. Please let me know your thoughts on it!

badeball added a commit that referenced this pull request Nov 26, 2023
Primarily introducing scenario outlines as a shorter alternative.
@badeball badeball merged commit c6358a7 into badeball:master Nov 26, 2023
6 checks passed
@badeball
Copy link
Owner

Excellent, thank you. I've merged and released this with v19.2.0. For reference, you can check out 1e3643a to see how I used scenario outlines to shorten everything.

@VidhiRambhia
Copy link
Author

Excellent, thank you. I've merged and released this with v19.2.0. For reference, you can check out 1e3643a to see how I used scenario outlines to shorten everything.

I'll go through it. Thank you, @badeball!

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

2 participants