feat(@embark/test-runner): return accounts in the describe callback

This commit is contained in:
Jonathan Rainville 2019-06-13 13:37:11 -04:00
parent 8c16541019
commit 332229ff9d
3 changed files with 19 additions and 13 deletions

View File

@ -26,7 +26,7 @@ config({
accounts = theAccounts;
});
contract("AnotherStorage", function() {
contract("AnotherStorage", function(accountsAgain) {
const defaultAccount = accounts[0];
this.timeout(0);
@ -34,6 +34,10 @@ contract("AnotherStorage", function() {
assert.strictEqual(defaultAccount, accounts[0]);
});
it("should have the accounts in the describe callback too", function () {
assert.deepStrictEqual(accountsAgain, accounts);
});
it("should have account with balance", async function() {
let balance = await web3.eth.getBalance(accounts[0]);
assert.ok(parseInt(balance, 10) > 4900000000000000000);

View File

@ -225,14 +225,10 @@ class TestRunner {
if (global.embark.needConfig) {
global.config({});
}
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.embark.onReady((_err, accounts) => {
self.ogMochaDescribe(describeName, callback.bind(mocha, accounts));
global.run(); // This tells mocha that it can run the test (used in conjunction with `delay()`
});
});
}
mocha.suite.on('pre-require', function() {

View File

@ -26,6 +26,7 @@ class Test {
this.accounts = [];
this.embarkjs = {};
this.dappPath = options.dappPath;
this.accounts = [];
this.events.setCommandHandler("blockchain:provider:contract:accounts:get", cb => {
this.events.request("blockchain:getAccounts", cb);
@ -112,10 +113,14 @@ class Test {
onReady(callback) {
const self = this;
if (this.ready) {
return callback();
return setImmediate(() => {
callback(null, this.accounts);
});
}
if (this.error) {
return callback(this.error);
return setImmediate(() => {
callback(this.error);
});
}
let errorCallback, readyCallback;
@ -125,9 +130,9 @@ class Test {
callback(err);
};
readyCallback = () => {
readyCallback = (accounts) => {
self.events.removeListener('tests:deployError', errorCallback);
callback();
callback(null, accounts);
};
this.events.once('tests:ready', readyCallback);
@ -250,8 +255,9 @@ 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.accounts = accounts;
callback(null, accounts);
self.events.emit('tests:ready');
self.events.emit('tests:ready', accounts);
});
}