Skip to content

Bail with failing after() runs suite twice #3096

Closed

Description

Prerequisites

  • Checked that your issue isn't already filed by cross referencing issues with the common mistake label
  • Checked next-gen ES issues and syntax problems by using the same environment and/or transpiler configuration without Mocha to ensure it isn't just a feature that actually isn't supported in the environment in question or a bug in your code.
  • 'Smoke tested' the code to be tested by running it outside the real test suite to get a better sense of whether the problem is in the code under test, your usage of Mocha, or Mocha itself
  • Ensured that there is no discrepancy between the locally and globally installed versions of Mocha. You can find them with:
    node node_modules/.bin/mocha --version(Local) and mocha --version(Global). We recommend avoiding the use of globally installed Mocha.

Description

With a failing test suite using the bail option in conjuncture with an after clause that throws an error.
Mocha bails properly, executes the after as expected.
Then it does it all again. But Why?

Steps to Reproduce

Very simple repro steps.
File new with latest mocha.

"scripts": {
    "test": "./node_modules/.bin/mocha --reporter spec --bail"
  }

and

describe("some suite", function() {
    it("does the first test", function() {
        throw new Error('first error')
    });
    after(() => {
        throw new Error('after error')
    })
})

yarn test, observe double suite run
remove error in after, observe one suite run

Expected behavior: [What you expect to happen]
test suite is only ran once
Actual behavior: [What actually happens]
test suite is ran twice
Reproduces how often: [What percentage of the time does it reproduce?]
100%

Versions

node node_modules/.bin/mocha --version => 4.0.1
macOS Sierra 10.12.6
zsh

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

Metadata

Labels

status: accepting prsMocha can use your help with this one!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