I'm trying to use mocha retry for async test and it doesn't seem to work. when the test fail (in the context of the callback) it will not call done() and therefore the retry doesn't work.
I have already many tests written this way and i need a solution that will not require to change all tests flows
var should = require('should');
var counter = 0;
describe('async',function(){
it('AsyncTest', function(done) {
setTimeout(function()
{
console.log('attempt::', counter++);
counter.should.equal(3);
done();
}, 300);
});
});
The following trivial code is working in sync test:
var counter = 0;
var should = require('should');
describe('sync', function() {
it('sync', function() {
if(counter > 1) {
console.log('counter::', counter);
} else {
counter++;
counter.should.equal(10);
}
});
});
Running the async code result: mocha testRetries.js --timeout 259200000 --ui bdd --retries 3
async attempt:: 0 1) AsyncTest
0 passing (319ms) 1 failing
1) async AsyncTest:
Uncaught AssertionError: expected 1 to be 3
+ expected - actual
-1
+3
at Assertion.fail (/Users/shaylang/dev/nodejsautomation/src/node_modules/should/cjs/should.js:258:17)
at Assertion.value (/Users/shaylang/dev/nodejsautomation/src/node_modules/should/cjs/should.js:335:19)
at Timeout._onTimeout (testRetries.js:20:27)
Running the sync code result:
mocha testRetries.js --timeout 259200000 --ui bdd --retries 3
sync counter:: 2 ✓ sync
1 passing (8ms)
mocha --version 6.1.4