Debug Mocha tests with Webstorm: mocha test timeouts are not respected

I've got a bunch of API tests written using Mocha. Most of them have non-default timeouts set.

When running test in 'Run' mode - test fail as expected if timeout is exceeded.

When running in 'Debug' mode - test is never failed on timeout, it will hang forever instead.

Is there some setting I'm missing to make it fail in debug mode too, or is it a bug?

 

UPD: Webstorm 2017.3.1

It was working fine in some previous version of Webstorm.

0
8 comments

Please can you provide a sample project I can use to recreate the issue?

0
Avatar
Permanently deleted user

Here's an example to reproduce:

var waitForSomething = function () {
  return function (done) {
    this.timeout(5000);
    var interval = setInterval(function () {
      if (2 > 3) {
        clearInterval(interval);
        done();
      }
    }, 500);
  };
};

describe('Test timeout', function (){
 
  it('With timeout', waitForSomething());
 
  it('Without timeout', function (){
    console.log('blah-blah');
  });
 
});

My Run/Debug config looks like this:

0

Looks as if something has changed in the way mocha handles async tests without done() call when timeout is disabled... When debugging, Webstorm disables timeouts by passing --timeout 0 to mocha (see https://youtrack.jetbrains.com/issue/WEB-9860#comment=27-628129). With Mocha 1.21.4, mocha --timeout 0 --ui bdd yourtest.js fails with Error: timeout of 5000ms exceeded. With Mocha 4, the same command hangs infinitely...

0
Avatar
Permanently deleted user

Hm... rechecked with mocha 2.3 and it's the same - no timeout. But it was working on my previous Webstorm installation (2017 something most probably). And I never had mocha older than 2.3.

0

tried it in 2017.2 - same result... Don't have mocha > 2 < 4 for testing

0
Avatar
Permanently deleted user

Sadly the "Extra Mocha options" from the "Run/Debug Configuration" get prepended to the --timeout 0 option. Which then overrides it. So no luck there :-(

0
Avatar
Permanently deleted user

try to add "-- --timeout=2000" it works here. 

0

Please sign in to leave a comment.