make running config() without callback work

This commit is contained in:
Jonathan Rainville 2018-05-30 16:17:17 -04:00
parent 198760609c
commit 521165f710
3 changed files with 35 additions and 19 deletions

View File

@ -21,7 +21,7 @@ function getFilesFromDir(filePath, cb) {
}
module.exports = {
run: function(filePath) {
run: function (filePath) {
const mocha = new Mocha();
if (!filePath) {
filePath = 'test/';
@ -53,7 +53,12 @@ module.exports = {
// TODO: this global here might not be necessary at all
global.web3 = global.embark.web3;
global.contract = function(describeName, callback) {
mocha.suite.beforeAll('Wait for deploy', (done) => {
test.onReady(() => {
done();
});
});
global.contract = function (describeName, callback) {
return Mocha.describe(describeName, callback);
};
@ -65,7 +70,7 @@ module.exports = {
process.exit(1);
}
// Run the tests.
mocha.run(function(failures) {
mocha.run(function (failures) {
// Clean contracts folder for next test run
fs.remove('.embark/contracts', (_err) => {
process.on('exit', function () {

View File

@ -4,6 +4,7 @@ const TestLogger = require('./test_logger.js');
const Web3 = require('web3');
const utils = require('../utils/utils');
const constants = require('../constants');
const Events = require('../core/events');
function getSimulator() {
try {
@ -28,6 +29,8 @@ class Test {
this.options = options || {};
this.simOptions = this.options.simulatorOptions || {};
this.contracts = {};
this.events = new Events();
this.ready = true;
this.web3 = new Web3();
if (this.simOptions.node) {
@ -65,11 +68,26 @@ class Test {
});
}
onReady(callback) {
if (this.ready) {
return callback();
}
this.events.once('ready', () => {
callback();
});
}
config(options, callback) {
if (!callback) {
callback = function () {};
}
this.options = utils.recursiveMerge(this.options, options);
this.simOptions = this.options.simulatorOptions || {};
this.ready = false;
this._deploy(options, (err, accounts) => {
this.ready = true;
this.events.emit('ready');
if (err) {
console.error(err);
return callback(err);

View File

@ -1,33 +1,26 @@
/*global contract, before, it, embark, web3*/
/*global contract, config, it, embark*/
const assert = require('assert');
const SimpleStorage = embark.require('contracts/SimpleStorage');
config({
contracts: {
"SimpleStorage": {
args: [100]
}
}
});
contract("SimpleStorage", function () {
this.timeout(0);
before(function (done) {
const contractsConfig = {
contracts: {
"SimpleStorage": {
args: [100]
}
}
};
embark.config(contractsConfig, () => {
done();
});
});
it("should set constructor value", async function () {
let result = await SimpleStorage.methods.storedData().call();
assert.strictEqual(parseInt(result, 10), 100);
});
it("set storage value", async function () {
// TODO Solve from
await SimpleStorage.methods.set(150).send();
let result = await SimpleStorage.methods.get().call();
assert.strictEqual(parseInt(result, 10), 499650);
});
});