Prerequisites
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 --version and node 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
Prerequisites
faqlabelnode 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
--bailand--exit. on a failed test, mocha stops and does not execute thesuiteTeardown().My assumption would have been that the
suiteTeardown()is always called, even after a failed test.Steps to Reproduce
no options:
only
--bail:only
--exit:both,
--bailand--exit:Expected behavior: I expect that in ALL cases, the suiteTeardown() is executed.
Actual behavior: If I give both,
--bailand--exit, the suiteTeardown() is not executed.Reproduces how often: 100%
Versions
mocha --versionandnode node_modules/.bin/mocha --version: 5.2.0node --version: v10.13.0Additional Information
n/a