Merge pull request #246 from toadkicker/speedup_test_class

Speedup test class
This commit is contained in:
Iuri Matias 2017-03-12 18:51:56 -04:00 committed by GitHub
commit 7aad925ea5
7 changed files with 75 additions and 58 deletions

View File

@ -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() {
try {
var sim = require('ethereumjs-testrpc');
return sim;
return require('ethereumjs-testrpc');
} catch (e) {
if (e.code === 'MODULE_NOT_FOUND') {
console.log('Simulator not found; Please install it with "npm install ethereumjs-testrpc --save"');
@ -25,28 +17,42 @@ var getSimulator = function() {
}
};
var Test = function(options) {
this.options = options || {};
var simOptions = this.options.simulatorOptions || {};
var Test;
Test = (function (options) {
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({
env: this.options.env || 'test',
function newWebThree() {
try {
var Web3 = require('web3');
var web3 = new Web3();
web3.setProvider(sim.provider(opts.simulatorOptions));
return web3;
} catch (e) {
throw new Error(e);
}
}
function deployAll(contractsConfig, cb) {
var RunCode = require('./runCode.js');
var self = this;
function newEngine () {
var Engine = require('./engine.js');
return new Engine({
env: opts.env || 'test',
// TODO: confi will need to detect if this is a obj
embarkConfig: this.options.embarkConfig || 'embark.json',
embarkConfig: opts.embarkConfig || 'embark.json',
interceptLogs: false
});
}
this.engine.init({
logger: new TestLogger({logLevel: this.options.logLevel || 'debug'})
});
this.sim = getSimulator();
this.web3 = new Web3();
this.web3.setProvider(this.sim.provider(simOptions));
};
Test.prototype.deployAll = function(contractsConfig, cb) {
var self = this;
self.web3 = newWebThree();
self.engine = newEngine();
self.engine.init();
async.waterfall([
function getConfig(callback) {
@ -89,6 +95,13 @@ Test.prototype.deployAll = function(contractsConfig, cb) {
cb();
});
});
}
return {
deployAll: deployAll,
sim: sim
};
}());
module.exports = Test;

View File

@ -6,8 +6,6 @@ var colors = require('colors');
var Engine = require('./core/engine.js');
var Test = require('./core/test.js');
var IPFS = require('./upload/ipfs.js');
var Swarm = require('./upload/swarm.js');
@ -167,6 +165,7 @@ var Embark = (function () {
}
function initTests (options) {
var Test = require('./core/test.js');
return new Test(options);
}

View File

@ -2,8 +2,8 @@ var Embark = require('../lib/index');
var Cmd = require('../lib/cmd');
describe('embark.Cmd', function () {
this.timeout(0);
var cmd = new Cmd(Embark);
describe('#new', function () {
it('it should not create an app without a name', function (done) {
cmd.newApp(undefined, function (output) {
@ -27,4 +27,15 @@ describe('embark.Cmd', function () {
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();
// });
// })
// })
});

View File

@ -10,7 +10,7 @@
"license": "ISC",
"homepage": "",
"devDependencies": {
"embark": "../",
"embark": "file:../",
"mocha": "^2.2.5"
},
"dependencies": {

View File

@ -1,7 +1,5 @@
var assert = require('assert');
var Embark = require('embark');
var EmbarkSpec = Embark.initTests();
var web3 = EmbarkSpec.web3;
var EmbarkSpec = require('embark/lib/core/test.js');
describe("AnotherStorage", function() {
before(function(done) {

View File

@ -1,7 +1,5 @@
var assert = require('assert');
var Embark = require('embark');
var EmbarkSpec = Embark.initTests();
var web3 = EmbarkSpec.web3;
var EmbarkSpec = require('embark/lib/core/test.js');
describe("SimpleStorage", function() {
before(function(done) {

View File

@ -1,7 +1,5 @@
var assert = require('assert');
var Embark = require('embark');
var EmbarkSpec = Embark.initTests();
var web3 = EmbarkSpec.web3;
var EmbarkSpec = require('embark/lib/core/test.js');
describe("Token", function() {
before(function(done) {