8

I'm running my tests on a private chain and some of them times out:

  1)  "before all" hook:
     Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.

I tried to set timeout to the whole test or to the before part as per mocha documentation:

contract("looong tests", accounts => {
   this.timeout();

or

before( done => {
   this.timeout(40000);

I got this error:

  1)  "before all" hook:
     TypeError: _this.timeout is not a function

Adding -t command line parameter doesn't seem to have any effect:

truffle test myTest.js -t 40000
truffle test myTest.js --timeout 40000

I see an old pending fix in truffle: https://github.com/trufflesuite/truffle/issues/261

How can I increase the timeout for the before statement?

Adding timeout to individual test cases works but not for before statement :(

   it('one long test', () => {
        ....
    }).timeout(40000 ); 

EDIT: I've a workaround for now, moved the code from before to the first test which I've made sync:

   it('should go to before block but can't set timeout there', done =>  {
        new Promise( async function (resolve, reject) {
          // my before code 
          resolve();
        }).then( res => {
         done();
        });
    }).timeout(40000 ); 
3

Add this in your Truffle configuration file (truffle.js or truffle-config.js):

mocha: {
    enableTimeouts: false
}

If you want to preserve timeouts (and even configure different timeouts for different tests), then simply follow the instructions here.

0

you cannot access this from a () => {} style function. If you want to use this.timeout() in the before block you need to do a

before(function() {
   ...
});
0

As an amendment to the answer provided by goodvibration: it matters where you place that code snippet inside of truffle.js. For me it only worked inside of module.exports at the highest level (not inside of other things like networks).

Here is what worked for me:

module.exports = {
  mocha: {
    enableTimeouts: false
  }
};

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.