diff --git a/dapps/tests/app/test/another_storage_spec.js b/dapps/tests/app/test/another_storage_spec.js index c054c3534..143e6ef92 100644 --- a/dapps/tests/app/test/another_storage_spec.js +++ b/dapps/tests/app/test/another_storage_spec.js @@ -27,8 +27,13 @@ config({ }); contract("AnotherStorage", function() { + const defaultAccount = accounts[0]; this.timeout(0); + it("should have got the default account in the describe", function () { + assert.strictEqual(defaultAccount, accounts[0]); + }); + it("should have account with balance", async function() { let balance = await web3.eth.getBalance(accounts[0]); assert.ok(parseInt(balance, 10) > 4900000000000000000); diff --git a/packages/embark-test-runner/src/index.js b/packages/embark-test-runner/src/index.js index e4e92bcb1..49f88ba84 100644 --- a/packages/embark-test-runner/src/index.js +++ b/packages/embark-test-runner/src/index.js @@ -208,6 +208,7 @@ class TestRunner { let fns = files.map((file) => { return (cb) => { const mocha = new Mocha(); + mocha.delay(); const gasLimit = options.coverage ? COVERAGE_GAS_LIMIT : GAS_LIMIT; const reporter = options.inProcess ? EmbarkApiSpec : EmbarkSpec; mocha.reporter(reporter, { @@ -219,17 +220,35 @@ class TestRunner { mocha.addFile(file); mocha.suite.timeout(0); - mocha.suite.beforeAll('Wait for deploy', (done) => { + + function describeWithWait(describeName, callback) { if (global.embark.needConfig) { global.config({}); } - global.embark.onReady(done); + global.embark.onReady(() => { + // Next tick makes sure to not have a hang when tests don't use `config()` + // I think this is needed because Mocha expects global.run() to be called ina further event loop + process.nextTick(() => { + self.ogMochaDescribe(describeName, callback); + global.run(); // This tells mocha that it can run the test (used in conjunction with `delay()` + }); + }); + } + + mocha.suite.on('pre-require', function() { + // We do this to make such our globals don't get overriden by Mocha + global.describe = describeWithWait; + global.contract = describeWithWait; }); + // This populates Mocha to have describe(), etc. + mocha.suite.emit('pre-require', global, file, mocha); + mocha.run(function (fails) { mocha.suite.removeAllListeners(); // Mocha prints the error already cb(null, fails); }); + self.ogMochaDescribe = Mocha.describe; }; }); async.series(fns, next); diff --git a/packages/embark-test-runner/src/test.js b/packages/embark-test-runner/src/test.js index 9b2ce212b..a47a15408 100644 --- a/packages/embark-test-runner/src/test.js +++ b/packages/embark-test-runner/src/test.js @@ -250,8 +250,8 @@ class Test { // TODO Do not exit in case of not a normal run (eg after a change) if (!self.options.inProcess) process.exit(1); } - self.events.emit('tests:ready'); callback(null, accounts); + self.events.emit('tests:ready'); }); }