cucumber / messages

A message protocol for representing results and other information from Cucumber
MIT License
21 stars 19 forks source link

Ability to name the hooks #73

Closed suswariadla closed 5 months ago

suswariadla commented 4 years ago

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 commented 4 years ago

@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 commented 4 years ago
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 commented 4 years ago

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 commented 4 years ago

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

aslakhellesoy commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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[bot] commented 3 years ago

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[bot] commented 3 years ago

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

dietergeerts commented 3 years ago

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 commented 3 years ago

@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 commented 3 years ago

Hey, nope. I did not finish it

dietergeerts commented 3 years ago

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 commented 2 years ago

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

luke-hill commented 5 months ago

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