mirror of https://github.com/embarklabs/embark.git
Merge pull request #246 from toadkicker/speedup_test_class
Speedup test class
This commit is contained in:
commit
7aad925ea5
101
lib/core/test.js
101
lib/core/test.js
|
@ -1,14 +1,6 @@
|
||||||
var async = require('async');
|
|
||||||
var Web3 = require('web3');
|
|
||||||
|
|
||||||
var Engine = require('./engine.js');
|
|
||||||
var RunCode = require('./runCode.js');
|
|
||||||
var TestLogger = require('./test_logger.js');
|
|
||||||
|
|
||||||
var getSimulator = function() {
|
var getSimulator = function() {
|
||||||
try {
|
try {
|
||||||
var sim = require('ethereumjs-testrpc');
|
return require('ethereumjs-testrpc');
|
||||||
return sim;
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e.code === 'MODULE_NOT_FOUND') {
|
if (e.code === 'MODULE_NOT_FOUND') {
|
||||||
console.log('Simulator not found; Please install it with "npm install ethereumjs-testrpc --save"');
|
console.log('Simulator not found; Please install it with "npm install ethereumjs-testrpc --save"');
|
||||||
|
@ -25,30 +17,44 @@ var getSimulator = function() {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var Test = function(options) {
|
var Test;
|
||||||
this.options = options || {};
|
Test = (function (options) {
|
||||||
var simOptions = this.options.simulatorOptions || {};
|
var async = require('async');
|
||||||
|
var opts = options === undefined ? {} : options;
|
||||||
|
opts.logLevel = opts.hasOwnProperty('logLevel') ? opts.logLevel : 'debug';
|
||||||
|
opts.simulatorOptions = opts.hasOwnProperty('simulatorOptions') ? opts.simulatorOptions : {};
|
||||||
|
var sim = getSimulator();
|
||||||
|
|
||||||
this.engine = new Engine({
|
function newWebThree() {
|
||||||
env: this.options.env || 'test',
|
try {
|
||||||
// TODO: confi will need to detect if this is a obj
|
var Web3 = require('web3');
|
||||||
embarkConfig: this.options.embarkConfig || 'embark.json',
|
var web3 = new Web3();
|
||||||
interceptLogs: false
|
web3.setProvider(sim.provider(opts.simulatorOptions));
|
||||||
});
|
return web3;
|
||||||
|
} catch (e) {
|
||||||
|
throw new Error(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.engine.init({
|
function deployAll(contractsConfig, cb) {
|
||||||
logger: new TestLogger({logLevel: this.options.logLevel || 'debug'})
|
var RunCode = require('./runCode.js');
|
||||||
});
|
var self = this;
|
||||||
|
|
||||||
this.sim = getSimulator();
|
function newEngine () {
|
||||||
this.web3 = new Web3();
|
var Engine = require('./engine.js');
|
||||||
this.web3.setProvider(this.sim.provider(simOptions));
|
return new Engine({
|
||||||
};
|
env: opts.env || 'test',
|
||||||
|
// TODO: confi will need to detect if this is a obj
|
||||||
|
embarkConfig: opts.embarkConfig || 'embark.json',
|
||||||
|
interceptLogs: false
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
Test.prototype.deployAll = function(contractsConfig, cb) {
|
self.web3 = newWebThree();
|
||||||
var self = this;
|
self.engine = newEngine();
|
||||||
|
self.engine.init();
|
||||||
|
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function getConfig(callback) {
|
function getConfig(callback) {
|
||||||
self.engine.config.contractsConfig = {contracts: contractsConfig};
|
self.engine.config.contractsConfig = {contracts: contractsConfig};
|
||||||
callback();
|
callback();
|
||||||
|
@ -63,32 +69,39 @@ Test.prototype.deployAll = function(contractsConfig, cb) {
|
||||||
callback();
|
callback();
|
||||||
},
|
},
|
||||||
function deploy(callback) {
|
function deploy(callback) {
|
||||||
self.engine.events.on('abi-contracts-vanila', function(vanillaABI) {
|
self.engine.events.on('abi-contracts-vanila', function (vanillaABI) {
|
||||||
callback(null, vanillaABI);
|
callback(null, vanillaABI);
|
||||||
});
|
});
|
||||||
self.engine.deployManager.deployContracts(function(err, result) {
|
self.engine.deployManager.deployContracts(function (err, result) {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
callback(err);
|
callback(err);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
], function(err, result) {
|
], function (err, result) {
|
||||||
if (err) {
|
|
||||||
console.log("got error");
|
|
||||||
process.exit();
|
|
||||||
}
|
|
||||||
// this should be part of the waterfall and not just something done at the
|
|
||||||
// end
|
|
||||||
self.web3.eth.getAccounts(function(err, accounts) {
|
|
||||||
if (err) {
|
if (err) {
|
||||||
throw new Error(err);
|
console.log("got error");
|
||||||
|
process.exit();
|
||||||
}
|
}
|
||||||
self.web3.eth.defaultAccount = accounts[0];
|
// this should be part of the waterfall and not just something done at the
|
||||||
RunCode.doEval(result, self.web3); // jshint ignore:line
|
// end
|
||||||
cb();
|
self.web3.eth.getAccounts(function (err, accounts) {
|
||||||
|
if (err) {
|
||||||
|
throw new Error(err);
|
||||||
|
}
|
||||||
|
self.web3.eth.defaultAccount = accounts[0];
|
||||||
|
RunCode.doEval(result, self.web3); // jshint ignore:line
|
||||||
|
cb();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
};
|
|
||||||
|
|
||||||
|
return {
|
||||||
|
deployAll: deployAll,
|
||||||
|
sim: sim
|
||||||
|
};
|
||||||
|
}());
|
||||||
|
|
||||||
module.exports = Test;
|
module.exports = Test;
|
||||||
|
|
|
@ -1,13 +1,11 @@
|
||||||
/*jshint esversion: 6 */
|
/*jshint esversion: 6 */
|
||||||
var async = require('async');
|
var async = require('async');
|
||||||
//require("./utils/debug_util.js")(__filename, async);
|
// require("./utils/debug_util.js")(__filename, async);
|
||||||
|
|
||||||
var colors = require('colors');
|
var colors = require('colors');
|
||||||
|
|
||||||
var Engine = require('./core/engine.js');
|
var Engine = require('./core/engine.js');
|
||||||
|
|
||||||
var Test = require('./core/test.js');
|
|
||||||
|
|
||||||
var IPFS = require('./upload/ipfs.js');
|
var IPFS = require('./upload/ipfs.js');
|
||||||
var Swarm = require('./upload/swarm.js');
|
var Swarm = require('./upload/swarm.js');
|
||||||
|
|
||||||
|
@ -167,6 +165,7 @@ var Embark = (function () {
|
||||||
}
|
}
|
||||||
|
|
||||||
function initTests (options) {
|
function initTests (options) {
|
||||||
|
var Test = require('./core/test.js');
|
||||||
return new Test(options);
|
return new Test(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
13
test/cmd.js
13
test/cmd.js
|
@ -2,8 +2,8 @@ var Embark = require('../lib/index');
|
||||||
var Cmd = require('../lib/cmd');
|
var Cmd = require('../lib/cmd');
|
||||||
|
|
||||||
describe('embark.Cmd', function () {
|
describe('embark.Cmd', function () {
|
||||||
|
this.timeout(0);
|
||||||
var cmd = new Cmd(Embark);
|
var cmd = new Cmd(Embark);
|
||||||
|
|
||||||
describe('#new', function () {
|
describe('#new', function () {
|
||||||
it('it should not create an app without a name', function (done) {
|
it('it should not create an app without a name', function (done) {
|
||||||
cmd.newApp(undefined, function (output) {
|
cmd.newApp(undefined, function (output) {
|
||||||
|
@ -27,4 +27,15 @@ describe('embark.Cmd', function () {
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// describe("#help", function () {
|
||||||
|
// it('it should spit out helpful text if no arguments are supplied', function (done) {
|
||||||
|
// cmd.process([], function (output) {
|
||||||
|
// var lines = output.split('\n');
|
||||||
|
// assert.equal(lines[0], '\n');
|
||||||
|
// assert.equal(lines[1], 'Usage:');
|
||||||
|
// done();
|
||||||
|
// });
|
||||||
|
// })
|
||||||
|
// })
|
||||||
});
|
});
|
|
@ -10,7 +10,7 @@
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"homepage": "",
|
"homepage": "",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"embark": "../",
|
"embark": "file:../",
|
||||||
"mocha": "^2.2.5"
|
"mocha": "^2.2.5"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
var assert = require('assert');
|
var assert = require('assert');
|
||||||
var Embark = require('embark');
|
var EmbarkSpec = require('embark/lib/core/test.js');
|
||||||
var EmbarkSpec = Embark.initTests();
|
|
||||||
var web3 = EmbarkSpec.web3;
|
|
||||||
|
|
||||||
describe("AnotherStorage", function() {
|
describe("AnotherStorage", function() {
|
||||||
before(function(done) {
|
before(function(done) {
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
var assert = require('assert');
|
var assert = require('assert');
|
||||||
var Embark = require('embark');
|
var EmbarkSpec = require('embark/lib/core/test.js');
|
||||||
var EmbarkSpec = Embark.initTests();
|
|
||||||
var web3 = EmbarkSpec.web3;
|
|
||||||
|
|
||||||
describe("SimpleStorage", function() {
|
describe("SimpleStorage", function() {
|
||||||
before(function(done) {
|
before(function(done) {
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
var assert = require('assert');
|
var assert = require('assert');
|
||||||
var Embark = require('embark');
|
var EmbarkSpec = require('embark/lib/core/test.js');
|
||||||
var EmbarkSpec = Embark.initTests();
|
|
||||||
var web3 = EmbarkSpec.web3;
|
|
||||||
|
|
||||||
describe("Token", function() {
|
describe("Token", function() {
|
||||||
before(function(done) {
|
before(function(done) {
|
||||||
|
|
Loading…
Reference in New Issue