diff --git a/lib/modules/tests/index.js b/lib/modules/tests/index.js index dae65b8e..d226c250 100644 --- a/lib/modules/tests/index.js +++ b/lib/modules/tests/index.js @@ -120,11 +120,12 @@ class TestRunner { } runJSTests(files, options, cb) { + const self = this; const loglevel = options.loglevel || 'warn'; async.waterfall([ function setupGlobalNamespace(next) { // TODO put default config - const test = new Test({loglevel, node: options.node}); + const test = new Test({loglevel, node: options.node, events: self.events}); global.embark = test; global.assert = assert; global.config = test.config.bind(test); @@ -143,15 +144,12 @@ class TestRunner { const Module = require('module'); const originalRequire = require('module').prototype.require; Module.prototype.require = function (requireName) { - if (requireName.startsWith('Embark')) { + if (requireName.startsWith('Embark/contracts')) { return test.require(...arguments); } return originalRequire.apply(this, arguments); }; - // TODO: this global here might not be necessary at all - global.web3 = global.embark.web3; - global.contract = function (describeName, callback) { return Mocha.describe(describeName, callback); }; @@ -165,7 +163,7 @@ class TestRunner { return (cb) => { const mocha = new Mocha(); mocha.reporter(EmbarkSpec, { - events: global.embark.engine.events, + events: self.events, gasDetails: options.gasDetails, gasLimit: 6000000 }); diff --git a/lib/modules/tests/test.js b/lib/modules/tests/test.js index 36a081f2..753738d6 100644 --- a/lib/modules/tests/test.js +++ b/lib/modules/tests/test.js @@ -2,7 +2,6 @@ const async = require('async'); const Engine = require('../../core/engine.js'); const TestLogger = require('./test_logger.js'); const Web3 = require('web3'); -const Events = require('../../core/events'); const AccountParser = require('../../utils/accountParser'); // TODO: breaks module isolation; tests need to be refactored to use the engine and avoid this const Provider = require('../blockchain_connector/provider.js'); @@ -32,7 +31,7 @@ class Test { constructor(options) { this.options = options || {}; this.simOptions = {}; - this.events = new Events(); + this.events = options.events; this.ready = true; this.firstRunConfig = true; this.error = false; @@ -225,17 +224,17 @@ class Test { let errorCallback, readyCallback; errorCallback = (err) => { - self.events.removeListener('ready', readyCallback); + self.events.removeListener('tests:ready', readyCallback); callback(err); }; readyCallback = () => { - self.events.removeListener('deployError', errorCallback); + self.events.removeListener('tests:deployError', errorCallback); callback(); }; - this.events.once('ready', readyCallback); - this.events.once('deployError', errorCallback); + this.events.once('tests:ready', readyCallback); + this.events.once('tests:deployError', errorCallback); } checkDeploymentOptions(options, callback) { @@ -312,13 +311,13 @@ class Test { function deploy(next) { self._deploy(options, (err, accounts) => { if (err) { - self.events.emit('deployError', err); + self.events.emit('tests:deployError', err); self.error = err; return next(err); } self.ready = true; self.error = false; - self.events.emit('ready'); + self.events.emit('tests:ready'); next(null, accounts); }); }