I have some requirement that demands to retry mocha failure tests multiple times. Is there any easy way/workaround to do this?

I tried https://github.com/giggio/mocha-retry, but it doesn't seem to work for me 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


Solution 1:

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

If your test case fail than it will re-execute the same test case again until the max no of retries reached or test case get passed. Once your test case get passed it will jump to the next test case.

Solution 2:

There is possibility to ask mocha to retry failed tests in the console:

mocha test/retry.js -g 'sample test' --retries 2