counterpane
Advanced tools
Comparing version
var fs = require('fs'); | ||
var colors = require('colors'); | ||
var argv = require('optimist').argv; | ||
var path = require('path'); | ||
exports.count = function(options){ | ||
@@ -9,5 +13,7 @@ options = options || {}; | ||
var testDir = options.testDir || argv.t || ''; | ||
process.chrdir('../.../..'); | ||
console.log(srcDir, testDir, __dirname, __filename, process.cwd()); | ||
srcDir = path.join(process.cwd() + srcDir); | ||
testDir = path.join(process.cwd() + testDir); | ||
var ignoreList = [ | ||
@@ -45,67 +51,51 @@ '/app/config.js', | ||
var walk = function (dir, done) { | ||
fs.readdir(dir, function (error, list) { | ||
console.log(list); | ||
if (error) { | ||
return done(error); | ||
} | ||
var i = 0; | ||
(function next () { | ||
var file = list[i++]; | ||
if (!file) { | ||
return done(null); | ||
function walk(dir) { | ||
var list = fs.readdirSync(dir), | ||
stat, | ||
newPath, | ||
file, | ||
checkFile; | ||
for(var i = 0; i<list.length; i++){ | ||
newPath = path.join(dir, list[i]); | ||
stat = fs.statSync(newPath); | ||
if(stat && stat.isDirectory()){ | ||
walk(newPath); | ||
} else if(stat && stat.isFile()){ | ||
var skip = false; | ||
for (var j = 0; j < ignoreList.length; j++) { | ||
if (newPath.indexOf(ignoreList[j]) !== -1) { | ||
skip = true; | ||
skipCount++; | ||
break; | ||
} | ||
} | ||
file = dir + '/' + file; | ||
fs.stat(file, function (error, stat) { | ||
if (stat && stat.isDirectory()) { | ||
walk(file, function (error) { | ||
next(); | ||
}); | ||
} else { | ||
var skip = false; | ||
for (var j = 0; j < ignoreList.length; j++) { | ||
if (file.indexOf(ignoreList[j]) !== -1) { | ||
//console.log('skipping ' + file); | ||
skip = true; | ||
skipCount++; | ||
break; | ||
} | ||
} | ||
if (!skip) { | ||
var checkFile = file.replace(srcDir, testDir); | ||
console.log(checkFile); | ||
fs.stat(checkFile, function (error, stat) { | ||
if (!skip) { | ||
checkFile = newPath.replace(srcDir, testDir); | ||
try{ | ||
fs.statSync(checkFile); | ||
foundCount++; | ||
} catch(error){ | ||
relFilePath = checkFile.replace(testDir, ''); | ||
splitPath = relFilePath.split('/'); | ||
appDir = splitPath[0]; | ||
if (!stat || !stat.isFile()) { | ||
relFilePath = file.replace(srcDir, ''); | ||
splitPath = relFilePath.split('/'); | ||
appDir = splitPath[1]; | ||
fileName = splitPath.slice(2,splitPath.length).join('/'); | ||
if(typeof output[appDir] !== 'undefined'){ | ||
output[appDir].push(fileName); | ||
} else { | ||
output[appDir] = [fileName]; | ||
fileName = splitPath.slice(1,splitPath.length).join('/'); | ||
if(typeof output[appDir] !== 'undefined'){ | ||
output[appDir].push(fileName); | ||
} else { | ||
output[appDir] = [fileName]; | ||
} | ||
//output[appDir].push[(fileName); | ||
//console.warn(appDir + ': ' + fileName + ' missing test'); | ||
missingCount++; | ||
} | ||
else { | ||
foundCount++; | ||
//console.log(file + ' OK'); | ||
} | ||
}); | ||
} | ||
next(); | ||
} | ||
missingCount++; | ||
} | ||
}); | ||
})(); | ||
}); | ||
} | ||
} | ||
} | ||
return output; | ||
} | ||
}; | ||
console.log('-------------------------------------------------------------'); | ||
@@ -115,18 +105,14 @@ console.log('processing...'); | ||
walk(srcDir, function(error) { | ||
if (error) { | ||
throw error; | ||
} else { | ||
write(output); | ||
var results = walk(srcDir); | ||
write(results); | ||
console.log('-------------------------------------------------------------'); | ||
console.log('Finished.\n'); | ||
console.log('Found tests : ' + String(foundCount).green); | ||
console.log('Skipped files : ' + String(skipCount).yellow); | ||
console.log('Missing tests : ' + String(missingCount).red); | ||
console.log('-------------------------------------------------------------'); | ||
console.log('Finished.\n'); | ||
console.log('Found tests : ' + String(foundCount).green); | ||
console.log('Skipped files : ' + String(skipCount).yellow); | ||
console.log('Missing tests : ' + String(missingCount).red); | ||
console.log('-------------------------------------------------------------'); | ||
} | ||
}); | ||
console.log('-------------------------------------------------------------'); | ||
}; | ||
@@ -5,3 +5,3 @@ { | ||
"description": "Counts files covered by tests", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"repository": { | ||
@@ -8,0 +8,0 @@ "url": "" |
3809
-15.79%97
-17.09%