abstract test results into callbacks

pull/7/head
Iuri Matias 7 years ago
parent 0c6c94c0f6
commit e525eaadcc
  1. 24
      index.js
  2. 21
      src/testRunner.js

@ -5,7 +5,29 @@ let Deployer = require('./src/deployer.js');
let TestRunner = require('./src/testRunner.js'); let TestRunner = require('./src/testRunner.js');
var runTest = function(contractName, contractObj, cb) { var runTest = function(contractName, contractObj, cb) {
TestRunner.runTest(contractName, contractObj, cb); var testCallback = function(result) {
if (result.type === 'contract') {
console.log(("#" + 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) {
if (err) {
return cb(err);
}
if (result.passingNum > 0) {
console.log((result.passingNum + " passing").green);
}
if (result.failureNum > 0) {
console.log((result.failureNum + " failing").red);
}
cb();
}
TestRunner.runTest(contractName, contractObj, testCallback, resultsCallback);
} }
var runTestFile = function(filename, web3) { var runTestFile = function(filename, web3) {

@ -2,7 +2,7 @@ var async = require('async');
var changeCase = require('change-case'); var changeCase = require('change-case');
require('colors'); require('colors');
function runTest(testName, testObject, callback) { function runTest(testName, testObject, testCallback, resultsCallback) {
let runList = []; let runList = [];
let specialFunctions = ['beforeAll']; let specialFunctions = ['beforeAll'];
let availableFunctions = testObject._jsonInterface.filter((x) => x.type === 'function').map((x) => x.name); let availableFunctions = testObject._jsonInterface.filter((x) => x.type === 'function').map((x) => x.name);
@ -18,19 +18,16 @@ function runTest(testName, testObject, callback) {
let passingNum = 0, failureNum = 0; let passingNum = 0, failureNum = 0;
console.log(("#" + testName).green); testCallback({type: "contract", value: testName});
async.eachOfLimit(runList, 1, function(func, index, next) { async.eachOfLimit(runList, 1, function(func, index, next) {
let method = testObject.methods[func.name].apply(testObject.methods[func.name], []); let method = testObject.methods[func.name].apply(testObject.methods[func.name], []);
if (func.constant) { if (func.constant) {
method.call().then((result) => { method.call().then((result) => {
if (result) { if (result) {
// TODO: should instead be returned in a callback, the caller can testCallback({type: "testPass", value: changeCase.sentenceCase(func.name)});
// decide how to handle the output (so works both in console and
// browser)
console.log("\t✓ ".green.bold + changeCase.sentenceCase(func.name).grey);
passingNum += 1; passingNum += 1;
} else { } else {
console.log("\t✘ ".bold.red + changeCase.sentenceCase(func.name).red); testCallback({type: "testFailure", value: changeCase.sentenceCase(func.name)});
failureNum += 1; failureNum += 1;
} }
next(); next();
@ -41,12 +38,10 @@ function runTest(testName, testObject, callback) {
}); });
} }
}, function() { }, function() {
if (passingNum > 0) { resultsCallback(null, {
console.log((passingNum + " passing").green); passingNum: passingNum,
} failureNum: failureNum
if (failureNum > 0) { });
console.log((failureNum + " failing").red);
}
}); });
} }

Loading…
Cancel
Save