mocha
mocha copied to clipboard
🚀 Feature: Retry logic should accommodate a timeout between retries
this.retries(N);
should support a timeout value before attempting to run the test again.
A signature like this.retries(N[, M]);
where N is the # of retries & M is the # of ms to wait before trying the test again would be ideal
This would be great for my end-to-end tests
yes this will be really helpful. Waiting for this to be implemented :)
I was able to use beforeEach
to delay test execution in case of retries - in the following example we need to back off proportionally to the number of failures, but it can easily be a constant
describe(....
// delay after first failure
beforeEach(function(done){
if(this.currentTest.currentRetry() > 0){
setTimeout(done, this.currentTest.currentRetry() * 500);
} else {
done();
}
})
this.retries(2)
...
// test cases here
it( ....
This seems reasonable to me. I think we'd probably want to make the second parameter to retries
an optional object that may contain a property like wait
. Two benefits:
- It'll be more clear what this new number is doing
- If more settings get requested in the future, we don't have to have two allowed types for the second parameter
cc @mochajs/maintenance-crew
Chatted with @voxpelli: this seems reasonable and straightforward to implement, and we don't think this will open too many rabbit holes. 🤞