make running config() without callback work
This commit is contained in:
parent
198760609c
commit
521165f710
|
@ -21,7 +21,7 @@ function getFilesFromDir(filePath, cb) {
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
run: function(filePath) {
|
run: function (filePath) {
|
||||||
const mocha = new Mocha();
|
const mocha = new Mocha();
|
||||||
if (!filePath) {
|
if (!filePath) {
|
||||||
filePath = 'test/';
|
filePath = 'test/';
|
||||||
|
@ -53,7 +53,12 @@ module.exports = {
|
||||||
// TODO: this global here might not be necessary at all
|
// TODO: this global here might not be necessary at all
|
||||||
global.web3 = global.embark.web3;
|
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);
|
return Mocha.describe(describeName, callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -65,7 +70,7 @@ module.exports = {
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
// Run the tests.
|
// Run the tests.
|
||||||
mocha.run(function(failures) {
|
mocha.run(function (failures) {
|
||||||
// Clean contracts folder for next test run
|
// Clean contracts folder for next test run
|
||||||
fs.remove('.embark/contracts', (_err) => {
|
fs.remove('.embark/contracts', (_err) => {
|
||||||
process.on('exit', function () {
|
process.on('exit', function () {
|
||||||
|
|
|
@ -4,6 +4,7 @@ const TestLogger = require('./test_logger.js');
|
||||||
const Web3 = require('web3');
|
const Web3 = require('web3');
|
||||||
const utils = require('../utils/utils');
|
const utils = require('../utils/utils');
|
||||||
const constants = require('../constants');
|
const constants = require('../constants');
|
||||||
|
const Events = require('../core/events');
|
||||||
|
|
||||||
function getSimulator() {
|
function getSimulator() {
|
||||||
try {
|
try {
|
||||||
|
@ -28,6 +29,8 @@ class Test {
|
||||||
this.options = options || {};
|
this.options = options || {};
|
||||||
this.simOptions = this.options.simulatorOptions || {};
|
this.simOptions = this.options.simulatorOptions || {};
|
||||||
this.contracts = {};
|
this.contracts = {};
|
||||||
|
this.events = new Events();
|
||||||
|
this.ready = true;
|
||||||
|
|
||||||
this.web3 = new Web3();
|
this.web3 = new Web3();
|
||||||
if (this.simOptions.node) {
|
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) {
|
config(options, callback) {
|
||||||
|
if (!callback) {
|
||||||
|
callback = function () {};
|
||||||
|
}
|
||||||
this.options = utils.recursiveMerge(this.options, options);
|
this.options = utils.recursiveMerge(this.options, options);
|
||||||
this.simOptions = this.options.simulatorOptions || {};
|
this.simOptions = this.options.simulatorOptions || {};
|
||||||
|
this.ready = false;
|
||||||
|
|
||||||
this._deploy(options, (err, accounts) => {
|
this._deploy(options, (err, accounts) => {
|
||||||
|
this.ready = true;
|
||||||
|
this.events.emit('ready');
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
return callback(err);
|
return callback(err);
|
||||||
|
|
|
@ -1,33 +1,26 @@
|
||||||
/*global contract, before, it, embark, web3*/
|
/*global contract, config, it, embark*/
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
const SimpleStorage = embark.require('contracts/SimpleStorage');
|
const SimpleStorage = embark.require('contracts/SimpleStorage');
|
||||||
|
|
||||||
|
config({
|
||||||
|
contracts: {
|
||||||
|
"SimpleStorage": {
|
||||||
|
args: [100]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
contract("SimpleStorage", function () {
|
contract("SimpleStorage", function () {
|
||||||
this.timeout(0);
|
this.timeout(0);
|
||||||
|
|
||||||
before(function (done) {
|
|
||||||
const contractsConfig = {
|
|
||||||
contracts: {
|
|
||||||
"SimpleStorage": {
|
|
||||||
args: [100]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
embark.config(contractsConfig, () => {
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should set constructor value", async function () {
|
it("should set constructor value", async function () {
|
||||||
let result = await SimpleStorage.methods.storedData().call();
|
let result = await SimpleStorage.methods.storedData().call();
|
||||||
assert.strictEqual(parseInt(result, 10), 100);
|
assert.strictEqual(parseInt(result, 10), 100);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("set storage value", async function () {
|
it("set storage value", async function () {
|
||||||
// TODO Solve from
|
|
||||||
await SimpleStorage.methods.set(150).send();
|
await SimpleStorage.methods.set(150).send();
|
||||||
let result = await SimpleStorage.methods.get().call();
|
let result = await SimpleStorage.methods.get().call();
|
||||||
assert.strictEqual(parseInt(result, 10), 499650);
|
assert.strictEqual(parseInt(result, 10), 499650);
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue