Commit 84a4d593 authored by Iuri Matias's avatar Iuri Matias

refactor: rejoin runTestFiles and runTestFile

parent 14dd2a8d
...@@ -7,62 +7,14 @@ let Compiler = require('./src/compiler.js') ...@@ -7,62 +7,14 @@ let Compiler = require('./src/compiler.js')
let Deployer = require('./src/deployer.js') let Deployer = require('./src/deployer.js')
let TestRunner = require('./src/testRunner.js') let TestRunner = require('./src/testRunner.js')
var runTest = function (contractName, contractObj, testCallback, resultsCallback) { var runTestFiles = function(filepath, is_directory, web3) {
TestRunner.runTest(contractName, contractObj, testCallback, resultsCallback)
}
var runTestFile = function (filename, web3) {
async.waterfall([ async.waterfall([
function compile (next) { function compile (next) {
Compiler.compileFile(filename, next) if (is_directory) {
}, Compiler.compileFiles(filepath, next)
function deployAllContracts (compilationResult, next) { } else {
Deployer.deployAll(compilationResult, web3, function (err, contracts) { Compiler.compileFile(filepath, next)
if (err) {
next(err)
}
let contractsToTest = Object.keys(compilationResult[path.basename(filename)])
next(null, contractsToTest, contracts)
})
},
function runTests (contractsToTest, contracts, next) {
var testCallback = function (result) {
if (result.type === 'contract') {
console.log(('\t ' + result.value).green)
} else if (result.type === 'testPass') {
console.log('\t✓ '.green.bold + result.value.grey)
} else if (result.type === 'testFailure') {
console.log('\t✘ '.bold.red + result.value.red)
}
}
var resultsCallback = function (_err, result, cb) {
if (result.passingNum > 0) {
console.log((result.passingNum + ' passing').green)
}
if (result.failureNum > 0) {
console.log((result.failureNum + ' failing').red)
}
cb()
}
async.eachLimit(contractsToTest, 1, (contractName, cb) => {
runTest(contractName, contracts[contractName], testCallback, (err, result) => {
if (err) {
return cb(err)
} }
resultsCallback(null, result, cb)
})
}, next)
}
], function () {
})
}
var runTestFiles = function (directory, web3) {
async.waterfall([
function compile (next) {
Compiler.compileFiles(directory, next)
}, },
function deployAllContracts (compilationResult, next) { function deployAllContracts (compilationResult, next) {
Deployer.deployAll(compilationResult, web3, function (err, contracts) { Deployer.deployAll(compilationResult, web3, function (err, contracts) {
...@@ -71,7 +23,8 @@ var runTestFiles = function (directory, web3) { ...@@ -71,7 +23,8 @@ var runTestFiles = function (directory, web3) {
} }
let contractsToTest = [] let contractsToTest = []
fs.readdirSync(directory).forEach(filename => { if (is_directory) {
fs.readdirSync(filepath).forEach(filename => {
if (filename.indexOf('_test.sol') < 0) { if (filename.indexOf('_test.sol') < 0) {
return return
} }
...@@ -79,6 +32,9 @@ var runTestFiles = function (directory, web3) { ...@@ -79,6 +32,9 @@ var runTestFiles = function (directory, web3) {
contractsToTest.push(contractName) contractsToTest.push(contractName)
}) })
}) })
} else {
contractsToTest = Object.keys(compilationResult[path.basename(filepath)])
}
next(null, contractsToTest, contracts) next(null, contractsToTest, contracts)
}) })
...@@ -104,7 +60,7 @@ var runTestFiles = function (directory, web3) { ...@@ -104,7 +60,7 @@ var runTestFiles = function (directory, web3) {
} }
async.eachOfLimit(contractsToTest, 1, (contractName, index, cb) => { async.eachOfLimit(contractsToTest, 1, (contractName, index, cb) => {
runTest(contractName, contracts[contractName], testCallback, (err, result) => { TestRunner.runTest(contractName, contracts[contractName], testCallback, (err, result) => {
if (err) { if (err) {
return cb(err) return cb(err)
} }
...@@ -117,7 +73,6 @@ var runTestFiles = function (directory, web3) { ...@@ -117,7 +73,6 @@ var runTestFiles = function (directory, web3) {
} }
module.exports = { module.exports = {
runTestFile: runTestFile,
runTestFiles: runTestFiles, runTestFiles: runTestFiles,
runTest: runTest runTest: TestRunner.runTest
} }
...@@ -7,11 +7,8 @@ commander.action(function (filename) { ...@@ -7,11 +7,8 @@ commander.action(function (filename) {
let web3 = new Web3() let web3 = new Web3()
web3.setProvider(new web3.providers.HttpProvider('http://localhost:8545')) web3.setProvider(new web3.providers.HttpProvider('http://localhost:8545'))
if (fs.lstatSync(filename).isDirectory()) { let isDirectory = fs.lstatSync(filename).isDirectory()
RemixTests.runTestFiles(filename, web3) RemixTests.runTestFiles(filename, isDirectory, web3)
} else {
RemixTests.runTestFile(filename, web3)
}
}) })
if (!process.argv.slice(2).length) { if (!process.argv.slice(2).length) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment