-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Closed
Description
Prerequisites
- Checked that your issue hasn't already been filed by cross-referencing issues with the
faqlabel - 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) andmocha --version(Global). We recommend avoiding the use of globally installed Mocha.
Description
Using mocha TDD ( https://mochajs.org/#tdd ), and calling mocha with --bail and --exit. on a failed test, mocha stops and does not execute the suiteTeardown().
My assumption would have been that the suiteTeardown() is always called, even after a failed test.
Steps to Reproduce
suite('suite', () => {
suiteSetup(() => {
console.log('suiteSetup');
});
suiteTeardown(() => {
console.log('suiteTeardown');
});
test('mytest', done => {
console.log('mytest');
done(new Error('fail'));
});
test('mytest async', async() => {
console.log('mytest async');
throw new Error('fail');
});
});
no options:
$ mocha --ui tdd test/units/
suite
suiteSetup
mytest
1) mytest
mytest async
2) mytest async
suiteTeardown
0 passing (11ms)
2 failing
1) suite
mytest:
Error: fail
at Context.done (test/units/testTests.js:15:10)
2) suite
mytest async:
Error: fail
at Context.test (test/units/testTests.js:21:11)
only --bail:
$ mocha --bail --ui tdd test/units/
suite
suiteSetup
mytest
1) mytest
0 passing (9ms)
1 failing
1) suite
mytest:
Error: fail
at Context.done (test/units/testTests.js:15:10)
suiteTeardown
only --exit:
$ mocha --exit --ui tdd test/units/
suite
suiteSetup
mytest
1) mytest
mytest async
2) mytest async
suiteTeardown
0 passing (11ms)
2 failing
1) suite
mytest:
Error: fail
at Context.done (test/units/testTests.js:15:10)
2) suite
mytest async:
Error: fail
at Context.test (test/units/testTests.js:21:11)
both, --bail and --exit:
$ mocha --bail --exit --ui tdd test/units/
suite
suiteSetup
mytest
1) mytest
0 passing (9ms)
1 failing
1) suite
mytest:
Error: fail
at Context.done (test/units/testTests.js:15:10)
Expected behavior: I expect that in ALL cases, the suiteTeardown() is executed.
Actual behavior: If I give both, --bail and --exit, the suiteTeardown() is not executed.
Reproduces how often: 100%
Versions
- The output of
mocha --versionandnode node_modules/.bin/mocha --version: 5.2.0 - The output of
node --version: v10.13.0 - The version and architecture of your operating system: ubuntu 18.04
- 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
n/a
Metadata
Metadata
Assignees
Labels
No labels