mocha 11.7.4 → 11.7.6

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 (67) hide show
  1. package/bin/_mocha +2 -2
  2. package/bin/mocha.js +46 -44
  3. package/browser-entry.js +20 -20
  4. package/index.js +2 -2
  5. package/lib/browser/highlight-tags.js +6 -6
  6. package/lib/browser/parse-query.js +5 -5
  7. package/lib/browser/template.html +2 -2
  8. package/lib/cli/cli.js +32 -27
  9. package/lib/cli/collect-files.js +25 -25
  10. package/lib/cli/commands.js +4 -4
  11. package/lib/cli/config.js +26 -25
  12. package/lib/cli/index.js +2 -2
  13. package/lib/cli/init.js +19 -19
  14. package/lib/cli/lookup-files.js +20 -20
  15. package/lib/cli/node-flags.js +12 -12
  16. package/lib/cli/one-and-dones.js +12 -11
  17. package/lib/cli/options.js +49 -49
  18. package/lib/cli/run-helpers.js +52 -54
  19. package/lib/cli/run-option-metadata.js +75 -75
  20. package/lib/cli/run.js +164 -159
  21. package/lib/cli/watch-run.js +75 -75
  22. package/lib/context.js +1 -1
  23. package/lib/error-constants.js +17 -17
  24. package/lib/errors.js +26 -26
  25. package/lib/hook.js +9 -9
  26. package/lib/interfaces/bdd.js +8 -8
  27. package/lib/interfaces/common.js +12 -12
  28. package/lib/interfaces/exports.js +8 -8
  29. package/lib/interfaces/index.js +5 -5
  30. package/lib/interfaces/qunit.js +7 -7
  31. package/lib/interfaces/tdd.js +7 -7
  32. package/lib/mocha.js +97 -97
  33. package/lib/nodejs/buffered-worker-pool.js +30 -30
  34. package/lib/nodejs/esm-utils.js +24 -21
  35. package/lib/nodejs/file-unloader.js +2 -2
  36. package/lib/nodejs/parallel-buffered-runner.js +67 -67
  37. package/lib/nodejs/reporters/parallel-buffered.js +13 -10
  38. package/lib/nodejs/serializer.js +47 -47
  39. package/lib/nodejs/worker.js +38 -38
  40. package/lib/pending.js +1 -1
  41. package/lib/plugin-loader.js +48 -48
  42. package/lib/reporters/base.js +97 -94
  43. package/lib/reporters/doc.js +17 -17
  44. package/lib/reporters/dot.js +14 -14
  45. package/lib/reporters/html.js +73 -67
  46. package/lib/reporters/index.js +16 -16
  47. package/lib/reporters/json-stream.js +10 -10
  48. package/lib/reporters/json.js +16 -16
  49. package/lib/reporters/landing.js +20 -20
  50. package/lib/reporters/list.js +10 -10
  51. package/lib/reporters/markdown.js +21 -21
  52. package/lib/reporters/min.js +7 -7
  53. package/lib/reporters/nyan.js +35 -35
  54. package/lib/reporters/progress.js +14 -14
  55. package/lib/reporters/spec.js +15 -15
  56. package/lib/reporters/tap.js +26 -26
  57. package/lib/reporters/xunit.js +38 -34
  58. package/lib/runnable.js +41 -41
  59. package/lib/runner.js +105 -105
  60. package/lib/stats-collector.js +4 -4
  61. package/lib/suite.js +56 -46
  62. package/lib/test.js +10 -10
  63. package/lib/utils.js +122 -122
  64. package/mocha.css +68 -50
  65. package/mocha.js +826 -803
  66. package/mocha.js.map +1 -1
  67. package/package.json +8 -13
package/lib/cli/config.js CHANGED
@@ -1,4 +1,4 @@
1
- 'use strict';
1
+ "use strict";
2
2
 
3
3
  /**
4
4
  * Responsible for loading / finding Mocha's "rc" files.
@@ -7,12 +7,12 @@
7
7
  * @module
8
8
  */
9
9
 
10
- const fs = require('node:fs');
11
- const path = require('node:path');
12
- const debug = require('debug')('mocha:cli:config');
13
- const findUp = require('find-up');
14
- const {createUnparsableFileError} = require('../errors');
15
- const utils = require('../utils');
10
+ const fs = require("node:fs");
11
+ const path = require("node:path");
12
+ const debug = require("debug")("mocha:cli:config");
13
+ const findUp = require("find-up");
14
+ const { createUnparsableFileError } = require("../errors");
15
+ const utils = require("../utils");
16
16
 
17
17
  /**
18
18
  * These are the valid config files, in order of precedence;
@@ -22,12 +22,12 @@ const utils = require('../utils');
22
22
  * @private
23
23
  */
24
24
  exports.CONFIG_FILES = [
25
- '.mocharc.cjs',
26
- '.mocharc.js',
27
- '.mocharc.yaml',
28
- '.mocharc.yml',
29
- '.mocharc.jsonc',
30
- '.mocharc.json'
25
+ ".mocharc.cjs",
26
+ ".mocharc.js",
27
+ ".mocharc.yaml",
28
+ ".mocharc.yml",
29
+ ".mocharc.jsonc",
30
+ ".mocharc.json",
31
31
  ];
32
32
 
33
33
  /**
@@ -35,8 +35,9 @@ exports.CONFIG_FILES = [
35
35
  * returns an object (but could throw)
36
36
  */
37
37
  const parsers = (exports.parsers = {
38
- yaml: filepath => require('js-yaml').load(fs.readFileSync(filepath, 'utf8')),
39
- js: filepath => {
38
+ yaml: (filepath) =>
39
+ require("js-yaml").load(fs.readFileSync(filepath, "utf8")),
40
+ js: (filepath) => {
40
41
  let cwdFilepath;
41
42
  try {
42
43
  debug('parsers: load cwd-relative path: "%s"', path.resolve(filepath));
@@ -49,10 +50,10 @@ const parsers = (exports.parsers = {
49
50
  return require(filepath);
50
51
  }
51
52
  },
52
- json: filepath =>
53
+ json: (filepath) =>
53
54
  JSON.parse(
54
- require('strip-json-comments')(fs.readFileSync(filepath, 'utf8'))
55
- )
55
+ require("strip-json-comments")(fs.readFileSync(filepath, "utf8")),
56
+ ),
56
57
  });
57
58
 
58
59
  /**
@@ -63,15 +64,15 @@ const parsers = (exports.parsers = {
63
64
  * @param {string} filepath - Config file path to load
64
65
  * @returns {Object} Parsed config object
65
66
  */
66
- exports.loadConfig = filepath => {
67
+ exports.loadConfig = (filepath) => {
67
68
  let config = {};
68
- debug('loadConfig: trying to parse config at %s', filepath);
69
+ debug("loadConfig: trying to parse config at %s", filepath);
69
70
 
70
71
  const ext = path.extname(filepath);
71
72
  try {
72
- if (ext === '.yml' || ext === '.yaml') {
73
+ if (ext === ".yml" || ext === ".yaml") {
73
74
  config = parsers.yaml(filepath);
74
- } else if (ext === '.js' || ext === '.cjs') {
75
+ } else if (ext === ".js" || ext === ".cjs") {
75
76
  config = parsers.js(filepath);
76
77
  } else {
77
78
  config = parsers.json(filepath);
@@ -79,7 +80,7 @@ exports.loadConfig = filepath => {
79
80
  } catch (err) {
80
81
  throw createUnparsableFileError(
81
82
  `Unable to read/parse ${filepath}: ${err}`,
82
- filepath
83
+ filepath,
83
84
  );
84
85
  }
85
86
  return config;
@@ -92,9 +93,9 @@ exports.loadConfig = filepath => {
92
93
  * @returns {string|null} Filepath to config, if found
93
94
  */
94
95
  exports.findConfig = (cwd = utils.cwd()) => {
95
- const filepath = findUp.sync(exports.CONFIG_FILES, {cwd});
96
+ const filepath = findUp.sync(exports.CONFIG_FILES, { cwd });
96
97
  if (filepath) {
97
- debug('findConfig: found config file %s', filepath);
98
+ debug("findConfig: found config file %s", filepath);
98
99
  }
99
100
  return filepath;
100
101
  };
package/lib/cli/index.js CHANGED
@@ -1,3 +1,3 @@
1
- 'use strict';
1
+ "use strict";
2
2
 
3
- module.exports = require('./cli');
3
+ module.exports = require("./cli");
package/lib/cli/init.js CHANGED
@@ -1,4 +1,4 @@
1
- 'use strict';
1
+ "use strict";
2
2
 
3
3
  /**
4
4
  * Command module for "init" command
@@ -7,30 +7,30 @@
7
7
  * @module
8
8
  */
9
9
 
10
- const fs = require('node:fs');
11
- const path = require('node:path');
10
+ const fs = require("node:fs");
11
+ const path = require("node:path");
12
12
 
13
- exports.command = 'init <path>';
13
+ exports.command = "init <path>";
14
14
 
15
- exports.description = 'create a client-side Mocha setup at <path>';
15
+ exports.description = "create a client-side Mocha setup at <path>";
16
16
 
17
- exports.builder = yargs =>
18
- yargs.positional('path', {
19
- type: 'string',
20
- normalize: true
17
+ exports.builder = (yargs) =>
18
+ yargs.positional("path", {
19
+ type: "string",
20
+ normalize: true,
21
21
  });
22
22
 
23
- exports.handler = argv => {
23
+ exports.handler = (argv) => {
24
24
  const destdir = argv.path;
25
- const srcdir = path.join(__dirname, '..', '..');
26
- fs.mkdirSync(destdir, {recursive: true});
27
- const css = fs.readFileSync(path.join(srcdir, 'mocha.css'));
28
- const js = fs.readFileSync(path.join(srcdir, 'mocha.js'));
25
+ const srcdir = path.join(__dirname, "..", "..");
26
+ fs.mkdirSync(destdir, { recursive: true });
27
+ const css = fs.readFileSync(path.join(srcdir, "mocha.css"));
28
+ const js = fs.readFileSync(path.join(srcdir, "mocha.js"));
29
29
  const tmpl = fs.readFileSync(
30
- path.join(srcdir, 'lib', 'browser', 'template.html')
30
+ path.join(srcdir, "lib", "browser", "template.html"),
31
31
  );
32
- fs.writeFileSync(path.join(destdir, 'mocha.css'), css);
33
- fs.writeFileSync(path.join(destdir, 'mocha.js'), js);
34
- fs.writeFileSync(path.join(destdir, 'tests.spec.js'), '');
35
- fs.writeFileSync(path.join(destdir, 'index.html'), tmpl);
32
+ fs.writeFileSync(path.join(destdir, "mocha.css"), css);
33
+ fs.writeFileSync(path.join(destdir, "mocha.js"), js);
34
+ fs.writeFileSync(path.join(destdir, "tests.spec.js"), "");
35
+ fs.writeFileSync(path.join(destdir, "index.html"), tmpl);
36
36
  };
@@ -1,17 +1,17 @@
1
- 'use strict';
1
+ "use strict";
2
2
  /**
3
3
  * Contains `lookupFiles`, which takes some globs/dirs/options and returns a list of files.
4
4
  * @module
5
5
  * @private
6
6
  */
7
7
 
8
- var fs = require('node:fs');
9
- var path = require('node:path');
10
- var glob = require('glob');
11
- var errors = require('../errors');
8
+ var fs = require("node:fs");
9
+ var path = require("node:path");
10
+ var glob = require("glob");
11
+ var errors = require("../errors");
12
12
  var createNoFilesMatchPatternError = errors.createNoFilesMatchPatternError;
13
13
  var createMissingArgumentError = errors.createMissingArgumentError;
14
- const debug = require('debug')('mocha:cli:lookup-files');
14
+ const debug = require("debug")("mocha:cli:lookup-files");
15
15
 
16
16
  /**
17
17
  * Determines if pathname would be a "hidden" file (or directory) on UN*X.
@@ -28,7 +28,7 @@ const debug = require('debug')('mocha:cli:lookup-files');
28
28
  * @example
29
29
  * isHiddenOnUnix('.profile'); // => true
30
30
  */
31
- const isHiddenOnUnix = pathname => path.basename(pathname).startsWith('.');
31
+ const isHiddenOnUnix = (pathname) => path.basename(pathname).startsWith(".");
32
32
 
33
33
  /**
34
34
  * Determines if pathname has a matching file extension.
@@ -46,8 +46,8 @@ const isHiddenOnUnix = pathname => path.basename(pathname).startsWith('.');
46
46
  */
47
47
  const hasMatchingExtname = (pathname, exts = []) =>
48
48
  exts
49
- .map(ext => (ext.startsWith('.') ? ext : `.${ext}`))
50
- .some(ext => pathname.endsWith(ext));
49
+ .map((ext) => (ext.startsWith(".") ? ext : `.${ext}`))
50
+ .some((ext) => pathname.endsWith(ext));
51
51
 
52
52
  /**
53
53
  * Lookup file names at the given `path`.
@@ -68,39 +68,39 @@ const hasMatchingExtname = (pathname, exts = []) =>
68
68
  module.exports = function lookupFiles(
69
69
  filepath,
70
70
  extensions = [],
71
- recursive = false
71
+ recursive = false,
72
72
  ) {
73
73
  const files = [];
74
74
  let stat;
75
75
 
76
76
  if (!fs.existsSync(filepath)) {
77
77
  let pattern;
78
- if (glob.hasMagic(filepath, {windowsPathsNoEscape: true})) {
78
+ if (glob.hasMagic(filepath, { windowsPathsNoEscape: true })) {
79
79
  // Handle glob as is without extensions
80
80
  pattern = filepath;
81
81
  } else {
82
82
  // glob pattern e.g. 'filepath+(.js|.ts)'
83
83
  const strExtensions = extensions
84
- .map(ext => (ext.startsWith('.') ? ext : `.${ext}`))
85
- .join('|');
84
+ .map((ext) => (ext.startsWith(".") ? ext : `.${ext}`))
85
+ .join("|");
86
86
  pattern = `${filepath}+(${strExtensions})`;
87
- debug('looking for files using glob pattern: %s', pattern);
87
+ debug("looking for files using glob pattern: %s", pattern);
88
88
  }
89
89
  files.push(
90
90
  ...glob
91
91
  .sync(pattern, {
92
92
  nodir: true,
93
- windowsPathsNoEscape: true
93
+ windowsPathsNoEscape: true,
94
94
  })
95
95
  // glob@8 and earlier sorted results in en; glob@9 depends on OS sorting.
96
96
  // This preserves the older glob behavior.
97
97
  // https://github.com/mochajs/mocha/pull/5250/files#r1840469747
98
- .sort((a, b) => a.localeCompare(b, 'en'))
98
+ .sort((a, b) => a.localeCompare(b, "en")),
99
99
  );
100
100
  if (!files.length) {
101
101
  throw createNoFilesMatchPatternError(
102
102
  `Cannot find any files matching pattern "${filepath}"`,
103
- filepath
103
+ filepath,
104
104
  );
105
105
  }
106
106
  return files;
@@ -118,7 +118,7 @@ module.exports = function lookupFiles(
118
118
  }
119
119
 
120
120
  // Handle directory
121
- fs.readdirSync(filepath).forEach(dirent => {
121
+ fs.readdirSync(filepath).forEach((dirent) => {
122
122
  const pathname = path.join(filepath, dirent);
123
123
  let stat;
124
124
 
@@ -136,8 +136,8 @@ module.exports = function lookupFiles(
136
136
  if (!extensions.length) {
137
137
  throw createMissingArgumentError(
138
138
  `Argument '${extensions}' required when argument '${filepath}' is a directory`,
139
- 'extensions',
140
- 'array'
139
+ "extensions",
140
+ "array",
141
141
  );
142
142
  }
143
143
 
@@ -1,4 +1,4 @@
1
- 'use strict';
1
+ "use strict";
2
2
 
3
3
  /**
4
4
  * Some settings and code related to Mocha's handling of Node.js/V8 flags.
@@ -7,15 +7,15 @@
7
7
  */
8
8
 
9
9
  const nodeFlags = process.allowedNodeEnvironmentFlags;
10
- const {isMochaFlag} = require('./run-option-metadata');
11
- const unparse = require('yargs-unparser');
10
+ const { isMochaFlag } = require("./run-option-metadata");
11
+ const unparse = require("yargs-unparser");
12
12
 
13
13
  /**
14
14
  * These flags are considered "debug" flags.
15
15
  * @see {@link impliesNoTimeouts}
16
16
  * @private
17
17
  */
18
- const debugFlags = new Set(['inspect', 'inspect-brk']);
18
+ const debugFlags = new Set(["inspect", "inspect-brk"]);
19
19
 
20
20
  /**
21
21
  * Mocha has historical support for various `node` and V8 flags which might not
@@ -41,7 +41,7 @@ exports.isNodeFlag = (flag, bareword = true) => {
41
41
  return false;
42
42
  }
43
43
  // strip the leading dashes to match against subsequent checks
44
- flag = flag.replace(/^--?/, '');
44
+ flag = flag.replace(/^--?/, "");
45
45
  }
46
46
  return (
47
47
  // check actual node flags from `process.allowedNodeEnvironmentFlags`,
@@ -50,7 +50,7 @@ exports.isNodeFlag = (flag, bareword = true) => {
50
50
  (!isMochaFlag(flag) && nodeFlags && nodeFlags.has(flag)) ||
51
51
  debugFlags.has(flag) ||
52
52
  /(?:preserve-symlinks(?:-main)?|harmony(?:[_-]|$)|(?:trace[_-].+$)|gc[_-]global$|es[_-]staging$|use[_-]strict$|v8[_-](?!options).+?$)/.test(
53
- flag
53
+ flag,
54
54
  )
55
55
  );
56
56
  };
@@ -62,7 +62,7 @@ exports.isNodeFlag = (flag, bareword = true) => {
62
62
  * @returns {boolean}
63
63
  * @private
64
64
  */
65
- exports.impliesNoTimeouts = flag => debugFlags.has(flag);
65
+ exports.impliesNoTimeouts = (flag) => debugFlags.has(flag);
66
66
 
67
67
  /**
68
68
  * All non-strictly-boolean arguments to node--those with values--must specify those values using `=`, e.g., `--inspect=0.0.0.0`.
@@ -72,14 +72,14 @@ exports.impliesNoTimeouts = flag => debugFlags.has(flag);
72
72
  * @returns {string[]} Unparsed arguments using `=` to specify values
73
73
  * @private
74
74
  */
75
- exports.unparseNodeFlags = opts => {
75
+ exports.unparseNodeFlags = (opts) => {
76
76
  var args = unparse(opts);
77
77
  return args.length
78
78
  ? args
79
- .join(' ')
79
+ .join(" ")
80
80
  .split(/\b/)
81
- .map(arg => (arg === ' ' ? '=' : arg))
82
- .join('')
83
- .split(' ')
81
+ .map((arg) => (arg === " " ? "=" : arg))
82
+ .join("")
83
+ .split(" ")
84
84
  : [];
85
85
  };
@@ -1,4 +1,4 @@
1
- 'use strict';
1
+ "use strict";
2
2
 
3
3
  /**
4
4
  * Contains "command" code for "one-and-dones"--options passed
@@ -8,7 +8,7 @@
8
8
  * @private
9
9
  */
10
10
 
11
- const Mocha = require('../mocha');
11
+ const Mocha = require("../mocha");
12
12
 
13
13
  /**
14
14
  * Dumps a sorted list of the enumerable, lower-case keys of some object
@@ -17,21 +17,22 @@ const Mocha = require('../mocha');
17
17
  * @ignore
18
18
  * @private
19
19
  */
20
- const showKeys = obj => {
20
+ const showKeys = (obj) => {
21
21
  console.log();
22
22
  const keys = Object.keys(obj);
23
23
  const maxKeyLength = keys.reduce((max, key) => Math.max(max, key.length), 0);
24
24
  keys
25
25
  .filter(
26
- key => /^[a-z]/.test(key) && !obj[key].browserOnly && !obj[key].abstract
26
+ (key) =>
27
+ /^[a-z]/.test(key) && !obj[key].browserOnly && !obj[key].abstract,
27
28
  )
28
29
  .sort()
29
- .forEach(key => {
30
+ .forEach((key) => {
30
31
  const description = obj[key].description;
31
32
  console.log(
32
33
  ` ${key.padEnd(maxKeyLength + 1)}${
33
- description ? `- ${description}` : ''
34
- }`
34
+ description ? `- ${description}` : ""
35
+ }`,
35
36
  );
36
37
  });
37
38
  console.log();
@@ -47,16 +48,16 @@ exports.ONE_AND_DONES = {
47
48
  * Dump list of built-in interfaces
48
49
  * @private
49
50
  */
50
- 'list-interfaces': () => {
51
+ "list-interfaces": () => {
51
52
  showKeys(Mocha.interfaces);
52
53
  },
53
54
  /**
54
55
  * Dump list of built-in reporters
55
56
  * @private
56
57
  */
57
- 'list-reporters': () => {
58
+ "list-reporters": () => {
58
59
  showKeys(Mocha.reporters);
59
- }
60
+ },
60
61
  };
61
62
 
62
63
  /**
@@ -65,5 +66,5 @@ exports.ONE_AND_DONES = {
65
66
  * @private
66
67
  */
67
68
  exports.ONE_AND_DONE_ARGS = new Set(
68
- ['help', 'h', 'version', 'V'].concat(Object.keys(exports.ONE_AND_DONES))
69
+ ["help", "h", "version", "V"].concat(Object.keys(exports.ONE_AND_DONES)),
69
70
  );
@@ -1,4 +1,4 @@
1
- 'use strict';
1
+ "use strict";
2
2
 
3
3
  /**
4
4
  * Main entry point for handling filesystem-based configuration,
@@ -7,28 +7,28 @@
7
7
  * @private
8
8
  */
9
9
 
10
- const fs = require('node:fs');
11
- const pc = require('picocolors');
12
- const yargsParser = require('yargs-parser');
10
+ const fs = require("node:fs");
11
+ const pc = require("picocolors");
12
+ const yargsParser = require("yargs-parser");
13
13
  const {
14
14
  types,
15
15
  aliases,
16
16
  isMochaFlag,
17
- expectedTypeForFlag
18
- } = require('./run-option-metadata');
19
- const {ONE_AND_DONE_ARGS} = require('./one-and-dones');
20
- const mocharc = require('../mocharc.json');
21
- const {list} = require('./run-helpers');
22
- const {loadConfig, findConfig} = require('./config');
23
- const findUp = require('find-up');
24
- const debug = require('debug')('mocha:cli:options');
25
- const {isNodeFlag} = require('./node-flags');
17
+ expectedTypeForFlag,
18
+ } = require("./run-option-metadata");
19
+ const { ONE_AND_DONE_ARGS } = require("./one-and-dones");
20
+ const mocharc = require("../mocharc.json");
21
+ const { list } = require("./run-helpers");
22
+ const { loadConfig, findConfig } = require("./config");
23
+ const findUp = require("find-up");
24
+ const debug = require("debug")("mocha:cli:options");
25
+ const { isNodeFlag } = require("./node-flags");
26
26
  const {
27
27
  createUnparsableFileError,
28
28
  createInvalidArgumentTypeError,
29
- createUnsupportedError
30
- } = require('../errors');
31
- const {isNumeric} = require('../utils');
29
+ createUnsupportedError,
30
+ } = require("../errors");
31
+ const { isNumeric } = require("../utils");
32
32
 
33
33
  /**
34
34
  * The `yargs-parser` namespace
@@ -47,10 +47,10 @@ const {isNumeric} = require('../utils');
47
47
  * @private
48
48
  */
49
49
  const YARGS_PARSER_CONFIG = {
50
- 'combine-arrays': true,
51
- 'short-option-groups': false,
52
- 'dot-notation': false,
53
- 'strip-aliased': true
50
+ "combine-arrays": true,
51
+ "short-option-groups": false,
52
+ "dot-notation": false,
53
+ "strip-aliased": true,
54
54
  };
55
55
 
56
56
  /**
@@ -62,7 +62,7 @@ const YARGS_PARSER_CONFIG = {
62
62
  * @ignore
63
63
  */
64
64
  const configuration = Object.assign({}, YARGS_PARSER_CONFIG, {
65
- 'camel-case-expansion': false
65
+ "camel-case-expansion": false,
66
66
  });
67
67
 
68
68
  /**
@@ -73,22 +73,23 @@ const configuration = Object.assign({}, YARGS_PARSER_CONFIG, {
73
73
  * @private
74
74
  * @ignore
75
75
  */
76
- const globOptions = ['spec', 'ignore'];
76
+ const globOptions = ["spec", "ignore"];
77
77
  const coerceOpts = Object.assign(
78
78
  types.array.reduce(
79
79
  (acc, arg) =>
80
80
  Object.assign(acc, {
81
- [arg]: v => Array.from(new Set(globOptions.includes(arg) ? v : list(v)))
81
+ [arg]: (v) =>
82
+ Array.from(new Set(globOptions.includes(arg) ? v : list(v))),
82
83
  }),
83
- {}
84
+ {},
84
85
  ),
85
86
  types.boolean
86
87
  .concat(types.string, types.number)
87
88
  .reduce(
88
89
  (acc, arg) =>
89
- Object.assign(acc, {[arg]: v => (Array.isArray(v) ? v.pop() : v)}),
90
- {}
91
- )
90
+ Object.assign(acc, { [arg]: (v) => (Array.isArray(v) ? v.pop() : v) }),
91
+ {},
92
+ ),
92
93
  );
93
94
 
94
95
  /**
@@ -101,7 +102,7 @@ const coerceOpts = Object.assign(
101
102
  */
102
103
  const nargOpts = types.array
103
104
  .concat(types.string, types.number)
104
- .reduce((acc, arg) => Object.assign(acc, {[arg]: 1}), {});
105
+ .reduce((acc, arg) => Object.assign(acc, { [arg]: 1 }), {});
105
106
 
106
107
  /**
107
108
  * Throws either "UNSUPPORTED" error or "INVALID_ARG_TYPE" error for numeric positional arguments.
@@ -114,13 +115,13 @@ const nargOpts = types.array
114
115
  const createErrorForNumericPositionalArg = (
115
116
  numericArg,
116
117
  allArgs,
117
- parsedResult
118
+ parsedResult,
118
119
  ) => {
119
120
  // A flag for `numericArg` exists if:
120
121
  // 1. A mocha flag immediately preceeded the numericArg in `allArgs` array and
121
122
  // 2. `numericArg` value could not be assigned to this flag by `yargs-parser` because of incompatible datatype.
122
123
  const flag = allArgs.find((arg, index) => {
123
- const normalizedArg = arg.replace(/^--?/, '');
124
+ const normalizedArg = arg.replace(/^--?/, "");
124
125
  return (
125
126
  isMochaFlag(arg) &&
126
127
  allArgs[index + 1] === String(numericArg) &&
@@ -132,11 +133,11 @@ const createErrorForNumericPositionalArg = (
132
133
  throw createInvalidArgumentTypeError(
133
134
  `Mocha flag '${flag}' given invalid option: '${numericArg}'`,
134
135
  numericArg,
135
- expectedTypeForFlag(flag)
136
+ expectedTypeForFlag(flag),
136
137
  );
137
138
  } else {
138
139
  throw createUnsupportedError(
139
- `Option ${numericArg} is unsupported by the mocha cli`
140
+ `Option ${numericArg} is unsupported by the mocha cli`,
140
141
  );
141
142
  }
142
143
  };
@@ -156,13 +157,13 @@ const parse = (args = [], defaultValues = {}, ...configObjects) => {
156
157
  // 3. to avoid explicitly defining the set of them, we tell yargs-parser they
157
158
  // are ALL boolean flags.
158
159
  // 4. we can then reapply the values after yargs-parser is done.
159
- const allArgs = Array.isArray(args) ? args : args.split(' ');
160
+ const allArgs = Array.isArray(args) ? args : args.split(" ");
160
161
  const nodeArgs = allArgs.reduce((acc, arg) => {
161
- const pair = arg.split('=');
162
+ const pair = arg.split("=");
162
163
  let flag = pair[0];
163
164
  if (isNodeFlag(flag, false)) {
164
- flag = flag.replace(/^--?/, '');
165
- return acc.concat([[flag, arg.includes('=') ? pair[1] : true]]);
165
+ flag = flag.replace(/^--?/, "");
166
+ return acc.concat([[flag, arg.includes("=") ? pair[1] : true]]);
166
167
  }
167
168
  return acc;
168
169
  }, []);
@@ -177,19 +178,19 @@ const parse = (args = [], defaultValues = {}, ...configObjects) => {
177
178
  string: types.string,
178
179
  array: types.array,
179
180
  number: types.number,
180
- boolean: types.boolean.concat(nodeArgs.map(pair => pair[0]))
181
+ boolean: types.boolean.concat(nodeArgs.map((pair) => pair[0])),
181
182
  });
182
183
  if (result.error) {
183
184
  console.error(pc.red(`Error: ${result.error.message}`));
184
185
  process.exit(1);
185
186
  }
186
187
 
187
- const numericPositionalArg = result.argv._.find(arg => isNumeric(arg));
188
+ const numericPositionalArg = result.argv._.find((arg) => isNumeric(arg));
188
189
  if (numericPositionalArg) {
189
190
  createErrorForNumericPositionalArg(
190
191
  numericPositionalArg,
191
192
  allArgs,
192
- result.argv
193
+ result.argv,
193
194
  );
194
195
  }
195
196
 
@@ -236,33 +237,32 @@ const loadPkgRc = (args = {}) => {
236
237
  if (filepath) {
237
238
  let configData;
238
239
  try {
239
- configData = fs.readFileSync(filepath, 'utf8');
240
+ configData = fs.readFileSync(filepath, "utf8");
240
241
  } catch (err) {
241
242
  // If `args.package` was explicitly specified, throw an error
242
243
  if (filepath == args.package) {
243
244
  throw createUnparsableFileError(
244
245
  `Unable to read ${filepath}: ${err}`,
245
- filepath
246
+ filepath,
246
247
  );
247
248
  } else {
248
- debug('failed to read default package.json at %s; ignoring',
249
- filepath);
249
+ debug("failed to read default package.json at %s; ignoring", filepath);
250
250
  return result;
251
251
  }
252
252
  }
253
253
  try {
254
254
  const pkg = JSON.parse(configData);
255
255
  if (pkg.mocha) {
256
- debug('`mocha` prop of package.json parsed: %O', pkg.mocha);
256
+ debug("`mocha` prop of package.json parsed: %O", pkg.mocha);
257
257
  result = pkg.mocha;
258
258
  } else {
259
- debug('no config found in %s', filepath);
259
+ debug("no config found in %s", filepath);
260
260
  }
261
261
  } catch (err) {
262
262
  // If JSON failed to parse, throw an error.
263
263
  throw createUnparsableFileError(
264
264
  `Unable to parse ${filepath}: ${err}`,
265
- filepath
265
+ filepath,
266
266
  );
267
267
  }
268
268
  }
@@ -293,13 +293,13 @@ const loadOptions = (argv = []) => {
293
293
  if (
294
294
  Array.from(ONE_AND_DONE_ARGS).reduce(
295
295
  (acc, arg) => acc || arg in args,
296
- false
296
+ false,
297
297
  )
298
298
  ) {
299
299
  return args;
300
300
  }
301
301
 
302
- const envConfig = parse(process.env.MOCHA_OPTIONS || '');
302
+ const envConfig = parse(process.env.MOCHA_OPTIONS || "");
303
303
  const rcConfig = loadRc(args);
304
304
  const pkgConfig = loadPkgRc(args);
305
305
 
@@ -318,7 +318,7 @@ const loadOptions = (argv = []) => {
318
318
  args,
319
319
  envConfig,
320
320
  rcConfig || {},
321
- pkgConfig || {}
321
+ pkgConfig || {},
322
322
  );
323
323
 
324
324
  // recombine positional arguments and "spec"