Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow nodeunit to run tests in a dir and recursively inside its child dirs #54

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 34 additions & 22 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ var async = require('../deps/async'),
fs = require('fs'),
sys = require('sys'),
Script = process.binding('evals').Script,
http = require('http');
http = require('http'),
path = require('path');


/**
Expand Down Expand Up @@ -53,33 +54,44 @@ exports.modulePaths = function (paths, callback) {
return cb(null, [p]);
}
if (stats.isDirectory()) {
fs.readdir(p, function (err, files) {
if (err) {
return cb(err);
}

// filter out any filenames with unsupported extensions
var modules = files.filter(function (filename) {
return extensionPattern.exec(filename);
});

// remove extension from module name and prepend the
// directory path
var fullpaths = modules.map(function (filename) {
var mod_name = filename.replace(extensionPattern, '');
return [p, mod_name].join('/');
});

// sort filenames here, because Array.map changes order
fullpaths.sort();

cb(null, fullpaths);
var files = exports.readDirRecursive(p);

// filter out any filenames with unsupported extensions
var modules = files.filter(function (filename) {
return extensionPattern.exec(filename);
});

// remove extension from module name and prepend the
// directory path
var fullpaths = modules.map(function (filename) {
var mod_name = filename.replace(extensionPattern, '');
return [p, mod_name].join('/');
});

// sort filenames here, because Array.map changes order
fullpaths.sort();

cb(null, fullpaths);
}
});
}, callback);
};

exports.readDirRecursive = function(dir) {
var list = [];
fs.readdirSync(dir).forEach(function(entityName) {
var entityPath = path.join(dir, entityName);
if ( fs.statSync(entityPath).isDirectory() ) {
exports.readDirRecursive(entityPath).forEach(function(file) {
list.push(path.join(entityName, file));
});
} else {
list.push(entityName);
}
});
return list;
};

/**
* Evaluates JavaScript files in a sandbox, returning the context. The first
* argument can either be a single filename or an array of filenames. If
Expand Down