Retry mocha

I have some kind of requirement requiring multiple repetition of mocha tests. Is there an easy way / workaround for this?

I tried https://github.com/giggio/mocha-retry , but for me this does not work with Mocha 1.21.3:

it (2, 'sample test', function(done) { expect(1).to.equal(2); done(); }); 

mocha test/retry.js -g 'sample test' --ui mocha-retry

+6
source share
2 answers
 it (2, 'sample test', function(done) { this.retries(2); pass the maximum no of retries expect(1).to.equal(2); done(); }); 

//this.retries(Maximum number of attempts);

If your test case fails, it will run the same test again until the maximum number of attempts or test test is reached. After passing the test test, he will proceed to the next test example.

+4
source

try{}catch and recursion

 var tries_threshold = 5; it(2, 'sample test', function(done) { var tries = 0; function actual_test() { expect(1).to.equal(2); } function test() { try { actual_test(); } catch (err) { if (err && tries++ < tries_threshold) test(); else done(err); } } test(); }); 

try{}catch will help prevent an error spike until you want it, and thus allow you to recursively continue trying.

0
source

Source: https://habr.com/ru/post/976847/


All Articles