use node option for tests

This commit is contained in:
Jonathan Rainville 2018-08-22 16:46:39 -04:00
parent b4e118c85b
commit 3f561f5257
4 changed files with 22 additions and 5 deletions

View File

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

View File

@ -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);

View File

@ -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 = {

View File

@ -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,