mocha 7.1.1 → 8.0.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/CHANGELOG.md CHANGED
@@ -1,3 +1,105 @@
1
+ # 8.0.1 / 2020-06-10
2
+
3
+ The obligatory patch after a major.
4
+
5
+ ## :bug: Fixes
6
+
7
+ - [#4328]: Fix `--parallel` when combined with `--watch` ([**@boneskull**](https://github.com/boneskull))
8
+
9
+ # 8.0.0 / 2020-06-10
10
+
11
+ In this major release, Mocha adds the ability to _run tests in parallel_. Better late than never! Please note the **breaking changes** detailed below.
12
+
13
+ Let's welcome [**@giltayar**](https://github.com/giltayar) and [**@nicojs**](https://github.com/nicojs) to the maintenance team!
14
+
15
+ ## :boom: Breaking Changes
16
+
17
+ - [#4164](https://github.com/mochajs/mocha/issues/4164): **Mocha v8.0.0 now requires Node.js v10.0.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))
18
+
19
+ - [#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))
20
+
21
+ :sparkles: **WORKAROUND:** Replace `mocha.opts` with a [configuration file](https://mochajs.org/#configuring-mocha-nodejs).
22
+
23
+ - [#4260](https://github.com/mochajs/mocha/issues/4260): Remove `enableTimeout()` (`this.enableTimeout()`) from the context object ([**@craigtaub**](https://github.com/craigtaub))
24
+
25
+ :sparkles: **WORKAROUND:** Replace usage of `this.enableTimeout(false)` in your tests with `this.timeout(0)`.
26
+
27
+ - [#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))
28
+
29
+ :sparkles: **WORKAROUND**: Use an array instead (e.g., `"spec": "foo.js,bar.js"` becomes `"spec": ["foo.js", "bar.js"]`).
30
+
31
+ - [#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))
32
+
33
+ - [#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))
34
+
35
+ - [#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))
36
+
37
+ - [#4178](https://github.com/mochajs/mocha/issues/4178): Remove previously soft-deprecated APIs ([**@wnghdcjfe**](https://github.com/wnghdcjfe)):
38
+ - `Mocha.prototype.ignoreLeaks()`
39
+ - `Mocha.prototype.useColors()`
40
+ - `Mocha.prototype.useInlineDiffs()`
41
+ - `Mocha.prototype.hideDiff()`
42
+
43
+ ## :tada: Enhancements
44
+
45
+ - [#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))
46
+
47
+ :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_
48
+
49
+ - [#4304](https://github.com/mochajs/mocha/issues/4304): `--require` now works with ES modules ([**@JacobLey**](https://github.com/JacobLey))
50
+
51
+ - [#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))
52
+
53
+ ## :book: Documentation
54
+
55
+ - [#4246](https://github.com/mochajs/mocha/issues/4246): Add documentation for parallel mode and Root Hook plugins ([**@boneskull**](https://github.com/boneskull))
56
+
57
+ ## :bug: Fixes
58
+
59
+ (All bug fixes in Mocha v8.0.0 are also breaking changes, and are listed above)
60
+
61
+ # 7.2.0 / 2020-05-22
62
+
63
+ ## :tada: Enhancements
64
+
65
+ - [#4234](https://github.com/mochajs/mocha/issues/4234): Add ability to run tests in a mocha instance multiple times ([**@nicojs**](https://github.com/nicojs))
66
+ - [#4219](https://github.com/mochajs/mocha/issues/4219): Exposing filename in JSON, doc, and json-stream reporters ([**@Daniel0113**](https://github.com/Daniel0113))
67
+ - [#4244](https://github.com/mochajs/mocha/issues/4244): Add Root Hook Plugins ([**@boneskull**](https://github.com/boneskull))
68
+
69
+ ## :bug: Fixes
70
+
71
+ - [#4258](https://github.com/mochajs/mocha/issues/4258): Fix missing dot in name of configuration file ([**@sonicdoe**](https://github.com/sonicdoe))
72
+ - [#4194](https://github.com/mochajs/mocha/issues/4194): Check if module.paths really exists ([**@ematipico**](https://github.com/ematipico))
73
+ - [#4256](https://github.com/mochajs/mocha/issues/4256): `--forbid-only` does not recognize `it.only` when `before` crashes ([**@arvidOtt**](https://github.com/arvidOtt))
74
+ - [#4152](https://github.com/mochajs/mocha/issues/4152): Bug with multiple async done() calls ([**@boneskull**](https://github.com/boneskull))
75
+ - [#4275](https://github.com/mochajs/mocha/issues/4275): Improper warnings for invalid reporters ([**@boneskull**](https://github.com/boneskull))
76
+ - [#4288](https://github.com/mochajs/mocha/issues/4288): Broken hook.spec.js test for IE11 ([**@boneskull**](https://github.com/boneskull))
77
+
78
+ ## :book: Documentation
79
+
80
+ - [#4081](https://github.com/mochajs/mocha/issues/4081): Insufficient white space for API docs in view on mobile ([**@HyunSangHan**](https://github.com/HyunSangHan))
81
+ - [#4255](https://github.com/mochajs/mocha/issues/4255): Update mocha-docdash for UI fixes on API docs ([**@craigtaub**](https://github.com/craigtaub))
82
+ - [#4235](https://github.com/mochajs/mocha/issues/4235): Enable emoji on website; enable normal ul elements ([**@boneskull**](https://github.com/boneskull))
83
+ - [#4272](https://github.com/mochajs/mocha/issues/4272): Fetch sponsors at build time, show ALL non-skeevy sponsors ([**@boneskull**](https://github.com/boneskull))
84
+
85
+ ## :nut_and_bolt: Other
86
+
87
+ - [#4249](https://github.com/mochajs/mocha/issues/4249): Refactoring improving encapsulation ([**@arvidOtt**](https://github.com/arvidOtt))
88
+ - [#4242](https://github.com/mochajs/mocha/issues/4242): CI add job names, add Node.js v14 to matrix ([**@boneskull**](https://github.com/boneskull))
89
+ - [#4237](https://github.com/mochajs/mocha/issues/4237): Refactor validatePlugins to throw coded errors ([**@boneskull**](https://github.com/boneskull))
90
+ - [#4236](https://github.com/mochajs/mocha/issues/4236): Better debug output ([**@boneskull**](https://github.com/boneskull))
91
+
92
+ # 7.1.2 / 2020-04-26
93
+
94
+ ## :nut_and_bolt: Other
95
+
96
+ - [#4251](https://github.com/mochajs/mocha/issues/4251): Prevent karma-mocha from stalling ([**@juergba**](https://github.com/juergba))
97
+ - [#4222](https://github.com/mochajs/mocha/issues/4222): Update dependency mkdirp to v0.5.5 ([**@outsideris**](https://github.com/outsideris))
98
+
99
+ ## :book: Documentation
100
+
101
+ - [#4208](https://github.com/mochajs/mocha/issues/4208): Add Wallaby logo to site ([**@boneskull**](https://github.com/boneskull))
102
+
1
103
  # 7.1.1 / 2020-03-18
2
104
 
3
105
  ## :lock: Security Fixes
@@ -117,6 +219,12 @@ These are _soft_-deprecated, and will emit a warning upon use. Support will be r
117
219
  - [#4089](https://github.com/mochajs/mocha/issues/4089): Add funding information to `package.json` ([**@Munter**](https://github.com/Munter))
118
220
  - [#4077](https://github.com/mochajs/mocha/issues/4077): Improve integration tests ([**@soobing**](https://github.com/soobing))
119
221
 
222
+ # 6.2.3 / 2020-03-25
223
+
224
+ ## :lock: Security Fixes
225
+
226
+ - [848d6fb8](https://github.com/mochajs/mocha/commit/848d6fb8feef659564b296db457312d38176910d): Update dependencies mkdirp, yargs-parser and yargs ([**@juergba**](https://github.com/juergba))
227
+
120
228
  # 6.2.2 / 2019-10-18
121
229
 
122
230
  ## :bug: Fixes
@@ -535,7 +643,7 @@ This release fixes a class of tests which report as _false positives_. **Certain
535
643
 
536
644
  - [#3226](https://github.com/mochajs/mocha/issues/3226): Do not swallow errors that are thrown asynchronously from passing tests ([@boneskull](https://github.com/boneskull)). Example:
537
645
 
538
- \```js
646
+ \`\`\`js
539
647
  it('should actually fail, sorry!', function (done) {
540
648
  // passing assertion
541
649
  assert(true === true);
@@ -548,7 +656,7 @@ This release fixes a class of tests which report as _false positives_. **Certain
548
656
  throw new Error('chaos!');
549
657
  }, 100);
550
658
  });
551
- \```
659
+ \`\`\`
552
660
 
553
661
  Previously to this version, Mocha would have _silently swallowed_ the `chaos!` exception, and you wouldn't know. Well, _now you know_. Mocha cannot recover from this gracefully, so it will exit with a nonzero code.
554
662
 
package/bin/mocha CHANGED
@@ -34,7 +34,7 @@ debug('loaded opts', opts);
34
34
  */
35
35
  const disableTimeouts = value => {
36
36
  if (impliesNoTimeouts(value)) {
37
- debug(`option "${value}" disabled timeouts`);
37
+ debug('option %s disabled timeouts', value);
38
38
  mochaArgs.timeout = 0;
39
39
  delete mochaArgs.timeouts;
40
40
  delete mochaArgs.t;
@@ -108,7 +108,11 @@ if (Object.keys(nodeArgs).length) {
108
108
  unparse(mochaArgs, {alias: aliases})
109
109
  );
110
110
 
111
- debug(`exec ${process.execPath} w/ args:`, args);
111
+ debug(
112
+ 'forking child process via command: %s %s',
113
+ process.execPath,
114
+ args.join(' ')
115
+ );
112
116
 
113
117
  const proc = spawn(process.execPath, args, {
114
118
  stdio: 'inherit'
@@ -126,9 +130,25 @@ if (Object.keys(nodeArgs).length) {
126
130
 
127
131
  // terminate children.
128
132
  process.on('SIGINT', () => {
129
- proc.kill('SIGINT'); // calls runner.abort()
130
- 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
+ }
131
150
  });
132
151
  } else {
152
+ debug('running Mocha in-process');
133
153
  require('../lib/cli/cli').main(unparse(mochaArgs, {alias: aliases}));
134
154
  }
package/browser-entry.js CHANGED
@@ -52,6 +52,17 @@ process.removeListener = function(e, fn) {
52
52
  }
53
53
  };
54
54
 
55
+ /**
56
+ * Implements listenerCount for 'uncaughtException'.
57
+ */
58
+
59
+ process.listenerCount = function(name) {
60
+ if (name === 'uncaughtException') {
61
+ return uncaughtExceptionHandlers.length;
62
+ }
63
+ return 0;
64
+ };
65
+
55
66
  /**
56
67
  * Implements uncaughtException listener.
57
68
  */
@@ -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
  /**
package/lib/cli/cli.js CHANGED
@@ -19,6 +19,7 @@ const {loadOptions, YARGS_PARSER_CONFIG} = require('./options');
19
19
  const commands = require('./commands');
20
20
  const ansi = require('ansi-colors');
21
21
  const {repository, homepage, version, gitter} = require('../../package.json');
22
+ const {cwd} = require('../utils');
22
23
 
23
24
  /**
24
25
  * - Accepts an `Array` of arguments
@@ -30,7 +31,9 @@ const {repository, homepage, version, gitter} = require('../../package.json');
30
31
  exports.main = (argv = process.argv.slice(2)) => {
31
32
  debug('entered main with raw args', argv);
32
33
  // ensure we can require() from current working directory
33
- module.paths.push(process.cwd(), path.resolve('node_modules'));
34
+ if (typeof module.paths !== 'undefined') {
35
+ module.paths.push(cwd(), path.resolve('node_modules'));
36
+ }
34
37
 
35
38
  Error.stackTraceLimit = Infinity; // configurable via --stack-trace-limit?
36
39
 
@@ -46,10 +49,10 @@ exports.main = (argv = process.argv.slice(2)) => {
46
49
  'Commands:': 'Commands'
47
50
  })
48
51
  .fail((msg, err, yargs) => {
49
- debug(err);
52
+ debug('caught error sometime before command handler: %O', err);
50
53
  yargs.showHelp();
51
54
  console.error(`\n${symbols.error} ${ansi.red('ERROR:')} ${msg}`);
52
- process.exit(1);
55
+ yargs.exit(1);
53
56
  })
54
57
  .help('help', 'Show usage information & exit')
55
58
  .alias('help', 'h')
@@ -5,6 +5,7 @@ const ansi = require('ansi-colors');
5
5
  const debug = require('debug')('mocha:cli:run:helpers');
6
6
  const minimatch = require('minimatch');
7
7
  const utils = require('../utils');
8
+ const {NO_FILES_MATCH_PATTERN} = require('../errors').constants;
8
9
 
9
10
  /**
10
11
  * Exports a function that collects test files from CLI parameters.
@@ -16,13 +17,7 @@ const utils = require('../utils');
16
17
 
17
18
  /**
18
19
  * Smash together an array of test files in the correct order
19
- * @param {Object} opts - Options
20
- * @param {string[]} opts.extension - File extensions to use
21
- * @param {string[]} opts.spec - Files, dirs, globs to run
22
- * @param {string[]} opts.ignore - Files, dirs, globs to ignore
23
- * @param {string[]} opts.file - List of additional files to include
24
- * @param {boolean} opts.recursive - Find files recursively
25
- * @param {boolean} opts.sort - Sort test files
20
+ * @param {FileCollectionOptions} [opts] - Options
26
21
  * @returns {string[]} List of files to test
27
22
  * @private
28
23
  */
@@ -34,7 +29,7 @@ module.exports = ({ignore, extension, file, recursive, sort, spec} = {}) => {
34
29
  try {
35
30
  newFiles = utils.lookupFiles(arg, extension, recursive);
36
31
  } catch (err) {
37
- if (err.code === 'ERR_MOCHA_NO_FILES_MATCH_PATTERN') {
32
+ if (err.code === NO_FILES_MATCH_PATTERN) {
38
33
  unmatched.push({message: err.message, pattern: err.pattern});
39
34
  return;
40
35
  }
@@ -83,3 +78,14 @@ module.exports = ({ignore, extension, file, recursive, sort, spec} = {}) => {
83
78
 
84
79
  return files;
85
80
  };
81
+
82
+ /**
83
+ * An object to configure how Mocha gathers test files
84
+ * @typedef {Object} FileCollectionOptions
85
+ * @property {string[]} extension - File extensions to use
86
+ * @property {string[]} spec - Files, dirs, globs to run
87
+ * @property {string[]} ignore - Files, dirs, globs to ignore
88
+ * @property {string[]} file - List of additional files to include
89
+ * @property {boolean} recursive - Find files recursively
90
+ * @property {boolean} sort - Sort test files
91
+ */
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
@@ -12,6 +11,7 @@ const fs = require('fs');
12
11
  const path = require('path');
13
12
  const debug = require('debug')('mocha:cli:config');
14
13
  const findUp = require('find-up');
14
+ const utils = require('../utils');
15
15
 
16
16
  /**
17
17
  * These are the valid config files, in order of precedence;
@@ -43,11 +43,11 @@ const parsers = (exports.parsers = {
43
43
  js: filepath => {
44
44
  const cwdFilepath = path.resolve(filepath);
45
45
  try {
46
- debug(`parsers: load using cwd-relative path: "${cwdFilepath}"`);
46
+ debug('parsers: load using cwd-relative path: "%s"', cwdFilepath);
47
47
  return require(cwdFilepath);
48
48
  } catch (err) {
49
49
  if (isModuleNotFoundError(err)) {
50
- debug(`parsers: retry load as module-relative path: "${filepath}"`);
50
+ debug('parsers: retry load as module-relative path: "%s"', filepath);
51
51
  return require(filepath);
52
52
  } else {
53
53
  throw err; // rethrow
@@ -70,7 +70,7 @@ const parsers = (exports.parsers = {
70
70
  */
71
71
  exports.loadConfig = filepath => {
72
72
  let config = {};
73
- debug(`loadConfig: "${filepath}"`);
73
+ debug('loadConfig: trying to parse config at %s', filepath);
74
74
 
75
75
  const ext = path.extname(filepath);
76
76
  try {
@@ -93,10 +93,10 @@ exports.loadConfig = filepath => {
93
93
  * @param {string} [cwd] - Current working directory
94
94
  * @returns {string|null} Filepath to config, if found
95
95
  */
96
- exports.findConfig = (cwd = process.cwd()) => {
96
+ exports.findConfig = (cwd = utils.cwd()) => {
97
97
  const filepath = findUp.sync(exports.CONFIG_FILES, {cwd});
98
98
  if (filepath) {
99
- debug(`findConfig: found "${filepath}"`);
99
+ debug('findConfig: found config file %s', filepath);
100
100
  }
101
101
  return filepath;
102
102
  };
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(
@@ -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
@@ -2,7 +2,7 @@
2
2
 
3
3
  /**
4
4
  * Main entry point for handling filesystem-based configuration,
5
- * whether that's `mocha.opts` or a config file or `package.json` or whatever.
5
+ * whether that's a config file or `package.json` or whatever.
6
6
  * @module
7
7
  */
8
8
 
@@ -15,7 +15,6 @@ const mocharc = require('../mocharc.json');
15
15
  const {list} = require('./run-helpers');
16
16
  const {loadConfig, findConfig} = require('./config');
17
17
  const findUp = require('find-up');
18
- const {deprecate} = require('../utils');
19
18
  const debug = require('debug')('mocha:cli:options');
20
19
  const {isNodeFlag} = require('./node-flags');
21
20
 
@@ -55,16 +54,19 @@ const configuration = Object.assign({}, YARGS_PARSER_CONFIG, {
55
54
 
56
55
  /**
57
56
  * This is a really fancy way to:
58
- * - ensure unique values for `array`-type options
59
- * - use its array's last element for `boolean`/`number`/`string`- options given multiple times
57
+ * - `array`-type options: ensure unique values and evtl. split comma-delimited lists
58
+ * - `boolean`/`number`/`string`- options: use last element when given multiple times
60
59
  * This is passed as the `coerce` option to `yargs-parser`
61
60
  * @private
62
61
  * @ignore
63
62
  */
63
+ const globOptions = ['spec', 'ignore'];
64
64
  const coerceOpts = Object.assign(
65
65
  types.array.reduce(
66
66
  (acc, arg) =>
67
- Object.assign(acc, {[arg]: v => Array.from(new Set(list(v)))}),
67
+ Object.assign(acc, {
68
+ [arg]: v => Array.from(new Set(globOptions.includes(arg) ? v : list(v)))
69
+ }),
68
70
  {}
69
71
  ),
70
72
  types.boolean
@@ -143,71 +145,6 @@ const parse = (args = [], defaultValues = {}, ...configObjects) => {
143
145
  return result.argv;
144
146
  };
145
147
 
146
- /**
147
- * - Replaces comments with empty strings
148
- * - Replaces escaped spaces (e.g., 'xxx\ yyy') with HTML space
149
- * - Splits on whitespace, creating array of substrings
150
- * - Filters empty string elements from array
151
- * - Replaces any HTML space with space
152
- * @summary Parses options read from run-control file.
153
- * @private
154
- * @param {string} content - Content read from run-control file.
155
- * @returns {string[]} cmdline options (and associated arguments)
156
- * @ignore
157
- */
158
- const parseMochaOpts = content =>
159
- content
160
- .replace(/^#.*$/gm, '')
161
- .replace(/\\\s/g, '%20')
162
- .split(/\s/)
163
- .filter(Boolean)
164
- .map(value => value.replace(/%20/g, ' '));
165
-
166
- /**
167
- * Given filepath in `args.opts`, attempt to load and parse a `mocha.opts` file.
168
- * @param {Object} [args] - Arguments object
169
- * @param {string|boolean} [args.opts] - Filepath to mocha.opts; defaults to whatever's in `mocharc.opts`, or `false` to skip
170
- * @returns {external:yargsParser.Arguments|void} If read, object containing parsed arguments
171
- * @memberof module:lib/cli/options
172
- * @see {@link /#mochaopts|mocha.opts}
173
- * @public
174
- */
175
- const loadMochaOpts = (args = {}) => {
176
- let result;
177
- let filepath = args.opts;
178
- // /dev/null is backwards compat
179
- if (filepath === false || filepath === '/dev/null') {
180
- return result;
181
- }
182
- filepath = filepath || mocharc.opts;
183
- result = {};
184
- let mochaOpts;
185
- try {
186
- mochaOpts = fs.readFileSync(filepath, 'utf8');
187
- debug(`read ${filepath}`);
188
- } catch (err) {
189
- if (args.opts) {
190
- throw new Error(`Unable to read ${filepath}: ${err}`);
191
- }
192
- // ignore otherwise. we tried
193
- debug(`No mocha.opts found at ${filepath}`);
194
- }
195
-
196
- // real args should override `mocha.opts` which should override defaults.
197
- // if there's an exception to catch here, I'm not sure what it is.
198
- // by attaching the `no-opts` arg, we avoid re-parsing of `mocha.opts`.
199
- if (mochaOpts) {
200
- deprecate(
201
- 'Configuration via mocha.opts is DEPRECATED and will be removed from a future version of Mocha. Use RC files or package.json instead.'
202
- );
203
- result = parse(parseMochaOpts(mochaOpts));
204
- debug(`${filepath} parsed succesfully`);
205
- }
206
- return result;
207
- };
208
-
209
- module.exports.loadMochaOpts = loadMochaOpts;
210
-
211
148
  /**
212
149
  * Given path to config file in `args.config`, attempt to load & parse config file.
213
150
  * @param {Object} [args] - Arguments object
@@ -244,16 +181,16 @@ const loadPkgRc = (args = {}) => {
244
181
  try {
245
182
  const pkg = JSON.parse(fs.readFileSync(filepath, 'utf8'));
246
183
  if (pkg.mocha) {
247
- debug(`'mocha' prop of package.json parsed:`, pkg.mocha);
184
+ debug('`mocha` prop of package.json parsed: %O', pkg.mocha);
248
185
  result = pkg.mocha;
249
186
  } else {
250
- debug(`no config found in ${filepath}`);
187
+ debug('no config found in %s', filepath);
251
188
  }
252
189
  } catch (err) {
253
190
  if (args.package) {
254
191
  throw new Error(`Unable to read/parse ${filepath}: ${err}`);
255
192
  }
256
- debug(`failed to read default package.json at ${filepath}; ignoring`);
193
+ debug('failed to read default package.json at %s; ignoring', filepath);
257
194
  }
258
195
  }
259
196
  return result;
@@ -267,11 +204,10 @@ module.exports.loadPkgRc = loadPkgRc;
267
204
  * 1. Command-line args
268
205
  * 2. RC file (`.mocharc.c?js`, `.mocharc.ya?ml`, `mocharc.json`)
269
206
  * 3. `mocha` prop of `package.json`
270
- * 4. `mocha.opts`
271
- * 5. default configuration (`lib/mocharc.json`)
207
+ * 4. default configuration (`lib/mocharc.json`)
272
208
  *
273
209
  * If a {@link module:lib/cli/one-and-dones.ONE_AND_DONE_ARGS "one-and-done" option} is present in the `argv` array, no external config files will be read.
274
- * @summary Parses options read from `mocha.opts`, `.mocharc.*` and `package.json`.
210
+ * @summary Parses options read from `.mocharc.*` and `package.json`.
275
211
  * @param {string|string[]} [argv] - Arguments to parse
276
212
  * @public
277
213
  * @memberof module:lib/cli/options
@@ -279,7 +215,7 @@ module.exports.loadPkgRc = loadPkgRc;
279
215
  */
280
216
  const loadOptions = (argv = []) => {
281
217
  let args = parse(argv);
282
- // short-circuit: look for a flag that would abort loading of mocha.opts
218
+ // short-circuit: look for a flag that would abort loading of options
283
219
  if (
284
220
  Array.from(ONE_AND_DONE_ARGS).reduce(
285
221
  (acc, arg) => acc || arg in args,
@@ -291,7 +227,6 @@ const loadOptions = (argv = []) => {
291
227
 
292
228
  const rcConfig = loadRc(args);
293
229
  const pkgConfig = loadPkgRc(args);
294
- const optsConfig = loadMochaOpts(args);
295
230
 
296
231
  if (rcConfig) {
297
232
  args.config = false;
@@ -301,19 +236,8 @@ const loadOptions = (argv = []) => {
301
236
  args.package = false;
302
237
  args._ = args._.concat(pkgConfig._ || []);
303
238
  }
304
- if (optsConfig) {
305
- args.opts = false;
306
- args._ = args._.concat(optsConfig._ || []);
307
- }
308
239
 
309
- args = parse(
310
- args._,
311
- mocharc,
312
- args,
313
- rcConfig || {},
314
- pkgConfig || {},
315
- optsConfig || {}
316
- );
240
+ args = parse(args._, mocharc, args, rcConfig || {}, pkgConfig || {});
317
241
 
318
242
  // recombine positional arguments and "spec"
319
243
  if (args.spec) {