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

Ability to name the hooks #73

Closed
suswariadla opened this issue Jul 9, 2020 · 15 comments
Closed

Ability to name the hooks #73

suswariadla opened this issue Jul 9, 2020 · 15 comments

Comments

@suswariadla
Copy link

Hi,
I don't see there is an ability to add names to the Before and After hooks rightnow.
Can the team consider adding the ability to name Before and After hooks so that they appear in the json reporter.

@davidjgoss davidjgoss transferred this issue from cucumber/cucumber-js Aug 7, 2020
@davidjgoss
Copy link
Contributor

@suswariadla would you mind elaborating on your use case a little? Interested to know the motivation and whether just attaching some text would be sufficient.

@suswariadla
Copy link
Author

Screen Shot 2020-08-14 at 10 16 18 AM

Hey @davidjgoss Thanks for Replying.
You see in the image, that is a shot from jenkins cucumber html reporter, how the statement looks for the Before hook. After taking a look in to json file which is the source for jenkins cucumber html reporter we found that the json file does not capture the Before hook name and infact the cucumberJs does not provide an option to define the hook name in its syntax.
So we request the flexibility to name the hooks in cucumberJs

@aslakhellesoy
Copy link
Contributor

I think this could be useful for reporting purposes. Would you be interested in helping us implement this @suswariadla?

Since the JSON format is now deprecated in favour of messages, this is something that would have to be added to the message protocol.

We probably wouldn't update the existing native JSON formatters, but we could update the standalone json formatter instead.

Cucumber implementations would have to extend the hook API. The syntax for various languages is already somewhat constrained because it's already used to pass tag expressions.

Proposed syntax:

JavaScript

Before({name: "Take out the rubbish"}, function () {
})

Java

@Before(name = "Take out the rubbish")
public void doSomething(){
    // Do something before each scenario
}

Ruby

Before(name: 'Take out the rubbish') do
end

@suswariadla
Copy link
Author

@aslakhellesoy Sure, I would be happy to implement it.

@aslakhellesoy
Copy link
Contributor

aslakhellesoy commented Aug 20, 2020

Thanks @suswariadla - much appreciated!

Here is a rough outline of the steps that should be taken:

  1. Add string name = 4; to https://github.com/cucumber/cucumber/blob/35c35561635555a0d098f2201d2806548dcfde47/messages/messages.proto#L632-L636
  2. Build it: cd messages then make
  3. npm link the node lib: cd javascript then npm link
  4. In Cucumber-JS, link @cucumber/messages - npm link @cucumber/messages
  5. Modify whatever needs to be modified in Cucumber.js to capture the hook name and add that name to the generated cucumber message

I think that's a good start. Eventually we'll also have to add an example to the compatibility kit's hook examples, and also improve fake-cucumber so it outputs hook messages with names.

We'll also have to update @cucumber/react so it can render the names of hooks.

For now I'd suggest focusing on the numbered list above.

Happy to answer any questions - I realise this is a bit light on detail.

@suswariadla
Copy link
Author

Hey @aslakhellesoy ,
I started working on this. I have a question from your instruction cucumber/common#4
When you referred Cucumber-JS does it exist as a folder in cucumber/
I tried to relate to other modules but I could not get a hint.

@mpkorstanje
Copy link
Contributor

You can find the Cucumber JS implementation here:

https://github.com/cucumber/cucumber-js

Messages (the module aslak you suggested to update) is a library that is used by Cucumber JS.

https://github.com/cucumber/cucumber-js/blob/master/package.json#L162

@stale
Copy link

stale bot commented Dec 15, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in a week if no further activity occurs.

@stale
Copy link

stale bot commented Dec 25, 2020

This issue has been automatically closed because of inactivity. You can support the Cucumber core team on opencollective.

@stale stale bot closed this as completed Dec 25, 2020
@dietergeerts
Copy link

Any progress on this? I would like to see the description/name of the hook in reports, as now it only shows Before, which isn't useful, especially when there are more before hooks.

@luke-hill
Copy link
Contributor

@suswariadla was the last person who was mentioning they would look at this. So I'll tag them to see if they worked on it.

I know no-one from the core team has spent time working on this.

If you are wanting to work on it yourself, let us know and someone might be able to help.

@suswariadla
Copy link
Author

Hey, nope. I did not finish it

@dietergeerts
Copy link

If you are wanting to work on it yourself, let us know and someone might be able to help.

Well, I don't have sufficient time right now, and this change isn't a minor one from what I see. (minor in the sense that it needs lots of changes, not that it would be a hard one). When I get the time in the future, and this isn't yet implemented, I can take another look into implementing it.

@davidjgoss
Copy link
Contributor

davidjgoss commented Dec 10, 2021

I'm happy to pitch in on this. I think we can do it in a few stages:

@luke-hill
Copy link
Contributor

Closing this as completed. We have named hooks being tested in the cck fully for all cck conformant cucumbers.

Any new cucumber flavours that would need conformancy would need to pass this step in the CCK. I know the main ones are already working with it

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

No branches or pull requests

7 participants