Last active
March 1, 2018 02:59
-
-
Save Gaubee/24478b403f6389507081 to your computer and use it in GitHub Desktop.
使用fb-flo监听文件改动并运行测试用例。捕捉所有错误并在结尾进行输出。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var flo = require('fb-flo'), | |
fs = require('fs'), | |
path = require('path'), | |
exec = require('child_process').exec; | |
var server = flo('./core/', { | |
port: 8888, | |
glob: ['**/*.js'] | |
}, resolver); | |
server.once('ready', function() { | |
console.log('Ready!'); | |
}); | |
function resolver(filepath, callback) { | |
var fileList = fs.readdirSync("./core/_test"); | |
var index = 0; | |
var errorList = {}; | |
function runNodeTest () { | |
var fileName = fileList[index]; | |
if (!fileName) { | |
printAllError(); | |
console.log("!!!END!!!") | |
return; | |
} | |
console.log("********[+",fileName,"]********"); | |
console.time(fileName); | |
exec("node ./core/_test/"+JSON.stringify(fileName),function (err,stdout) { | |
if (err) { | |
var errStack = err.stack.split("\n"); | |
//get error line number and column number and error message as error hash | |
var errHash = errStack[1]+errStack[4]; | |
if(!errorList[errHash]){ | |
errorList[errHash] = err; | |
} | |
} | |
console.log(stdout); | |
console.timeEnd(fileName); | |
console.log("********[-",fileName,"(",err?"error":"success",")]********\n\n"); | |
index+=1; | |
runNodeTest(); | |
}); | |
}; | |
runNodeTest(); | |
//prinln all error | |
function printAllError (argument) { | |
console.log("\n\n********[Catch",Object.keys(errorList).length,"Error!]********") | |
Object.keys(errorList).forEach(function (errHash,index) { | |
index = index+1; | |
console.log("---------------[+error:",index,"]----------------") | |
console.dir(errorList[errHash]); | |
console.log("---------------[-error:",index,"]----------------") | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment