Skip to content

armgit / mocha

Public Imported from GitHub
0

☕️ Classic, reliable, trusted test framework for Node.js and the browser

cleanup mocha(1) file lookup for --recursive a bit

TJ Holowaychuk740780c405d3
diff --git a/bin/_mocha b/bin/_mocha
index 84b7f53f..7f1b9485 100755
--- a/bin/_mocha
+++ b/bin/_mocha
@@ -204,18 +204,8 @@ var files = program.args;
// default files to test/*.{js,coffee}
-function dir(p) {
- fs.readdirSync(p).forEach(function(file){
- file = path.join(p, file);
- var stat = fs.statSync(file);
- if (stat.isDirectory()) return program.recursive ? dir(file) : null;
- if (!stat.isFile() || !re.test(file)) return;
- files.push(file);
- });
-}
-
if (!files.length) {
- dir(path.join(cwd, 'test'))
+ files = lookupFiles(path.join(cwd, 'test'), program.recursive);
}
// resolve
@@ -358,6 +348,25 @@ function stop() {
clearInterval(play.timer);
}
+/**
+ * Lookup file names at the given `path`.
+ */
+
+function lookupFiles(p, recursive) {
+ var files = [];
+ fs.readdirSync(p).forEach(function(file){
+ file = path.join(p, file);
+ var stat = fs.statSync(file);
+ if (stat.isDirectory()) {
+ if (recursive) files = files.concat(lookupFiles(file, true));
+ return
+ }
+ if (!stat.isFile() || !re.test(file)) return;
+ files.push(file);
+ });
+ return files;
+}
+
/**
* Play the given array of strings.
*/