Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mocha retry whole suite not only failing test

Tags:

mocha.js

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

like image 587
Rafael García Lara Avatar asked Nov 07 '22 00:11

Rafael García Lara


1 Answers

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

like image 182
deerawan Avatar answered Nov 28 '22 22:11

deerawan