diff --git a/cmd/cmd.js b/cmd/cmd.js index 97a3ff66c..53ba06f1b 100644 --- a/cmd/cmd.js +++ b/cmd/cmd.js @@ -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}); }); } diff --git a/lib/tests/run_tests.js b/lib/tests/run_tests.js index a4e9d258a..97af4f24f 100644 --- a/lib/tests/run_tests.js +++ b/lib/tests/run_tests.js @@ -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); diff --git a/lib/tests/test.js b/lib/tests/test.js index 64cd218d9..e22db40bf 100644 --- a/lib/tests/test.js +++ b/lib/tests/test.js @@ -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 = { diff --git a/lib/utils/utils.js b/lib/utils/utils.js index 92facc19d..c1ccbfca6 100644 --- a/lib/utils/utils.js +++ b/lib/utils/utils.js @@ -364,6 +364,16 @@ function buildUrlFromConfig(configObj) { return this.buildUrl(configObj.protocol, canonicalHost(configObj.host), configObj.port); } +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){ if(!web3){ throw new Error(__('[utils.getWeiBalanceFromString]: Missing parameter \'web3\'')); @@ -482,6 +492,7 @@ module.exports = { normalizeInput, buildUrl, buildUrlFromConfig, + deconstructUrl, getWeiBalanceFromString, getHexBalanceFromString, compact,