Skip to content

Bail flag causes before() hooks to be run even after a failure #1812

Closed

Description

Example file:

describe('one', function(){
  it('fails', function(){
    throw Error("failed");
  });
});

var slowHook = function(next) {
  console.log("hook");
  setTimeout(next, 1000);
};

describe('two', function(){
  before(slowHook);
  it('never runs', function(){ });
});

describe('three', function(){
  before(slowHook);
  it('never runs', function(){ });
});

describe('four', function(){
  before(slowHook);
  it('never runs', function(){ });
});

So what I'm seeing is that when you run this with --bail and the first test fails, it keeps going and runs all the other hooks before actually quitting. The output looks like this:

$ mocha --version
2.2.5
$ mocha timeout.js -b


  one
    1) fails

  two
hook

  three
hook

  four
hook


  0 passing (3s)
  1 failing

  1) one fails:
     Error: failed
      at Error (<anonymous>)
      at Context.<anonymous> (timeout.js:3:11)

In our actual code base we have hundreds of test suites each with sometimes lengthy hooks that set up and tear down fixtures in the db. When you run the whole suite with -b, you might see one red dot, and then it appears to hang for over a minute while it is running all the other hooks. Finally it reports with the failure. I can't think of why this would be desirable, so my best guess is that it is a bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    type: buga defect, confirmed by a maintainer

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions