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

Add afterAll hooks #97

Closed
jbpros opened this issue Nov 7, 2012 · 21 comments
Closed

Add afterAll hooks #97

jbpros opened this issue Nov 7, 2012 · 21 comments

Comments

@jbpros
Copy link
Member

jbpros commented Nov 7, 2012

From #84 (comment).

@mwinteringham
Copy link

+1

1 similar comment
@JRedgrave
Copy link

+1

@aslakhellesoy
Copy link
Contributor

What are all these strange patches that add a single line with a 1?

I'm not sure that implementation is complete!

@namukang
Copy link

namukang commented Aug 8, 2013

+1

3 similar comments
@3Thomson14
Copy link

+1

@ahoffmann
Copy link

+1

@corinna000
Copy link

+1

@DavidSouther
Copy link

Any progress on this in the past year?

@jbpros
Copy link
Member Author

jbpros commented Nov 27, 2013

While this is not a definitive solution, the recently-added registerHandler() method (available on NPM as of 0.3.2) can help you run code at the end of the run:

module.exports = function () {
  this.registerHandler('AfterFeatures', function (event, callback) {
    console.log("finished running scenarios", event);
    // do your stuff
    callback();
  });
};

registerHandler() is considered unstable API at the moment. I'm not sure we'll keep it in and we still want a decent this.AfterAll() helper at some point.

One potential issue I see (and tested) with this solution is that calling back with an error will not make Cucumber fail the run. @devpaul is that a bug in your opinion?

@devpaul
Copy link
Contributor

devpaul commented Dec 2, 2013

@jbpros I believe it should be considered a bug. It doesn't follow convention.

@jwoudenberg
Copy link

To me, it wouldn't make sense if an event handler can make the piece of code that triggered it throw an error, that's now how I expect events to work (they listen).

Also, the handler does not get the world as a context as reported in #244. Again, from the perspective of it being an event, that makes sense to me. When using it as an AfterAll hook however, this is a serious shortcoming.

@djungowski
Copy link

@jbpros This does not help either since a handler registered this way is executed after every feature file.

@djungowski
Copy link

Furthermore, the README is completely misleading on the behavior of AfterFeatures:

The after features event is emitted once all features have been executed, just before the process exits. It can be used for tasks such as closing your browser after running automated browser tests with selenium or phantomjs.

No, it is not. It is executed after every set of features (=feature file)

@jbpros
Copy link
Member Author

jbpros commented Dec 23, 2014

@djungowski no, AfterFeatures is triggered only once per run, after all features and their scenarios were processed. The README section related to it looks good to me. How do you think it's misleading?

@jbpros jbpros removed the ready label Jul 3, 2015
@jbpros jbpros removed this from the major features milestone Oct 10, 2015
@charlierudolph
Copy link
Member

Closing as registerHandler now has full support and the passed function can use any of the available interfaces that steps/hooks use and when passed an error it will throw it and kill the test run.

@jwbuitenhuis
Copy link

In which version is that enhancement? I've tried it in 0.10.4 but it doesn't seem to respond to callback(new Error('foo')).

@charlierudolph
Copy link
Member

In the future please see the changelog. Searching through it, it appears it was added in 1.1.0

@alayor
Copy link

alayor commented Feb 16, 2017

@charlierudolph Could you tell me how I can use registerHandler using defineSupportCode?

var {defineSupportCode} = require('cucumber');

@charlierudolph
Copy link
Member

Please see the docs for "Event Handlers". There is a link on the README

@kyleian
Copy link

kyleian commented Mar 5, 2017

Hate to pull this one out of the grave again, but per @charlierudolph's comment, can you clarify the expectation is that passing an error to the registerHandler callback should infact kill the entire test run?

In my use case/need, I'd like to fail exclusively the scenario if an error is raised during the AfterScenario hook, but continue the suite after marking that scenario as failed (in the way I can during a step); is this achievable with 1.3.1+? My example usecase would be in the event of failing to tear down mocks generated during the scenario.

e: after looking around for some different examples this comment seems to directly answer my question.

@lock
Copy link

lock bot commented Oct 25, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Oct 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests