mocha 7.2.0 → 8.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.
Files changed (46) hide show
  1. package/CHANGELOG.md +116 -0
  2. package/bin/mocha +17 -2
  3. package/browser-entry.js +26 -9
  4. package/lib/browser/growl.js +2 -1
  5. package/lib/browser/highlight-tags.js +39 -0
  6. package/lib/browser/parse-query.js +24 -0
  7. package/lib/browser/progress.js +4 -0
  8. package/lib/browser/template.html +7 -5
  9. package/lib/cli/cli.js +2 -2
  10. package/lib/cli/collect-files.js +15 -9
  11. package/lib/cli/config.js +0 -1
  12. package/lib/cli/init.js +1 -2
  13. package/lib/cli/lookup-files.js +145 -0
  14. package/lib/cli/node-flags.js +2 -2
  15. package/lib/cli/options.js +11 -87
  16. package/lib/cli/run-helpers.js +54 -16
  17. package/lib/cli/run-option-metadata.js +4 -2
  18. package/lib/cli/run.js +61 -14
  19. package/lib/cli/watch-run.js +211 -51
  20. package/lib/context.js +0 -15
  21. package/lib/errors.js +26 -3
  22. package/lib/esm-utils.js +11 -6
  23. package/lib/hook.js +24 -0
  24. package/lib/interfaces/common.js +19 -11
  25. package/lib/mocha.js +137 -121
  26. package/lib/mocharc.json +0 -1
  27. package/lib/nodejs/buffered-worker-pool.js +174 -0
  28. package/lib/{growl.js → nodejs/growl.js} +3 -2
  29. package/lib/nodejs/parallel-buffered-runner.js +295 -0
  30. package/lib/nodejs/reporters/parallel-buffered.js +133 -0
  31. package/lib/nodejs/serializer.js +404 -0
  32. package/lib/nodejs/worker.js +154 -0
  33. package/lib/pending.js +4 -0
  34. package/lib/reporters/base.js +25 -12
  35. package/lib/reporters/landing.js +3 -3
  36. package/lib/reporters/tap.js +1 -2
  37. package/lib/reporters/xunit.js +3 -2
  38. package/lib/runnable.js +18 -30
  39. package/lib/runner.js +58 -64
  40. package/lib/suite.js +32 -24
  41. package/lib/test.js +28 -1
  42. package/lib/utils.js +19 -206
  43. package/mocha.js +25522 -18248
  44. package/mocha.js.map +1 -0
  45. package/package.json +52 -42
  46. package/lib/browser/tty.js +0 -13
package/CHANGELOG.md CHANGED
@@ -1,3 +1,113 @@
1
+ # 8.1.1 / 2020-08-04
2
+
3
+ ## :bug: Fixes
4
+
5
+ - [#4394](https://github.com/mochajs/mocha/issues/4394): Fix regression wherein certain reporters did not correctly detect terminal width ([**@boneskull**](https://github.com/boneskull))
6
+
7
+ # 8.1.0 / 2020-07-30
8
+
9
+ In this release, Mocha now builds its browser bundle with Rollup and Babel, which will provide the project's codebase more flexibility and consistency.
10
+
11
+ While we've been diligent about backwards compatibility, it's _possible_ consumers of the browser bundle will encounter differences (other than an increase in the bundle size). If you _do_ encounter an issue with the build, please [report it here](https://github.com/mochajs/mocha/issues/new?labels=unconfirmed-bug&template=bug_report.md&title=).
12
+
13
+ This release **does not** drop support for IE11.
14
+
15
+ Other community contributions came from [**@Devjeel**](https://github.com/Devjeel), [**@Harsha509**](https://github.com/Harsha509) and [**@sharath2106**](https://github.com/sharath2106). _Thank you_ to everyone who contributed to this release!
16
+
17
+ > Do you read Korean? See [this guide to running parallel tests in Mocha](https://blog.outsider.ne.kr/1489), translated by our maintainer, [**@outsideris**](https://github.com/outsideris).
18
+
19
+ ## :tada: Enhancements
20
+
21
+ - [#4287](https://github.com/mochajs/mocha/issues/4287): Use background colors with inline diffs for better visual distinction ([**@michael-brade**](https://github.com/michael-brade))
22
+
23
+ ## :bug: Fixes
24
+
25
+ - [#4328](https://github.com/mochajs/mocha/issues/4328): Fix "watch" mode when Mocha run in parallel ([**@boneskull**](https://github.com/boneskull))
26
+ - [#4382](https://github.com/mochajs/mocha/issues/4382): Fix root hook execution in "watch" mode ([**@indieisaconcept**](https://github.com/indieisaconcept))
27
+ - [#4383](https://github.com/mochajs/mocha/issues/4383): Consistent auto-generated hook titles ([**@cspotcode**](https://github.com/cspotcode))
28
+ - [#4359](https://github.com/mochajs/mocha/issues/4359): Better errors when running `mocha init` ([**@boneskull**](https://github.com/boneskull))
29
+ - [#4341](https://github.com/mochajs/mocha/issues/4341): Fix weirdness when using `delay` option in browser ([**@craigtaub**](https://github.com/craigtaub))
30
+
31
+ ## :lock: Security Fixes
32
+
33
+ - [#4378](https://github.com/mochajs/mocha/issues/4378), [#4333](https://github.com/mochajs/mocha/issues/4333): Update [javascript-serialize](https://npm.im/javascript-serialize) ([**@martinoppitz**](https://github.com/martinoppitz), [**@wnghdcjfe**](https://github.com/wnghdcjfe))
34
+ - [#4354](https://github.com/mochajs/mocha/issues/4354): Update [yargs-unparser](https://npm.im/yargs-unparser) ([**@martinoppitz**](https://github.com/martinoppitz))
35
+
36
+ ## :book: Documentation & Website
37
+
38
+ - [#4173](https://github.com/mochajs/mocha/issues/4173): Document how to use `--enable-source-maps` with Mocha ([**@bcoe**](https://github.com/bcoe))
39
+ - [#4343](https://github.com/mochajs/mocha/issues/4343): Clean up some API docs ([**@craigtaub**](https://github.com/craigtaub))
40
+ - [#4318](https://github.com/mochajs/mocha/issues/4318): Sponsor images are now self-hosted ([**@Munter**](https://github.com/Munter))
41
+
42
+ ## :nut_and_bolt: Other
43
+
44
+ - [#4293](https://github.com/mochajs/mocha/issues/4293): Use Rollup and Babel in build pipeline; add source map to published files ([**@Munter**](https://github.com/Munter))
45
+
46
+ # 8.0.1 / 2020-06-10
47
+
48
+ The obligatory patch after a major.
49
+
50
+ ## :bug: Fixes
51
+
52
+ - [#4328](https://github.com/mochajs/mocha/issues/4328): Fix `--parallel` when combined with `--watch` ([**@boneskull**](https://github.com/boneskull))
53
+
54
+ # 8.0.0 / 2020-06-10
55
+
56
+ In this major release, Mocha adds the ability to _run tests in parallel_. Better late than never! Please note the **breaking changes** detailed below.
57
+
58
+ Let's welcome [**@giltayar**](https://github.com/giltayar) and [**@nicojs**](https://github.com/nicojs) to the maintenance team!
59
+
60
+ ## :boom: Breaking Changes
61
+
62
+ - [#4164](https://github.com/mochajs/mocha/issues/4164): **Mocha v8.0.0 now requires Node.js v10.12.0 or newer.** Mocha no longer supports the Node.js v8.x line ("Carbon"), which entered End-of-Life at the end of 2019 ([**@UlisesGascon**](https://github.com/UlisesGascon))
63
+
64
+ - [#4175](https://github.com/mochajs/mocha/issues/4175): Having been deprecated with a warning since v7.0.0, **`mocha.opts` is no longer supported** ([**@juergba**](https://github.com/juergba))
65
+
66
+ :sparkles: **WORKAROUND:** Replace `mocha.opts` with a [configuration file](https://mochajs.org/#configuring-mocha-nodejs).
67
+
68
+ - [#4260](https://github.com/mochajs/mocha/issues/4260): Remove `enableTimeout()` (`this.enableTimeout()`) from the context object ([**@craigtaub**](https://github.com/craigtaub))
69
+
70
+ :sparkles: **WORKAROUND:** Replace usage of `this.enableTimeout(false)` in your tests with `this.timeout(0)`.
71
+
72
+ - [#4315](https://github.com/mochajs/mocha/issues/4315): The `spec` option no longer supports a comma-delimited list of files ([**@juergba**](https://github.com/juergba))
73
+
74
+ :sparkles: **WORKAROUND**: Use an array instead (e.g., `"spec": "foo.js,bar.js"` becomes `"spec": ["foo.js", "bar.js"]`).
75
+
76
+ - [#4309](https://github.com/mochajs/mocha/issues/4309): Drop support for Node.js v13.x line, which is now End-of-Life ([**@juergba**](https://github.com/juergba))
77
+
78
+ - [#4282](https://github.com/mochajs/mocha/issues/4282): `--forbid-only` will throw an error even if exclusive tests are avoided via `--grep` or other means ([**@arvidOtt**](https://github.com/arvidOtt))
79
+
80
+ - [#4223](https://github.com/mochajs/mocha/issues/4223): The context object's `skip()` (`this.skip()`) in a "before all" (`before()`) hook will no longer execute subsequent sibling hooks, in addition to hooks in child suites ([**@juergba**](https://github.com/juergba))
81
+
82
+ - [#4178](https://github.com/mochajs/mocha/issues/4178): Remove previously soft-deprecated APIs ([**@wnghdcjfe**](https://github.com/wnghdcjfe)):
83
+
84
+ - `Mocha.prototype.ignoreLeaks()`
85
+ - `Mocha.prototype.useColors()`
86
+ - `Mocha.prototype.useInlineDiffs()`
87
+ - `Mocha.prototype.hideDiff()`
88
+
89
+ ## :tada: Enhancements
90
+
91
+ - [#4245](https://github.com/mochajs/mocha/issues/4245): Add ability to run tests in parallel for Node.js (see [docs](https://mochajs.org/#parallel-tests)) ([**@boneskull**](https://github.com/boneskull))
92
+
93
+ :exclamation: See also [#4244](https://github.com/mochajs/mocha/issues/4244); [Root Hook Plugins (docs)](https://mochajs.org/#root-hook-plugins) -- _root hooks must be defined via Root Hook Plugins to work in parallel mode_
94
+
95
+ - [#4304](https://github.com/mochajs/mocha/issues/4304): `--require` now works with ES modules ([**@JacobLey**](https://github.com/JacobLey))
96
+
97
+ - [#4299](https://github.com/mochajs/mocha/issues/4299): In some circumstances, Mocha can run ES modules under Node.js v10 -- _use at your own risk!_ ([**@giltayar**](https://github.com/giltayar))
98
+
99
+ ## :book: Documentation
100
+
101
+ - [#4246](https://github.com/mochajs/mocha/issues/4246): Add documentation for parallel mode and Root Hook plugins ([**@boneskull**](https://github.com/boneskull))
102
+
103
+ ## :nut_and_bolt: Other
104
+
105
+ - [#4200](https://github.com/mochajs/mocha/issues/4200): Drop mkdirp and replace it with fs.mkdirSync ([**@HyunSangHan**](https://github.com/HyunSangHan))
106
+
107
+ ## :bug: Fixes
108
+
109
+ (All bug fixes in Mocha v8.0.0 are also breaking changes, and are listed above)
110
+
1
111
  # 7.2.0 / 2020-05-22
2
112
 
3
113
  ## :tada: Enhancements
@@ -159,6 +269,12 @@ These are _soft_-deprecated, and will emit a warning upon use. Support will be r
159
269
  - [#4089](https://github.com/mochajs/mocha/issues/4089): Add funding information to `package.json` ([**@Munter**](https://github.com/Munter))
160
270
  - [#4077](https://github.com/mochajs/mocha/issues/4077): Improve integration tests ([**@soobing**](https://github.com/soobing))
161
271
 
272
+ # 6.2.3 / 2020-03-25
273
+
274
+ ## :lock: Security Fixes
275
+
276
+ - [848d6fb8](https://github.com/mochajs/mocha/commit/848d6fb8feef659564b296db457312d38176910d): Update dependencies mkdirp, yargs-parser and yargs ([**@juergba**](https://github.com/juergba))
277
+
162
278
  # 6.2.2 / 2019-10-18
163
279
 
164
280
  ## :bug: Fixes
package/bin/mocha CHANGED
@@ -130,8 +130,23 @@ if (Object.keys(nodeArgs).length) {
130
130
 
131
131
  // terminate children.
132
132
  process.on('SIGINT', () => {
133
- proc.kill('SIGINT'); // calls runner.abort()
134
- proc.kill('SIGTERM'); // if that didn't work, we're probably in an infinite loop, so make it die.
133
+ // XXX: a previous comment said this would abort the runner, but I can't see that it does
134
+ // anything with the default runner.
135
+ debug('main process caught SIGINT');
136
+ proc.kill('SIGINT');
137
+ // if running in parallel mode, we will have a proper SIGINT handler, so the below won't
138
+ // be needed.
139
+ if (!args.parallel || args.jobs < 2) {
140
+ // win32 does not support SIGTERM, so use next best thing.
141
+ if (require('os').platform() === 'win32') {
142
+ proc.kill('SIGKILL');
143
+ } else {
144
+ // using SIGKILL won't cleanly close the output streams, which can result
145
+ // in cut-off text or a befouled terminal.
146
+ debug('sending SIGTERM to child process');
147
+ proc.kill('SIGTERM');
148
+ }
149
+ }
135
150
  });
136
151
  } else {
137
152
  debug('running Mocha in-process');
package/browser-entry.js CHANGED
@@ -9,6 +9,8 @@
9
9
 
10
10
  process.stdout = require('browser-stdout')({label: false});
11
11
 
12
+ var parseQuery = require('./lib/browser/parse-query');
13
+ var highlightTags = require('./lib/browser/highlight-tags');
12
14
  var Mocha = require('./lib/mocha');
13
15
 
14
16
  /**
@@ -77,6 +79,13 @@ process.on = function(e, fn) {
77
79
  }
78
80
  };
79
81
 
82
+ process.listeners = function(e) {
83
+ if (e === 'uncaughtException') {
84
+ return uncaughtExceptionHandlers;
85
+ }
86
+ return [];
87
+ };
88
+
80
89
  // The BDD UI is registered by default, but no UI will be functional in the
81
90
  // browser without an explicit call to the overridden `mocha.ui` (see below).
82
91
  // Ensure that this default UI does not expose its methods to the global scope.
@@ -139,11 +148,19 @@ mocha.setup = function(opts) {
139
148
  if (typeof opts === 'string') {
140
149
  opts = {ui: opts};
141
150
  }
142
- for (var opt in opts) {
143
- if (Object.prototype.hasOwnProperty.call(opts, opt)) {
144
- this[opt](opts[opt]);
145
- }
151
+ if (opts.delay === true) {
152
+ this.delay();
146
153
  }
154
+ var self = this;
155
+ Object.keys(opts)
156
+ .filter(function(opt) {
157
+ return opt !== 'delay';
158
+ })
159
+ .forEach(function(opt) {
160
+ if (Object.prototype.hasOwnProperty.call(opts, opt)) {
161
+ self[opt](opts[opt]);
162
+ }
163
+ });
147
164
  return this;
148
165
  };
149
166
 
@@ -155,7 +172,7 @@ mocha.run = function(fn) {
155
172
  var options = mocha.options;
156
173
  mocha.globals('location');
157
174
 
158
- var query = Mocha.utils.parseQuery(global.location.search || '');
175
+ var query = parseQuery(global.location.search || '');
159
176
  if (query.grep) {
160
177
  mocha.grep(query.grep);
161
178
  }
@@ -174,7 +191,7 @@ mocha.run = function(fn) {
174
191
  document.getElementById('mocha') &&
175
192
  options.noHighlighting !== true
176
193
  ) {
177
- Mocha.utils.highlightTags('code');
194
+ highlightTags('code');
178
195
  }
179
196
  if (fn) {
180
197
  fn(err);
@@ -193,10 +210,10 @@ Mocha.process = process;
193
210
  * Expose mocha.
194
211
  */
195
212
 
196
- global.Mocha = Mocha;
197
- global.mocha = mocha;
213
+ mocha.Mocha = Mocha;
214
+ mocha.mocha = mocha;
198
215
 
199
216
  // this allows test/acceptance/required-tokens.js to pass; thus,
200
217
  // you can now do `const describe = require('mocha').describe` in a
201
218
  // browser context (assuming browserification). should fix #880
202
- module.exports = global;
219
+ module.exports = Object.assign(mocha, global);
@@ -11,6 +11,7 @@
11
11
  var Date = global.Date;
12
12
  var setTimeout = global.setTimeout;
13
13
  var EVENT_RUN_END = require('../runner').constants.EVENT_RUN_END;
14
+ var isBrowser = require('../utils').isBrowser;
14
15
 
15
16
  /**
16
17
  * Checks if browser notification support exists.
@@ -25,7 +26,7 @@ var EVENT_RUN_END = require('../runner').constants.EVENT_RUN_END;
25
26
  exports.isCapable = function() {
26
27
  var hasNotificationSupport = 'Notification' in window;
27
28
  var hasPromiseSupport = typeof Promise === 'function';
28
- return process.browser && hasNotificationSupport && hasPromiseSupport;
29
+ return isBrowser() && hasNotificationSupport && hasPromiseSupport;
29
30
  };
30
31
 
31
32
  /**
@@ -0,0 +1,39 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Highlight the given string of `js`.
5
+ *
6
+ * @private
7
+ * @param {string} js
8
+ * @return {string}
9
+ */
10
+ function highlight(js) {
11
+ return js
12
+ .replace(/</g, '&lt;')
13
+ .replace(/>/g, '&gt;')
14
+ .replace(/\/\/(.*)/gm, '<span class="comment">//$1</span>')
15
+ .replace(/('.*?')/gm, '<span class="string">$1</span>')
16
+ .replace(/(\d+\.\d+)/gm, '<span class="number">$1</span>')
17
+ .replace(/(\d+)/gm, '<span class="number">$1</span>')
18
+ .replace(
19
+ /\bnew[ \t]+(\w+)/gm,
20
+ '<span class="keyword">new</span> <span class="init">$1</span>'
21
+ )
22
+ .replace(
23
+ /\b(function|new|throw|return|var|if|else)\b/gm,
24
+ '<span class="keyword">$1</span>'
25
+ );
26
+ }
27
+
28
+ /**
29
+ * Highlight the contents of tag `name`.
30
+ *
31
+ * @private
32
+ * @param {string} name
33
+ */
34
+ module.exports = function highlightTags(name) {
35
+ var code = document.getElementById('mocha').getElementsByTagName(name);
36
+ for (var i = 0, len = code.length; i < len; ++i) {
37
+ code[i].innerHTML = highlight(code[i].innerHTML);
38
+ }
39
+ };
@@ -0,0 +1,24 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Parse the given `qs`.
5
+ *
6
+ * @private
7
+ * @param {string} qs
8
+ * @return {Object<string, string>}
9
+ */
10
+ module.exports = function parseQuery(qs) {
11
+ return qs
12
+ .replace('?', '')
13
+ .split('&')
14
+ .reduce(function(obj, pair) {
15
+ var i = pair.indexOf('=');
16
+ var key = pair.slice(0, i);
17
+ var val = pair.slice(++i);
18
+
19
+ // Due to how the URLSearchParams API treats spaces
20
+ obj[key] = decodeURIComponent(val.replace(/\+/g, '%20'));
21
+
22
+ return obj;
23
+ }, {});
24
+ };
@@ -1,5 +1,9 @@
1
1
  'use strict';
2
2
 
3
+ /**
4
+ @module browser/Progress
5
+ */
6
+
3
7
  /**
4
8
  * Expose `Progress`.
5
9
  */
@@ -1,16 +1,18 @@
1
1
  <!DOCTYPE html>
2
2
  <html lang="en">
3
3
  <head>
4
- <meta charset="utf-8">
4
+ <meta charset="utf-8" />
5
5
  <title>Mocha</title>
6
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
7
- <link rel="stylesheet" href="mocha.css">
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
+ <link rel="stylesheet" href="mocha.css" />
8
8
  </head>
9
9
  <body>
10
10
  <div id="mocha"></div>
11
11
  <script src="mocha.js"></script>
12
- <script>mocha.setup('bdd');</script>
13
- <script src="tests.js"></script>
12
+ <script>
13
+ mocha.setup('bdd');
14
+ </script>
15
+ <script src="tests.spec.js"></script>
14
16
  <script>
15
17
  mocha.run();
16
18
  </script>
package/lib/cli/cli.js CHANGED
@@ -49,10 +49,10 @@ exports.main = (argv = process.argv.slice(2)) => {
49
49
  'Commands:': 'Commands'
50
50
  })
51
51
  .fail((msg, err, yargs) => {
52
- debug(err);
52
+ debug('caught error sometime before command handler: %O', err);
53
53
  yargs.showHelp();
54
54
  console.error(`\n${symbols.error} ${ansi.red('ERROR:')} ${msg}`);
55
- process.exit(1);
55
+ process.exitCode = 1;
56
56
  })
57
57
  .help('help', 'Show usage information & exit')
58
58
  .alias('help', 'h')
@@ -4,8 +4,8 @@ const path = require('path');
4
4
  const ansi = require('ansi-colors');
5
5
  const debug = require('debug')('mocha:cli:run:helpers');
6
6
  const minimatch = require('minimatch');
7
- const utils = require('../utils');
8
7
  const {NO_FILES_MATCH_PATTERN} = require('../errors').constants;
8
+ const lookupFiles = require('./lookup-files');
9
9
 
10
10
  /**
11
11
  * Exports a function that collects test files from CLI parameters.
@@ -17,13 +17,7 @@ const {NO_FILES_MATCH_PATTERN} = require('../errors').constants;
17
17
 
18
18
  /**
19
19
  * Smash together an array of test files in the correct order
20
- * @param {Object} opts - Options
21
- * @param {string[]} opts.extension - File extensions to use
22
- * @param {string[]} opts.spec - Files, dirs, globs to run
23
- * @param {string[]} opts.ignore - Files, dirs, globs to ignore
24
- * @param {string[]} opts.file - List of additional files to include
25
- * @param {boolean} opts.recursive - Find files recursively
26
- * @param {boolean} opts.sort - Sort test files
20
+ * @param {FileCollectionOptions} [opts] - Options
27
21
  * @returns {string[]} List of files to test
28
22
  * @private
29
23
  */
@@ -33,7 +27,7 @@ module.exports = ({ignore, extension, file, recursive, sort, spec} = {}) => {
33
27
  spec.forEach(arg => {
34
28
  let newFiles;
35
29
  try {
36
- newFiles = utils.lookupFiles(arg, extension, recursive);
30
+ newFiles = lookupFiles(arg, extension, recursive);
37
31
  } catch (err) {
38
32
  if (err.code === NO_FILES_MATCH_PATTERN) {
39
33
  unmatched.push({message: err.message, pattern: err.pattern});
@@ -84,3 +78,15 @@ module.exports = ({ignore, extension, file, recursive, sort, spec} = {}) => {
84
78
 
85
79
  return files;
86
80
  };
81
+
82
+ /**
83
+ * An object to configure how Mocha gathers test files
84
+ * @private
85
+ * @typedef {Object} FileCollectionOptions
86
+ * @property {string[]} extension - File extensions to use
87
+ * @property {string[]} spec - Files, dirs, globs to run
88
+ * @property {string[]} ignore - Files, dirs, globs to ignore
89
+ * @property {string[]} file - List of additional files to include
90
+ * @property {boolean} recursive - Find files recursively
91
+ * @property {boolean} sort - Sort test files
92
+ */
package/lib/cli/config.js CHANGED
@@ -2,7 +2,6 @@
2
2
 
3
3
  /**
4
4
  * Responsible for loading / finding Mocha's "rc" files.
5
- * This doesn't have anything to do with `mocha.opts`.
6
5
  *
7
6
  * @private
8
7
  * @module
package/lib/cli/init.js CHANGED
@@ -9,7 +9,6 @@
9
9
 
10
10
  const fs = require('fs');
11
11
  const path = require('path');
12
- const mkdirp = require('mkdirp');
13
12
 
14
13
  exports.command = 'init <path>';
15
14
 
@@ -24,7 +23,7 @@ exports.builder = yargs =>
24
23
  exports.handler = argv => {
25
24
  const destdir = argv.path;
26
25
  const srcdir = path.join(__dirname, '..', '..');
27
- mkdirp.sync(destdir);
26
+ fs.mkdirSync(destdir, {recursive: true});
28
27
  const css = fs.readFileSync(path.join(srcdir, 'mocha.css'));
29
28
  const js = fs.readFileSync(path.join(srcdir, 'mocha.js'));
30
29
  const tmpl = fs.readFileSync(
@@ -0,0 +1,145 @@
1
+ 'use strict';
2
+
3
+ var fs = require('fs');
4
+ var path = require('path');
5
+ var glob = require('glob');
6
+ var {format} = require('util');
7
+ var errors = require('../errors');
8
+ var createNoFilesMatchPatternError = errors.createNoFilesMatchPatternError;
9
+ var createMissingArgumentError = errors.createMissingArgumentError;
10
+ var {sQuote, dQuote} = require('../utils');
11
+
12
+ /**
13
+ * Determines if pathname would be a "hidden" file (or directory) on UN*X.
14
+ *
15
+ * @description
16
+ * On UN*X, pathnames beginning with a full stop (aka dot) are hidden during
17
+ * typical usage. Dotfiles, plain-text configuration files, are prime examples.
18
+ *
19
+ * @see {@link http://xahlee.info/UnixResource_dir/writ/unix_origin_of_dot_filename.html|Origin of Dot File Names}
20
+ *
21
+ * @private
22
+ * @param {string} pathname - Pathname to check for match.
23
+ * @return {boolean} whether pathname would be considered a hidden file.
24
+ * @example
25
+ * isHiddenOnUnix('.profile'); // => true
26
+ */
27
+ function isHiddenOnUnix(pathname) {
28
+ return path.basename(pathname)[0] === '.';
29
+ }
30
+
31
+ /**
32
+ * Determines if pathname has a matching file extension.
33
+ *
34
+ * @private
35
+ * @param {string} pathname - Pathname to check for match.
36
+ * @param {string[]} exts - List of file extensions (sans period).
37
+ * @return {boolean} whether file extension matches.
38
+ * @example
39
+ * hasMatchingExtname('foo.html', ['js', 'css']); // => false
40
+ */
41
+ function hasMatchingExtname(pathname, exts) {
42
+ var suffix = path.extname(pathname).slice(1);
43
+ return exts.some(function(element) {
44
+ return suffix === element;
45
+ });
46
+ }
47
+
48
+ /**
49
+ * Lookup file names at the given `path`.
50
+ *
51
+ * @description
52
+ * Filenames are returned in _traversal_ order by the OS/filesystem.
53
+ * **Make no assumption that the names will be sorted in any fashion.**
54
+ *
55
+ * @public
56
+ * @memberof Mocha.utils
57
+ * @param {string} filepath - Base path to start searching from.
58
+ * @param {string[]} [extensions=[]] - File extensions to look for.
59
+ * @param {boolean} [recursive=false] - Whether to recurse into subdirectories.
60
+ * @return {string[]} An array of paths.
61
+ * @throws {Error} if no files match pattern.
62
+ * @throws {TypeError} if `filepath` is directory and `extensions` not provided.
63
+ */
64
+ module.exports = function lookupFiles(filepath, extensions, recursive) {
65
+ extensions = extensions || [];
66
+ recursive = recursive || false;
67
+ var files = [];
68
+ var stat;
69
+
70
+ if (!fs.existsSync(filepath)) {
71
+ var pattern;
72
+ if (glob.hasMagic(filepath)) {
73
+ // Handle glob as is without extensions
74
+ pattern = filepath;
75
+ } else {
76
+ // glob pattern e.g. 'filepath+(.js|.ts)'
77
+ var strExtensions = extensions
78
+ .map(function(v) {
79
+ return '.' + v;
80
+ })
81
+ .join('|');
82
+ pattern = filepath + '+(' + strExtensions + ')';
83
+ }
84
+ files = glob.sync(pattern, {nodir: true});
85
+ if (!files.length) {
86
+ throw createNoFilesMatchPatternError(
87
+ 'Cannot find any files matching pattern ' + dQuote(filepath),
88
+ filepath
89
+ );
90
+ }
91
+ return files;
92
+ }
93
+
94
+ // Handle file
95
+ try {
96
+ stat = fs.statSync(filepath);
97
+ if (stat.isFile()) {
98
+ return filepath;
99
+ }
100
+ } catch (err) {
101
+ // ignore error
102
+ return;
103
+ }
104
+
105
+ // Handle directory
106
+ fs.readdirSync(filepath).forEach(function(dirent) {
107
+ var pathname = path.join(filepath, dirent);
108
+ var stat;
109
+
110
+ try {
111
+ stat = fs.statSync(pathname);
112
+ if (stat.isDirectory()) {
113
+ if (recursive) {
114
+ files = files.concat(lookupFiles(pathname, extensions, recursive));
115
+ }
116
+ return;
117
+ }
118
+ } catch (err) {
119
+ // ignore error
120
+ return;
121
+ }
122
+ if (!extensions.length) {
123
+ throw createMissingArgumentError(
124
+ format(
125
+ 'Argument %s required when argument %s is a directory',
126
+ sQuote('extensions'),
127
+ sQuote('filepath')
128
+ ),
129
+ 'extensions',
130
+ 'array'
131
+ );
132
+ }
133
+
134
+ if (
135
+ !stat.isFile() ||
136
+ !hasMatchingExtname(pathname, extensions) ||
137
+ isHiddenOnUnix(pathname)
138
+ ) {
139
+ return;
140
+ }
141
+ files.push(pathname);
142
+ });
143
+
144
+ return files;
145
+ };
@@ -6,7 +6,7 @@
6
6
  * @module
7
7
  */
8
8
 
9
- const nodeFlags = require('node-environment-flags');
9
+ const nodeFlags = process.allowedNodeEnvironmentFlags;
10
10
  const unparse = require('yargs-unparser');
11
11
 
12
12
  /**
@@ -48,7 +48,7 @@ exports.isNodeFlag = (flag, bareword = true) => {
48
48
  // check actual node flags from `process.allowedNodeEnvironmentFlags`,
49
49
  // then historical support for various V8 and non-`NODE_OPTIONS` flags
50
50
  // and also any V8 flags with `--v8-` prefix
51
- (nodeFlags.has(flag) ||
51
+ ((nodeFlags && nodeFlags.has(flag)) ||
52
52
  debugFlags.has(flag) ||
53
53
  /(?:preserve-symlinks(?:-main)?|harmony(?:[_-]|$)|(?:trace[_-].+$)|gc(?:[_-]global)?$|es[_-]staging$|use[_-]strict$|v8[_-](?!options).+?$)/.test(
54
54
  flag