Skip to content

Commit

Permalink
restore removed methods which still used
Browse files Browse the repository at this point in the history
  • Loading branch information
outsideris authored and boneskull committed Mar 7, 2018
1 parent da6e5c9 commit eb09421
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
47 changes: 47 additions & 0 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,15 @@ var debug = require('debug')('mocha:watch');
var fs = require('fs');
var glob = require('glob');
var path = require('path');
var join = path.join;
var he = require('he');

/**
* Ignored directories.
*/

var ignore = ['node_modules', '.git'];

exports.inherits = require('util').inherits;

/**
Expand Down Expand Up @@ -54,6 +61,46 @@ exports.watch = function (files, fn) {
});
};

/**
* Ignored files.
*
* @api private
* @param {string} path
* @return {boolean}
*/
function ignored (path) {
return !~ignore.indexOf(path);
}

/**
* Lookup files in the given `dir`.
*
* @api private
* @param {string} dir
* @param {string[]} [ext=['.js']]
* @param {Array} [ret=[]]
* @return {Array}
*/
exports.files = function (dir, ext, ret) {
ret = ret || [];
ext = ext || ['js'];

var re = new RegExp('\\.(' + ext.join('|') + ')$');

fs.readdirSync(dir)
.filter(ignored)
.forEach(function (path) {
path = join(dir, path);
if (fs.lstatSync(path).isDirectory()) {
exports.files(path, ext, ret);
} else if (path.match(re)) {
ret.push(path);
}
});

return ret;
};

/**
* Compute a slug from the given `str`.
*
Expand Down
20 changes: 20 additions & 0 deletions test/node-unit/file-utils.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,26 @@ describe('file utils', function () {
});
});

describe('.files', function () {
(symlinkSupported ? it : it.skip)('should return broken symlink file path', function () {
expect(utils.files(tmpDir, ['js']))
.to.contain(tmpFile('mocha-utils-link.js'))
.and.contain(tmpFile('mocha-utils.js'))
.and.have.length(2);

expect(existsSync(tmpFile('mocha-utils-link.js')))
.to.be(true);

fs.renameSync(tmpFile('mocha-utils.js'), tmpFile('bob'));

expect(existsSync(tmpFile('mocha-utils-link.js')))
.to.be(false);

expect(utils.files(tmpDir, ['js']))
.to.eql([tmpFile('mocha-utils-link.js')]);
});
});

afterEach(removeTempDir);

function makeTempDir () {
Expand Down

0 comments on commit eb09421

Please sign in to comment.