1

I have two tests directories. Unit tests, and integration tests. Both use mocha.

Unit tests run on average between 1-5 ms. Unfortunately our integration tests take longer. Some of them up to 30 seconds.

I was wondering if I could set the timeout to 30 seconds only for the test/integration directory, but leave test/unit using the default mocha timeout (2 seconds) in the mocha.opts file. Or perhaps have multiple mocha.opts files.

jac0117
  • 77
  • 8

1 Answers1

0

There's no support for multiple mocha.opts files being active for a single invocation of Mocha. You could have two Mocha invocations each with their own mocha.opts, however.

If you want everything in a single Mocha invocation, and set different timeouts for different parts of the suite, there's no direct way for telling Mocha "files in this directory have one timeout, and files in that other directory have another timeout". You are limited to calling this.timeout in your callbacks, like this:

describe("User view", function () {
  this.timeout(...);

  // Tests....
});

If you structure your suite so that all integration tests are seen by Mocha as being descendants of a single top describe, you can effectively set this timeout in only one location (the top describe) for all your integration tests. See this question and its answers for ways to structure a suite in this way.

Community
  • 1
  • 1
Louis
  • 146,715
  • 28
  • 274
  • 320