From a0b229202954555f12869c4816005f189fdf16a5 Mon Sep 17 00:00:00 2001 From: Kamil Skowron Date: Thu, 3 Jul 2014 22:30:47 +0100 Subject: [PATCH] Added support for recursive tests --- bin/nodeunit | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/bin/nodeunit b/bin/nodeunit index e3e15b57c..49e076505 100755 --- a/bin/nodeunit +++ b/bin/nodeunit @@ -15,13 +15,42 @@ var args = (process.ARGV || process.argv).slice(2); var files = []; +/** + * Method responsible for recursive search for test files passed + * in arguments + */ +var parsePath = function (dir, files) { + + var stat = fs.statSync(dir); + if (!stat || !stat.isDirectory()) { + files.push(dir); + return files; + } + + fs.readdirSync(dir).forEach(function (file) { + + file = dir + '/' + file; + + var stat = fs.statSync(file); + + if (stat && stat.isDirectory()) { + parsePath(file, files); + } else { + files.push(file); + } + + }); + + return files; +}; + var testrunner, config_file, config_param_found = false, output_param_found = false, reporter_file = 'default', reporter_param_found = false, - testspec_param_found = false; + testspec_param_found = false, testFullSpec_param_found = false; var usage = "Usage: nodeunit [options] testmodule1.js testfolder [...] \n" + @@ -97,7 +126,7 @@ args.forEach(function (arg) { console.log(usage); process.exit(0); } else { - files.push(arg); + files = parsePath(arg, files); } });