mirror of
https://github.com/embarklabs/embark.git
synced 2025-02-26 04:15:29 +00:00
feat(@embark/test-runner): wait for deploy before enterning describe
This commit is contained in:
parent
ae5b92ff45
commit
8c16541019
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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');
|
||||
});
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user