I'm trying to configure mocha to retry a whole suite if any test fails.
I navigate to a URL then populate a form and submit, then the users get redirected and if some element is found the last test passes.
If the element is not found i need to navigate to the form again, fill it and submit, re-running the whole suite N times.
I have tried with this.retries() at describe and it levels, also bail and retries flags but mocha ONLY retries the failing test.
var count = 0
describe('Main suite', function () {
this.retries(5)
it('Some setup', () => {
console.log('1. Some setup');
});
it("bail issue", function() {
console.log('2. bail issue');
if (count < 4) {
count += 1
throw new Error("Must be retried")
}
})
});
describe('end', function () {
it('close', () => {
});
});
mocha
Based on Mocha documentation, retries
purpose is for failed tests only
You can choose to retry failed tests up to a certain number of times. This feature is designed to handle end-to-end tests (functional tests/Selenium…) where resources cannot be easily mocked/stubbed. It’s not recommended to use this feature for unit tests.
Ref: - https://mochajs.org/#retry-tests
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With