mocha 5.0.3 → 5.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/utils.js CHANGED
@@ -1,5 +1,9 @@
1
1
  'use strict';
2
2
 
3
+ /**
4
+ * @module
5
+ */
6
+
3
7
  /**
4
8
  * Module dependencies.
5
9
  */
@@ -8,8 +12,15 @@ var debug = require('debug')('mocha:watch');
8
12
  var fs = require('fs');
9
13
  var glob = require('glob');
10
14
  var path = require('path');
15
+ var join = path.join;
11
16
  var he = require('he');
12
17
 
18
+ /**
19
+ * Ignored directories.
20
+ */
21
+
22
+ var ignore = ['node_modules', '.git'];
23
+
13
24
  exports.inherits = require('util').inherits;
14
25
 
15
26
  /**
@@ -54,6 +65,46 @@ exports.watch = function (files, fn) {
54
65
  });
55
66
  };
56
67
 
68
+ /**
69
+ * Ignored files.
70
+ *
71
+ * @api private
72
+ * @param {string} path
73
+ * @return {boolean}
74
+ */
75
+ function ignored (path) {
76
+ return !~ignore.indexOf(path);
77
+ }
78
+
79
+ /**
80
+ * Lookup files in the given `dir`.
81
+ *
82
+ * @api private
83
+ * @param {string} dir
84
+ * @param {string[]} [ext=['.js']]
85
+ * @param {Array} [ret=[]]
86
+ * @return {Array}
87
+ */
88
+ exports.files = function (dir, ext, ret) {
89
+ ret = ret || [];
90
+ ext = ext || ['js'];
91
+
92
+ var re = new RegExp('\\.(' + ext.join('|') + ')$');
93
+
94
+ fs.readdirSync(dir)
95
+ .filter(ignored)
96
+ .forEach(function (path) {
97
+ path = join(dir, path);
98
+ if (fs.lstatSync(path).isDirectory()) {
99
+ exports.files(path, ext, ret);
100
+ } else if (path.match(re)) {
101
+ ret.push(path);
102
+ }
103
+ });
104
+
105
+ return ret;
106
+ };
107
+
57
108
  /**
58
109
  * Compute a slug from the given `str`.
59
110
  *
@@ -414,6 +465,8 @@ exports.canonicalize = function canonicalize (value, stack, typeHint) {
414
465
  /**
415
466
  * Lookup file names at the given `path`.
416
467
  *
468
+ * @memberof Mocha.utils
469
+ * @public
417
470
  * @api public
418
471
  * @param {string} filepath Base path to start searching from.
419
472
  * @param {string[]} extensions File extensions to look for.