Skip to content

Commit

Permalink
Merge 37325b4 into 9b00fed
Browse files Browse the repository at this point in the history
  • Loading branch information
juergba committed May 9, 2019
2 parents 9b00fed + 37325b4 commit f921683
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -563,33 +563,37 @@ function isHiddenOnUnix(pathname) {
* @public
* @memberof Mocha.utils
* @param {string} filepath - Base path to start searching from.
* @param {string[]} extensions - File extensions to look for.
* @param {boolean} recursive - Whether to recurse into subdirectories.
* @param {string[]} [extensions=[]] - File extensions to look for.
* @param {boolean} [recursive=false] - Whether to recurse into subdirectories.
* @return {string[]} An array of paths.
* @throws {Error} if no files match pattern.
* @throws {TypeError} if `filepath` is directory and `extensions` not provided.
*/
exports.lookupFiles = function lookupFiles(filepath, extensions, recursive) {
extensions = extensions || [];
recursive = recursive || false;
var files = [];
var stat;

if (!fs.existsSync(filepath)) {
// check all extensions
extensions.forEach(function(ext) {
if (fs.existsSync(filepath + '.' + ext)) {
files.push(filepath + '.' + ext);
}
});
if (glob.hasMagic(filepath)) {
// Handle glob without extensions
files = glob.sync(filepath, {nodir: true});
} else {
// glob pattern e.g. 'filepath+(js|ts)'
var strExtensions = extensions
.map(function(v) {
return '.' + v;
})
.join('|');
var pattern = filepath + '+(' + strExtensions + ')';
files = glob.sync(pattern, {nodir: true});
}
if (!files.length) {
// Handle glob
files = glob.sync(filepath);
if (!files.length) {
throw createNoFilesMatchPatternError(
'Cannot find any files matching pattern ' + exports.dQuote(filepath),
filepath
);
}
throw createNoFilesMatchPatternError(
'Cannot find any files matching pattern ' + exports.dQuote(filepath),
filepath
);
}
return files;
}
Expand Down

0 comments on commit f921683

Please sign in to comment.