mirror of https://github.com/embarklabs/embark.git
Merge pull request #736 from embark-framework/features/test-node-option
Add --node option for tests
This commit is contained in:
commit
5fe86e35d1
|
@ -207,13 +207,14 @@ class Cmd {
|
|||
test() {
|
||||
program
|
||||
.command('test [file]')
|
||||
.option('-n , --node [node]', __('Node to connect to (default: vm)'))
|
||||
.option('-d , --gasDetails', __('When set, will print the gas cost for each contract deploy'))
|
||||
.option('--locale [locale]', __('language to use (default: en)'))
|
||||
.option('--loglevel [loglevel]', __('level of logging to display') + ' ["error", "warn", "info", "debug", "trace"]', /^(error|warn|info|debug|trace)$/i, 'warn')
|
||||
.description(__('run tests'))
|
||||
.action(function (file, options) {
|
||||
i18n.setOrDetectLocale(options.locale);
|
||||
embark.runTests({file, loglevel: options.loglevel, gasDetails: options.gasDetails});
|
||||
embark.runTests({file, loglevel: options.loglevel, gasDetails: options.gasDetails, node: options.node});
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -212,7 +212,8 @@ class Engine {
|
|||
web3Service(options) {
|
||||
this.registerModule('blockchain_process', {
|
||||
locale: this.locale,
|
||||
isDev: this.isDev
|
||||
isDev: this.isDev,
|
||||
ipc: this.ipc
|
||||
});
|
||||
|
||||
this.registerModule('blockchain_connector', {
|
||||
|
|
|
@ -13,6 +13,7 @@ class BlockchainModule {
|
|||
this.embark = embark;
|
||||
this.locale = options.locale;
|
||||
this.isDev = options.isDev;
|
||||
this.ipc = options.ipc;
|
||||
|
||||
this.registerBlockchainProcess();
|
||||
}
|
||||
|
@ -25,6 +26,11 @@ class BlockchainModule {
|
|||
self.startBlockchainNode(cb);
|
||||
});
|
||||
});
|
||||
|
||||
if (!this.ipc.isServer()) return;
|
||||
self.ipc.on('blockchain:node', (_message, cb) => {
|
||||
cb(null, utils.buildUrlFromConfig(self.contractsConfig.deployment));
|
||||
});
|
||||
}
|
||||
|
||||
assertNodeConnection(noLogs, cb) {
|
||||
|
@ -47,7 +53,7 @@ class BlockchainModule {
|
|||
if (!self.contractsConfig || !self.contractsConfig.deployment || !self.contractsConfig.deployment.host) {
|
||||
return next();
|
||||
}
|
||||
const {host, port, type, protocol} = self.contractsConfig.deployment;
|
||||
const {host, port, type, protocol} = self.contractsConfig.deployment;
|
||||
utils.pingEndpoint(host, port, type, protocol, self.blockchainConfig.wsOrigins.split(',')[0], next);
|
||||
}
|
||||
], function (err) {
|
||||
|
|
|
@ -21,6 +21,10 @@ class SolcW {
|
|||
return self.load_compiler_internally(done);
|
||||
}
|
||||
|
||||
if (self.ipc.connected) {
|
||||
self.compilerLoaded = true;
|
||||
return done();
|
||||
}
|
||||
self.ipc.connect((err) => {
|
||||
if (err) {
|
||||
return self.load_compiler_internally(done);
|
||||
|
|
|
@ -136,7 +136,7 @@ class Pipeline {
|
|||
|
||||
], function (err, contentFile) {
|
||||
if (err) {
|
||||
self.logger.error(err);
|
||||
self.logger.error(err.message || err);
|
||||
return fileCb(err);
|
||||
}
|
||||
|
||||
|
|
|
@ -61,7 +61,7 @@ module.exports = {
|
|||
},
|
||||
function setupGlobalNamespace(files, next) {
|
||||
// TODO put default config
|
||||
const test = new Test({loglevel});
|
||||
const test = new Test({loglevel, node: options.node});
|
||||
global.embark = test;
|
||||
global.assert = assert;
|
||||
global.config = test.config.bind(test);
|
||||
|
|
|
@ -58,10 +58,15 @@ class Test {
|
|||
});
|
||||
}
|
||||
|
||||
if (this.simOptions.host) {
|
||||
let {host, port, type, protocol, accounts} = this.simOptions;
|
||||
if (this.simOptions.host || this.options.node) {
|
||||
let options = this.simOptions;
|
||||
if (this.options.node) {
|
||||
options = utils.deconstructUrl(this.options.node);
|
||||
}
|
||||
|
||||
let {host, port, type, protocol, accounts} = options;
|
||||
if (!protocol) {
|
||||
protocol = (this.simOptions.type === "rpc") ? 'http' : 'ws';
|
||||
protocol = (options.type === "rpc") ? 'http' : 'ws';
|
||||
}
|
||||
const endpoint = `${protocol}://${host}:${port}`;
|
||||
const providerOptions = {
|
||||
|
@ -134,6 +139,22 @@ class Test {
|
|||
this.initDeployServices();
|
||||
this.engine.startService("codeGenerator");
|
||||
|
||||
if (this.options.node === 'embark') {
|
||||
return this.engine.ipc.connect((err) => {
|
||||
if (err) {
|
||||
this.engine.logger.error(err.message || err);
|
||||
this.engine.logger.error("Could not connect to Embark's IPC. Is embark running?");
|
||||
process.exit(1);
|
||||
}
|
||||
this.engine.ipc.request('blockchain:node', {}, (err, node) => {
|
||||
if (err) {
|
||||
return this.engine.logger.error(err.message || err);
|
||||
}
|
||||
this.options.node = node;
|
||||
callback();
|
||||
});
|
||||
});
|
||||
}
|
||||
callback();
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,6 @@ class TestLogger {
|
|||
if (!(this.shouldLog('error'))) {
|
||||
return;
|
||||
}
|
||||
console.error(txt);
|
||||
this.logFunction(txt.red);
|
||||
}
|
||||
|
||||
|
|
|
@ -340,13 +340,18 @@ function normalizeInput(input) {
|
|||
* The URL host, required.
|
||||
* @param {string} port
|
||||
* The URL port, default to empty string.
|
||||
* @param {string} [type]
|
||||
* Type of connection
|
||||
* @returns {string} the constructued URL, with defaults
|
||||
*/
|
||||
function buildUrl(protocol, host, port) {
|
||||
function buildUrl(protocol, host, port, type) {
|
||||
if (!host) throw new Error('utils.buildUrl: parameter \'host\' is required');
|
||||
if (port) port = ':' + port;
|
||||
else port = '';
|
||||
return `${protocol || 'http'}://${host}${port}`;
|
||||
if (!protocol) {
|
||||
protocol = type === 'ws' ? 'ws' : 'http';
|
||||
}
|
||||
return `${protocol}://${host}${port}`;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -361,7 +366,17 @@ function buildUrl(protocol, host, port) {
|
|||
function buildUrlFromConfig(configObj) {
|
||||
if (!configObj) throw new Error('[utils.buildUrlFromConfig]: config object must cannot be null');
|
||||
if (!configObj.host) throw new Error('[utils.buildUrlFromConfig]: object must contain a \'host\' property');
|
||||
return this.buildUrl(configObj.protocol, canonicalHost(configObj.host), configObj.port);
|
||||
return this.buildUrl(configObj.protocol, canonicalHost(configObj.host), configObj.port, configObj.type);
|
||||
}
|
||||
|
||||
function deconstructUrl(endpoint) {
|
||||
const matches = endpoint.match(/(ws|https?):\/\/([a-zA-Z0-9_.-]*):?([0-9]*)?/);
|
||||
return {
|
||||
protocol: matches[1],
|
||||
host: matches[2],
|
||||
port: matches[3],
|
||||
type: matches[1] === 'ws' ? 'ws' : 'rpc'
|
||||
};
|
||||
}
|
||||
|
||||
function getWeiBalanceFromString(balanceString, web3){
|
||||
|
@ -482,6 +497,7 @@ module.exports = {
|
|||
normalizeInput,
|
||||
buildUrl,
|
||||
buildUrlFromConfig,
|
||||
deconstructUrl,
|
||||
getWeiBalanceFromString,
|
||||
getHexBalanceFromString,
|
||||
compact,
|
||||
|
|
Loading…
Reference in New Issue