speed up test class - unstable

This commit is contained in:
Todd Baur 2017-03-12 12:23:30 +09:00
parent 8cc139e54c
commit 383b3c31a5
6 changed files with 89 additions and 63 deletions

View File

@ -1,14 +1,9 @@
var async = require('async'); var async = require('async');
var Web3 = require('web3'); 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,32 +20,58 @@ var getSimulator = function() {
} }
}; };
var Test = function(options) { var Test = function(options) {
this.options = options || {}; var opts = options === undefined ? {} : options;
var simOptions = this.options.simulatorOptions || {}; opts.logLevel = opts.hasOwnProperty('logLevel') ? opts.logLevel : 'debug';
opts.simulatorOptions = opts.hasOwnProperty('simulatorOptions') ? opts.simulatorOptions : {};
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(getSimulator());
}); } catch (e) {
if (e.code === 'MODULE_NOT_FOUND') {
console.log('Simulator not found; Please install it with "npm install ethereumjs-testrpc --save"');
console.log('IMPORTANT: if you using a NodeJS version older than 6.9.1 then you need to install an older version of testrpc "npm install ethereumjs-testrpc@2.0 --save"');
console.log('For more information see https://github.com/ethereumjs/testrpc');
// TODO: should throw exception instead
return process.exit();
}
console.log("==============");
console.log("Tried to load testrpc but an error occurred. This is a problem with testrpc");
console.log('IMPORTANT: if you using a NodeJS version older than 6.9.1 then you need to install an older version of testrpc "npm install ethereumjs-testrpc@2.0 --save". Alternatively install node 6.9.1 and the testrpc 3.0');
console.log("==============");
throw new Error(e);
}
}
this.engine.init({ function deployAll (contractsConfig, cb) {
logger: new TestLogger({logLevel: this.options.logLevel || 'debug'}) var RunCode = require('./runCode.js');
});
this.sim = getSimulator();
this.web3 = new Web3();
this.web3.setProvider(this.sim.provider(simOptions));
};
Test.prototype.deployAll = function(contractsConfig, cb) {
var self = this; 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: opts.embarkConfig || 'embark.json',
interceptLogs: false
}).init();
}
function newLogger() {
var TestLogger = require('./test_logger.js');
new TestLogger({logLevel: opts.logLevel})
}
this.engine = newEngine();
this.web3 = newWebThree();
async.waterfall([ async.waterfall([
function getConfig(callback) { function getConfig(callback) {
self.engine.config.contractsConfig = {contracts: contractsConfig}; contractsConfig = { contracts: contractsConfig };
callback(); callback();
}, },
function startServices(callback) { function startServices(callback) {
@ -89,6 +110,12 @@ Test.prototype.deployAll = function(contractsConfig, cb) {
cb(); cb();
}); });
}); });
}; }
return {
deployAll: deployAll
}
}();
module.exports = Test; module.exports = Test;

View File

@ -1,19 +1,17 @@
/*jshint esversion: 6 */ /*jshint esversion: 6 */
var async = require('async'); var async = require('async');
//require("./utils/debug_util.js")(__filename, async); //require("./core/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');
var version = require('../package.json').version; var version = require('../package.json').version;
var Embark = function () { var Embark = (function () {
function initConfig (env, options) { function initConfig (env, options) {
var Events = require('./core/events.js'); var Events = require('./core/events.js');
var Logger = require('./core/logger.js'); var Logger = require('./core/logger.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);
} }
@ -196,19 +195,7 @@ var Embark = function () {
upload: upload upload: upload
}; };
}(); })();
Embark.initTests = function() {
console.error("=============================".green);
console.error("deprecated: Starting with Embark 2.5.0 the Embark object needs to be initialized".red);
console.log("replace:");
console.log("var Embark = require('embark');");
console.log("with:");
console.log("var Embark = require('embark')();");
console.error("=============================".green);
var embark = Embark();
return embark.initTests();
};
module.exports = Embark; module.exports = Embark;

View File

@ -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();
// });
// })
// })
}); });

View File

@ -1,6 +1,7 @@
var assert = require('assert'); var assert = require('assert');
var Embark = require('embark')(); var Embark = require('embark');
var EmbarkSpec = Embark.initTests(); //TODO: this path is temporary to handle the scope of Embark within an app
var EmbarkSpec = require('../node_modules/embark/lib/core/test.js');
var web3 = EmbarkSpec.web3; var web3 = EmbarkSpec.web3;
describe("AnotherStorage", function() { describe("AnotherStorage", function() {

View File

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

View File

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