Skip to content

armgit / mocha

Public Imported from GitHub
0

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

restore removed methods which still used

Outsidereb094216bc02
diff --git a/lib/utils.js b/lib/utils.js
index a308490a..60151b66 100644
--- a/lib/utils.js
+++ b/lib/utils.js
@@ -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;
/**
@@ -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`.
*
diff --git a/test/node-unit/file-utils.spec.js b/test/node-unit/file-utils.spec.js
index e3c4f4a4..1ee06724 100644
--- a/test/node-unit/file-utils.spec.js
+++ b/test/node-unit/file-utils.spec.js
@@ -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 () {