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

Errors in before hooks exit with status 0 when --bail is used #3367

Closed
4 tasks done
lathonez opened this issue May 1, 2018 · 1 comment
Closed
4 tasks done

Errors in before hooks exit with status 0 when --bail is used #3367

lathonez opened this issue May 1, 2018 · 1 comment

Comments

@lathonez
Copy link

lathonez commented May 1, 2018

Prerequisites

  • Checked that your issue hasn't already been filed by cross-referencing issues with the faq 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

When using the --bail flag, mocha will exit with a status of 0, instead of 1, when it encounters an error in before hooks. This potentially causes CI to pass when it should fail.

Steps to Reproduce

let describe = require('mocha').describe;
let before = require('mocha').before;

describe('before-all-working', function() {
  before(function() {
    console.log('before hook');
    throw new Error('before hook error');
  });

  it('test', function() {});
});
xps:../backend-issue-965$ ./node_modules/.bin/mocha 


  before-all-working
before hook
    1) "before all" hook


  0 passing (4ms)
  1 failing

  1) before-all-working
       "before all" hook:
     Error: before hook error
      at Context.<anonymous> (test:7:11)



xps:../backend-issue-965$ echo $?
1
xps:../backend-issue-965$ ./node_modules/.bin/mocha --bail


  before-all-working
before hook

  0 passing (3ms)

    1) "before all" hook

xps:../backend-issue-965$ echo $?
0

Expected behavior: mocha exits with status 1

Actual behavior: mocha exits with status 0

Reproduces how often: 100%

Versions

  • The output of mocha --version and node node_modules/.bin/mocha --version: not globally installed / 5.1.1
  • The output of node --version: 8.11.1
  • The version and architecture of your operating system: Ubuntu 16.04.4 LTS x64
  • Your shell (bash, zsh, PowerShell, cmd, etc.): bash
  • Your browser and version (if running browser tests): N/A
  • Any other third party Mocha related modules (with versions): N/A
  • The code transpiler being used: N/A

Additional Information

None

@outsideris
Copy link
Contributor

duplicated #3303
And it already fixed in #3346 , but we didn't release new version yet.
Thank you.

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

2 participants