From eb22e6841cbdcf09fc886f84d4700d53be10a6b7 Mon Sep 17 00:00:00 2001 From: 0mkar <0mkar@protonmail.com> Date: Sat, 25 Aug 2018 01:40:56 +0530 Subject: [PATCH 1/6] fix import, inject remix_tests.sol, use signale for logging --- remix-tests/examples/simple_storage2_test.sol | 2 -- remix-tests/examples/simple_storage_test.sol | 2 -- remix-tests/package.json | 1 + remix-tests/src/compiler.js | 16 +++++++--- remix-tests/src/index.js | 30 +++++++++++++++++-- remix-tests/src/run.js | 4 ++- .../tests/examples_1/simple_storage_test.sol | 2 -- .../tests/examples_2/simple_storage_test.sol | 2 -- .../tests/examples_3/simple_string_test.sol | 1 - 9 files changed, 43 insertions(+), 17 deletions(-) diff --git a/remix-tests/examples/simple_storage2_test.sol b/remix-tests/examples/simple_storage2_test.sol index 0c199f9b03..814570aae7 100644 --- a/remix-tests/examples/simple_storage2_test.sol +++ b/remix-tests/examples/simple_storage2_test.sol @@ -1,5 +1,4 @@ pragma solidity ^0.4.7; -import "./tests.sol"; import "./simple_storage.sol"; contract MyTest2 { @@ -26,4 +25,3 @@ contract MyTest2 { } } - diff --git a/remix-tests/examples/simple_storage_test.sol b/remix-tests/examples/simple_storage_test.sol index ec780ae85d..09392087e3 100644 --- a/remix-tests/examples/simple_storage_test.sol +++ b/remix-tests/examples/simple_storage_test.sol @@ -1,5 +1,4 @@ pragma solidity ^0.4.7; -import "./tests.sol"; import "./simple_storage.sol"; contract MyTest { @@ -26,4 +25,3 @@ contract MyTest { } } - diff --git a/remix-tests/package.json b/remix-tests/package.json index 5036e7c6b1..52187f47f9 100644 --- a/remix-tests/package.json +++ b/remix-tests/package.json @@ -43,6 +43,7 @@ "commander": "^2.13.0", "remix-simulator": "0.0.3", "remix-solidity": "^0.2.5", + "signale": "^1.2.1", "solc": "^0.4.24", "standard": "^10.0.3", "web3": "1.0.0-beta.27" diff --git a/remix-tests/src/compiler.js b/remix-tests/src/compiler.js index e7de72c36f..2fc3e2e52d 100644 --- a/remix-tests/src/compiler.js +++ b/remix-tests/src/compiler.js @@ -1,7 +1,7 @@ let fs = require('fs') var async = require('async') var path = require('path') - +const signale = require('signale') let RemixCompiler = require('remix-solidity').Compiler // TODO: replace this with remix's own compiler code @@ -13,13 +13,21 @@ function compileFileOrFiles (filename, isDirectory, cb) { 'tests.sol': { content: require('../sol/tests.sol.js') }, 'remix_tests.sol': { content: require('../sol/tests.sol.js') } } + // signale.debug(sources) // TODO: for now assumes filepath dir contains all tests, later all this // should be replaced with remix's & browser solidity compiler code filepath = (isDirectory ? filename : path.dirname(filename)) fs.readdirSync(filepath).forEach(file => { - sources[file] = {content: fs.readFileSync(path.join(filepath, file)).toString()} + // only process .sol files + if (file.split('.').pop() === 'sol') { + let c = fs.readFileSync(path.join(filepath, file)).toString() + if (file.indexOf('_test.sol') > 0) { + c = c.replace(/(pragma solidity \^\d+\.\d+\.\d+;)/, '$1\nimport \'remix_tests.sol\';') + } + sources[file] = { content: c } + } }) async.waterfall([ @@ -39,7 +47,7 @@ function compileFileOrFiles (filename, isDirectory, cb) { ], function (err, result) { let errors = (result.errors || []).filter((e) => e.type === 'Error' || e.severity === 'error') if (errors.length > 0) { - console.dir(errors) + signale.fatal(errors) return cb(new Error('errors compiling')) } cb(err, result.contracts) @@ -70,7 +78,7 @@ function compileContractSources (sources, importFileCb, cb) { ], function (err, result) { let errors = (result.errors || []).filter((e) => e.type === 'Error' || e.severity === 'error') if (errors.length > 0) { - console.dir(errors) + signale.fatal(errors) return cb(new Error('errors compiling')) } cb(err, result.contracts) diff --git a/remix-tests/src/index.js b/remix-tests/src/index.js index f8019f1dfa..d5e86afc6c 100644 --- a/remix-tests/src/index.js +++ b/remix-tests/src/index.js @@ -1,6 +1,7 @@ const async = require('async') const path = require('path') const fs = require('fs') +const { Signale } = require('signale') require('colors') let Compiler = require('./compiler.js') @@ -11,11 +12,34 @@ const Web3 = require('web3') const Provider = require('remix-simulator').Provider var createWeb3Provider = function () { + signale.info('Creating providers') let web3 = new Web3() web3.setProvider(new Provider()) return web3 } +// signale configuration +const options = { + types: { + result: { + badge: '\t✓', + label: '', + color: 'greenBright' + }, + name: { + badge: '\n\t◼', + label: '', + color: 'white' + }, + error: { + badge: '\t✘', + label: '', + color: 'redBright' + } + } +} +const signale = new Signale(options) + var runTestSources = function (contractSources, testCallback, resultCallback, finalCallback, importFileCb) { async.waterfall([ function compile (next) { @@ -134,11 +158,11 @@ var runTestFiles = function (filepath, isDirectory, web3) { var testCallback = function (result) { if (result.type === 'contract') { - console.log('\n ' + result.value) + signale.name(result.value.white) } else if (result.type === 'testPass') { - console.log('\t✓ '.green.bold + result.value.grey) + signale.result(result.value) } else if (result.type === 'testFailure') { - console.log('\t✘ '.bold.red + result.value.red) + signale.result(result.value.red) errors.push(result) } } diff --git a/remix-tests/src/run.js b/remix-tests/src/run.js index 6eb4aa2655..6a3815f007 100644 --- a/remix-tests/src/run.js +++ b/remix-tests/src/run.js @@ -2,6 +2,7 @@ const commander = require('commander') const Web3 = require('web3') const RemixTests = require('./index.js') const fs = require('fs') +const signale = require('signale') const Provider = require('remix-simulator').Provider @@ -16,7 +17,8 @@ commander.action(function (filename) { }) if (!process.argv.slice(2).length) { - console.log('please specify filename') + signale.fatal('Please specify a filename') + process.exit() } commander.parse(process.argv) diff --git a/remix-tests/tests/examples_1/simple_storage_test.sol b/remix-tests/tests/examples_1/simple_storage_test.sol index 896970933f..6c4b35942f 100644 --- a/remix-tests/tests/examples_1/simple_storage_test.sol +++ b/remix-tests/tests/examples_1/simple_storage_test.sol @@ -1,5 +1,4 @@ pragma solidity ^0.4.7; -import "remix_tests.sol"; import "./simple_storage.sol"; contract MyTest { @@ -29,4 +28,3 @@ contract MyTest { } } - diff --git a/remix-tests/tests/examples_2/simple_storage_test.sol b/remix-tests/tests/examples_2/simple_storage_test.sol index 016b3c7f5d..b794095f5c 100644 --- a/remix-tests/tests/examples_2/simple_storage_test.sol +++ b/remix-tests/tests/examples_2/simple_storage_test.sol @@ -1,5 +1,4 @@ pragma solidity ^0.4.7; -import "./tests.sol"; import "./simple_storage.sol"; contract MyTest { @@ -25,4 +24,3 @@ contract MyTest { } } - diff --git a/remix-tests/tests/examples_3/simple_string_test.sol b/remix-tests/tests/examples_3/simple_string_test.sol index 270c2719b8..918c97c88e 100644 --- a/remix-tests/tests/examples_3/simple_string_test.sol +++ b/remix-tests/tests/examples_3/simple_string_test.sol @@ -1,5 +1,4 @@ pragma solidity ^0.4.7; -import "./tests.sol"; import "./simple_string.sol"; contract StringTest { From e5a3959eb4c3413b46ff16bf7cb97ac1478d4f0b Mon Sep 17 00:00:00 2001 From: 0mkar <0mkar@protonmail.com> Date: Mon, 27 Aug 2018 13:47:00 +0530 Subject: [PATCH 2/6] inject import statement only if not present --- remix-tests/examples/simple_storage2_test.sol | 1 + remix-tests/src/compiler.js | 12 +++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/remix-tests/examples/simple_storage2_test.sol b/remix-tests/examples/simple_storage2_test.sol index 814570aae7..3f0bc511c6 100644 --- a/remix-tests/examples/simple_storage2_test.sol +++ b/remix-tests/examples/simple_storage2_test.sol @@ -1,4 +1,5 @@ pragma solidity ^0.4.7; +import "remix_test.sol"; import "./simple_storage.sol"; contract MyTest2 { diff --git a/remix-tests/src/compiler.js b/remix-tests/src/compiler.js index 2fc3e2e52d..5b31cb70b2 100644 --- a/remix-tests/src/compiler.js +++ b/remix-tests/src/compiler.js @@ -1,11 +1,16 @@ +/* eslint no-extend-native: "warn" */ let fs = require('fs') var async = require('async') var path = require('path') const signale = require('signale') let RemixCompiler = require('remix-solidity').Compiler -// TODO: replace this with remix's own compiler code +String.prototype.regexIndexOf = function (regex, startpos) { + var indexOf = this.substring(startpos || 0).search(regex) + return (indexOf >= 0) ? (indexOf + (startpos || 0)) : indexOf +} +// TODO: replace this with remix's own compiler code function compileFileOrFiles (filename, isDirectory, cb) { let compiler, filepath @@ -23,7 +28,8 @@ function compileFileOrFiles (filename, isDirectory, cb) { // only process .sol files if (file.split('.').pop() === 'sol') { let c = fs.readFileSync(path.join(filepath, file)).toString() - if (file.indexOf('_test.sol') > 0) { + const s = /^(import)\s['"](remix_tests.sol|tests.sol)['"];/gm + if (file.indexOf('_test.sol') > 0 && c.regexIndexOf(s) < 0) { c = c.replace(/(pragma solidity \^\d+\.\d+\.\d+;)/, '$1\nimport \'remix_tests.sol\';') } sources[file] = { content: c } @@ -58,7 +64,7 @@ function compileContractSources (sources, importFileCb, cb) { let compiler, filepath if (!sources['remix_tests.sol']) { - sources['remix_tests.sol'] = {content: require('../sol/tests.sol.js')} + sources['remix_tests.sol'] = { content: require('../sol/tests.sol.js') } } async.waterfall([ From 853234175f599ed7eef2fc2e461b1d99255e03e2 Mon Sep 17 00:00:00 2001 From: 0mkar <0mkar@protonmail.com> Date: Sat, 25 Aug 2018 01:40:56 +0530 Subject: [PATCH 3/6] fix import, inject remix_tests.sol, use signale for logging --- remix-tests/examples/simple_storage2_test.sol | 2 -- remix-tests/examples/simple_storage_test.sol | 2 -- remix-tests/package.json | 1 + remix-tests/src/compiler.js | 16 +++++++--- remix-tests/src/index.js | 30 +++++++++++++++++-- remix-tests/src/run.js | 4 ++- .../tests/examples_1/simple_storage_test.sol | 2 -- .../tests/examples_2/simple_storage_test.sol | 2 -- .../tests/examples_3/simple_string_test.sol | 1 - 9 files changed, 43 insertions(+), 17 deletions(-) diff --git a/remix-tests/examples/simple_storage2_test.sol b/remix-tests/examples/simple_storage2_test.sol index 0c199f9b03..814570aae7 100644 --- a/remix-tests/examples/simple_storage2_test.sol +++ b/remix-tests/examples/simple_storage2_test.sol @@ -1,5 +1,4 @@ pragma solidity ^0.4.7; -import "./tests.sol"; import "./simple_storage.sol"; contract MyTest2 { @@ -26,4 +25,3 @@ contract MyTest2 { } } - diff --git a/remix-tests/examples/simple_storage_test.sol b/remix-tests/examples/simple_storage_test.sol index ec780ae85d..09392087e3 100644 --- a/remix-tests/examples/simple_storage_test.sol +++ b/remix-tests/examples/simple_storage_test.sol @@ -1,5 +1,4 @@ pragma solidity ^0.4.7; -import "./tests.sol"; import "./simple_storage.sol"; contract MyTest { @@ -26,4 +25,3 @@ contract MyTest { } } - diff --git a/remix-tests/package.json b/remix-tests/package.json index 50047c8ad6..a7ecf7e529 100644 --- a/remix-tests/package.json +++ b/remix-tests/package.json @@ -43,6 +43,7 @@ "commander": "^2.13.0", "remix-simulator": "0.0.3", "remix-solidity": "^0.2.6", + "signale": "^1.2.1", "solc": "^0.4.24", "standard": "^10.0.3", "web3": "1.0.0-beta.27" diff --git a/remix-tests/src/compiler.js b/remix-tests/src/compiler.js index e7de72c36f..2fc3e2e52d 100644 --- a/remix-tests/src/compiler.js +++ b/remix-tests/src/compiler.js @@ -1,7 +1,7 @@ let fs = require('fs') var async = require('async') var path = require('path') - +const signale = require('signale') let RemixCompiler = require('remix-solidity').Compiler // TODO: replace this with remix's own compiler code @@ -13,13 +13,21 @@ function compileFileOrFiles (filename, isDirectory, cb) { 'tests.sol': { content: require('../sol/tests.sol.js') }, 'remix_tests.sol': { content: require('../sol/tests.sol.js') } } + // signale.debug(sources) // TODO: for now assumes filepath dir contains all tests, later all this // should be replaced with remix's & browser solidity compiler code filepath = (isDirectory ? filename : path.dirname(filename)) fs.readdirSync(filepath).forEach(file => { - sources[file] = {content: fs.readFileSync(path.join(filepath, file)).toString()} + // only process .sol files + if (file.split('.').pop() === 'sol') { + let c = fs.readFileSync(path.join(filepath, file)).toString() + if (file.indexOf('_test.sol') > 0) { + c = c.replace(/(pragma solidity \^\d+\.\d+\.\d+;)/, '$1\nimport \'remix_tests.sol\';') + } + sources[file] = { content: c } + } }) async.waterfall([ @@ -39,7 +47,7 @@ function compileFileOrFiles (filename, isDirectory, cb) { ], function (err, result) { let errors = (result.errors || []).filter((e) => e.type === 'Error' || e.severity === 'error') if (errors.length > 0) { - console.dir(errors) + signale.fatal(errors) return cb(new Error('errors compiling')) } cb(err, result.contracts) @@ -70,7 +78,7 @@ function compileContractSources (sources, importFileCb, cb) { ], function (err, result) { let errors = (result.errors || []).filter((e) => e.type === 'Error' || e.severity === 'error') if (errors.length > 0) { - console.dir(errors) + signale.fatal(errors) return cb(new Error('errors compiling')) } cb(err, result.contracts) diff --git a/remix-tests/src/index.js b/remix-tests/src/index.js index f8019f1dfa..d5e86afc6c 100644 --- a/remix-tests/src/index.js +++ b/remix-tests/src/index.js @@ -1,6 +1,7 @@ const async = require('async') const path = require('path') const fs = require('fs') +const { Signale } = require('signale') require('colors') let Compiler = require('./compiler.js') @@ -11,11 +12,34 @@ const Web3 = require('web3') const Provider = require('remix-simulator').Provider var createWeb3Provider = function () { + signale.info('Creating providers') let web3 = new Web3() web3.setProvider(new Provider()) return web3 } +// signale configuration +const options = { + types: { + result: { + badge: '\t✓', + label: '', + color: 'greenBright' + }, + name: { + badge: '\n\t◼', + label: '', + color: 'white' + }, + error: { + badge: '\t✘', + label: '', + color: 'redBright' + } + } +} +const signale = new Signale(options) + var runTestSources = function (contractSources, testCallback, resultCallback, finalCallback, importFileCb) { async.waterfall([ function compile (next) { @@ -134,11 +158,11 @@ var runTestFiles = function (filepath, isDirectory, web3) { var testCallback = function (result) { if (result.type === 'contract') { - console.log('\n ' + result.value) + signale.name(result.value.white) } else if (result.type === 'testPass') { - console.log('\t✓ '.green.bold + result.value.grey) + signale.result(result.value) } else if (result.type === 'testFailure') { - console.log('\t✘ '.bold.red + result.value.red) + signale.result(result.value.red) errors.push(result) } } diff --git a/remix-tests/src/run.js b/remix-tests/src/run.js index 6eb4aa2655..6a3815f007 100644 --- a/remix-tests/src/run.js +++ b/remix-tests/src/run.js @@ -2,6 +2,7 @@ const commander = require('commander') const Web3 = require('web3') const RemixTests = require('./index.js') const fs = require('fs') +const signale = require('signale') const Provider = require('remix-simulator').Provider @@ -16,7 +17,8 @@ commander.action(function (filename) { }) if (!process.argv.slice(2).length) { - console.log('please specify filename') + signale.fatal('Please specify a filename') + process.exit() } commander.parse(process.argv) diff --git a/remix-tests/tests/examples_1/simple_storage_test.sol b/remix-tests/tests/examples_1/simple_storage_test.sol index 896970933f..6c4b35942f 100644 --- a/remix-tests/tests/examples_1/simple_storage_test.sol +++ b/remix-tests/tests/examples_1/simple_storage_test.sol @@ -1,5 +1,4 @@ pragma solidity ^0.4.7; -import "remix_tests.sol"; import "./simple_storage.sol"; contract MyTest { @@ -29,4 +28,3 @@ contract MyTest { } } - diff --git a/remix-tests/tests/examples_2/simple_storage_test.sol b/remix-tests/tests/examples_2/simple_storage_test.sol index 016b3c7f5d..b794095f5c 100644 --- a/remix-tests/tests/examples_2/simple_storage_test.sol +++ b/remix-tests/tests/examples_2/simple_storage_test.sol @@ -1,5 +1,4 @@ pragma solidity ^0.4.7; -import "./tests.sol"; import "./simple_storage.sol"; contract MyTest { @@ -25,4 +24,3 @@ contract MyTest { } } - diff --git a/remix-tests/tests/examples_3/simple_string_test.sol b/remix-tests/tests/examples_3/simple_string_test.sol index 270c2719b8..918c97c88e 100644 --- a/remix-tests/tests/examples_3/simple_string_test.sol +++ b/remix-tests/tests/examples_3/simple_string_test.sol @@ -1,5 +1,4 @@ pragma solidity ^0.4.7; -import "./tests.sol"; import "./simple_string.sol"; contract StringTest { From 62a4b8abb1a8d6681b8e8355e79b875a77243048 Mon Sep 17 00:00:00 2001 From: 0mkar <0mkar@protonmail.com> Date: Mon, 27 Aug 2018 13:47:00 +0530 Subject: [PATCH 4/6] inject import statement only if not present --- remix-tests/examples/simple_storage2_test.sol | 1 + remix-tests/src/compiler.js | 12 +++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/remix-tests/examples/simple_storage2_test.sol b/remix-tests/examples/simple_storage2_test.sol index 814570aae7..3f0bc511c6 100644 --- a/remix-tests/examples/simple_storage2_test.sol +++ b/remix-tests/examples/simple_storage2_test.sol @@ -1,4 +1,5 @@ pragma solidity ^0.4.7; +import "remix_test.sol"; import "./simple_storage.sol"; contract MyTest2 { diff --git a/remix-tests/src/compiler.js b/remix-tests/src/compiler.js index 2fc3e2e52d..5b31cb70b2 100644 --- a/remix-tests/src/compiler.js +++ b/remix-tests/src/compiler.js @@ -1,11 +1,16 @@ +/* eslint no-extend-native: "warn" */ let fs = require('fs') var async = require('async') var path = require('path') const signale = require('signale') let RemixCompiler = require('remix-solidity').Compiler -// TODO: replace this with remix's own compiler code +String.prototype.regexIndexOf = function (regex, startpos) { + var indexOf = this.substring(startpos || 0).search(regex) + return (indexOf >= 0) ? (indexOf + (startpos || 0)) : indexOf +} +// TODO: replace this with remix's own compiler code function compileFileOrFiles (filename, isDirectory, cb) { let compiler, filepath @@ -23,7 +28,8 @@ function compileFileOrFiles (filename, isDirectory, cb) { // only process .sol files if (file.split('.').pop() === 'sol') { let c = fs.readFileSync(path.join(filepath, file)).toString() - if (file.indexOf('_test.sol') > 0) { + const s = /^(import)\s['"](remix_tests.sol|tests.sol)['"];/gm + if (file.indexOf('_test.sol') > 0 && c.regexIndexOf(s) < 0) { c = c.replace(/(pragma solidity \^\d+\.\d+\.\d+;)/, '$1\nimport \'remix_tests.sol\';') } sources[file] = { content: c } @@ -58,7 +64,7 @@ function compileContractSources (sources, importFileCb, cb) { let compiler, filepath if (!sources['remix_tests.sol']) { - sources['remix_tests.sol'] = {content: require('../sol/tests.sol.js')} + sources['remix_tests.sol'] = { content: require('../sol/tests.sol.js') } } async.waterfall([ From cf1cd8c077f76154cb4abd90f4c2754f0b7467af Mon Sep 17 00:00:00 2001 From: 0mkar <0mkar@protonmail.com> Date: Tue, 28 Aug 2018 09:17:12 +0530 Subject: [PATCH 5/6] Add initial message --- remix-tests/src/run.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/remix-tests/src/run.js b/remix-tests/src/run.js index 6a3815f007..5793c1210d 100644 --- a/remix-tests/src/run.js +++ b/remix-tests/src/run.js @@ -2,11 +2,24 @@ const commander = require('commander') const Web3 = require('web3') const RemixTests = require('./index.js') const fs = require('fs') -const signale = require('signale') - +const { Signale } = require('signale') const Provider = require('remix-simulator').Provider +require('colors') + +// signale configuration +const options = { + types: { + greet: { + badge: '\n👁', + label: '', + color: 'yellow' + } + } +} +const signale = new Signale(options) commander.action(function (filename) { + signale.greet(('Running remix-tests: Unit testing for solidity.\n').yellow) let web3 = new Web3() // web3.setProvider(new web3.providers.HttpProvider('http://localhost:8545')) web3.setProvider(new Provider()) From 3891b5660e7e0f7703a141f1bf0198ec6dbb39cb Mon Sep 17 00:00:00 2001 From: 0mkar <0mkar@protonmail.com> Date: Tue, 28 Aug 2018 16:37:02 +0530 Subject: [PATCH 6/6] Add winston logger for different verbosity level --- remix-tests/package.json | 3 +- remix-tests/src/index.js | 1 - remix-tests/src/logger.js | 58 +++++++++++++++++++++++++++++++++++++++ remix-tests/src/run.js | 55 +++++++++++++++++++++++-------------- 4 files changed, 94 insertions(+), 23 deletions(-) create mode 100644 remix-tests/src/logger.js diff --git a/remix-tests/package.json b/remix-tests/package.json index a7ecf7e529..df2d3cab1f 100644 --- a/remix-tests/package.json +++ b/remix-tests/package.json @@ -46,7 +46,8 @@ "signale": "^1.2.1", "solc": "^0.4.24", "standard": "^10.0.3", - "web3": "1.0.0-beta.27" + "web3": "1.0.0-beta.27", + "winston": "^3.0.0" }, "devDependencies": { "mocha": "^5.1.0" diff --git a/remix-tests/src/index.js b/remix-tests/src/index.js index d5e86afc6c..0bd322382d 100644 --- a/remix-tests/src/index.js +++ b/remix-tests/src/index.js @@ -12,7 +12,6 @@ const Web3 = require('web3') const Provider = require('remix-simulator').Provider var createWeb3Provider = function () { - signale.info('Creating providers') let web3 = new Web3() web3.setProvider(new Provider()) return web3 diff --git a/remix-tests/src/logger.js b/remix-tests/src/logger.js new file mode 100644 index 0000000000..6dc6253bf1 --- /dev/null +++ b/remix-tests/src/logger.js @@ -0,0 +1,58 @@ +var gray = require('ansi-gray') +const winston = require('winston') +var timestamp = require('time-stamp') +var supportsColor = require('color-support') + +function hasFlag (flag) { + return ((typeof (process) !== 'undefined') && (process.argv.indexOf('--' + flag) !== -1)) +} + +function addColor (str) { + if (hasFlag('no-color')) { + return str + } + + if (hasFlag('color')) { + return gray(str) + } + + if (supportsColor()) { + return gray(str) + } + + return str +} +function getTimestamp () { + return '[' + addColor(timestamp('HH:mm:ss')) + ']' +} +// create winston logger format +const logFmt = winston.format.printf((info) => { + return `${getTimestamp()} ${info.level}: ${info.message}` +}) + +class Log { + constructor () { + this.logger = winston.createLogger({ + level: 'error', + transports: [new winston.transports.Console()], + format: winston.format.combine( + winston.format.colorize({ all: true }), + logFmt + ) + }) + } + setVerbosity (v) { + this.logger.configure({ + level: v, + transports: [new winston.transports.Console()], + format: winston.format.combine( + winston.format.colorize({ all: true }), + logFmt + ) + }) + } +} + +module.exports = { + Log +} diff --git a/remix-tests/src/run.js b/remix-tests/src/run.js index 5793c1210d..c06c1aace5 100644 --- a/remix-tests/src/run.js +++ b/remix-tests/src/run.js @@ -2,35 +2,48 @@ const commander = require('commander') const Web3 = require('web3') const RemixTests = require('./index.js') const fs = require('fs') -const { Signale } = require('signale') const Provider = require('remix-simulator').Provider +const { Log } = require('./logger.js') +const logger = new Log() +const log = logger.logger require('colors') -// signale configuration -const options = { - types: { - greet: { - badge: '\n👁', - label: '', - color: 'yellow' - } +// parse verbosity +function mapVerbosity (v) { + const levels = { + 0: 'error', + 1: 'warn', + 2: 'info', + 3: 'verbose', + 4: 'debug', + 5: 'silly' } + return levels[v] } -const signale = new Signale(options) - -commander.action(function (filename) { - signale.greet(('Running remix-tests: Unit testing for solidity.\n').yellow) - let web3 = new Web3() - // web3.setProvider(new web3.providers.HttpProvider('http://localhost:8545')) - web3.setProvider(new Provider()) - // web3.setProvider(new web3.providers.WebsocketProvider('ws://localhost:8546')) +// get current version +const pjson = require('../package.json') +commander + .version(pjson.version) + .option('-v, --verbose ', 'run with verbosity', mapVerbosity) + .action(function (filename) { + // Console message + console.log(('\n\t👁 :: Running remix-tests - Unit testing for solidity :: 👁\t\n').white) + // set logger verbosity + if (commander.verbose) { + logger.setVerbosity(commander.verbose) + log.info('verbosity level set to ' + commander.verbose.blue) + } + let web3 = new Web3() + // web3.setProvider(new web3.providers.HttpProvider('http://localhost:8545')) + web3.setProvider(new Provider()) + // web3.setProvider(new web3.providers.WebsocketProvider('ws://localhost:8546')) - let isDirectory = fs.lstatSync(filename).isDirectory() - RemixTests.runTestFiles(filename, isDirectory, web3) -}) + let isDirectory = fs.lstatSync(filename).isDirectory() + RemixTests.runTestFiles(filename, isDirectory, web3) + }) if (!process.argv.slice(2).length) { - signale.fatal('Please specify a filename') + log.error('Please specify a filename') process.exit() }