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 );
mochain the wrong place within your Truffle configuration file. Or you could possibly have two configuration files -truffle.jsortruffle-config.js- Truffle would default for the former, but you've addedmochato the latter. – goodvibration Sep 10 '19 at 13:24before_timeoutwas possiby added in a more recent version of Mocha, used by a more recent version of Truffle, which you are possibly using (5.x?). At the time of writing this answer, Truffle version was 4.x. – goodvibration Sep 10 '19 at 17:58