mocha 12.0.0-beta-9.2 → 12.0.0-beta-9.4

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 (63) hide show
  1. package/bin/mocha.js +6 -6
  2. package/browser-entry.js +2 -2
  3. package/lib/browser/{highlight-tags.js → highlight-tags.mjs} +2 -4
  4. package/lib/browser/{parse-query.js → parse-query.mjs} +2 -4
  5. package/lib/cli/{cli.js → cli.mjs} +25 -41
  6. package/lib/cli/collect-files.js +2 -2
  7. package/lib/cli/{commands.js → commands.mjs} +3 -7
  8. package/lib/cli/config.js +2 -1
  9. package/lib/cli/index.js +1 -1
  10. package/lib/cli/{init.js → init.mjs} +7 -9
  11. package/lib/cli/{lookup-files.js → lookup-files.mjs} +11 -14
  12. package/lib/cli/{node-flags.js → node-flags.mjs} +9 -9
  13. package/lib/cli/{one-and-dones.js → one-and-dones.mjs} +6 -6
  14. package/lib/cli/{options.js → options.mjs} +25 -32
  15. package/lib/cli/run-helpers.js +2 -2
  16. package/lib/cli/{run-option-metadata.js → run-option-metadata.mjs} +13 -14
  17. package/lib/cli/run.js +3 -3
  18. package/lib/cli/watch-run.js +1 -1
  19. package/lib/context.mjs +79 -0
  20. package/lib/{error-constants.js → error-constants.mjs} +1 -5
  21. package/lib/{errors.js → errors.mjs} +6 -73
  22. package/lib/{hook.js → hook.mjs} +4 -5
  23. package/lib/interfaces/{bdd.js → bdd.mjs} +11 -12
  24. package/lib/interfaces/{common.js → common.mjs} +10 -18
  25. package/lib/interfaces/{exports.js → exports.mjs} +8 -6
  26. package/lib/interfaces/index.mjs +11 -0
  27. package/lib/interfaces/{qunit.js → qunit.mjs} +11 -11
  28. package/lib/interfaces/{tdd.js → tdd.mjs} +11 -12
  29. package/lib/mocha.js +14 -11
  30. package/lib/nodejs/buffered-worker-pool.js +1 -1
  31. package/lib/nodejs/esm-utils.js +18 -2
  32. package/lib/nodejs/parallel-buffered-runner.js +1 -1
  33. package/lib/nodejs/serializer.js +1 -1
  34. package/lib/nodejs/worker.js +1 -1
  35. package/lib/{pending.js → pending.mjs} +1 -3
  36. package/lib/{plugin-loader.js → plugin-loader.mjs} +6 -7
  37. package/lib/reporters/base.js +1 -1
  38. package/lib/reporters/{doc.js → doc.mjs} +5 -6
  39. package/lib/reporters/{dot.js → dot.mjs} +5 -5
  40. package/lib/reporters/{html.js → html.mjs} +8 -9
  41. package/lib/reporters/index.js +28 -14
  42. package/lib/reporters/{json-stream.js → json-stream.mjs} +5 -6
  43. package/lib/reporters/{json.js → json.mjs} +9 -9
  44. package/lib/reporters/{landing.js → landing.mjs} +6 -6
  45. package/lib/reporters/{list.js → list.mjs} +5 -5
  46. package/lib/reporters/{markdown.js → markdown.mjs} +5 -6
  47. package/lib/reporters/{min.js → min.mjs} +5 -5
  48. package/lib/reporters/{nyan.js → nyan.mjs} +4 -5
  49. package/lib/reporters/{progress.js → progress.mjs} +4 -5
  50. package/lib/reporters/{spec.js → spec.mjs} +5 -6
  51. package/lib/reporters/{tap.js → tap.mjs} +6 -7
  52. package/lib/reporters/{xunit.js → xunit.mjs} +11 -11
  53. package/lib/{runnable.js → runnable.mjs} +10 -10
  54. package/lib/runner.js +5 -5
  55. package/lib/{stats-collector.js → stats-collector.mjs} +11 -12
  56. package/lib/{suite.js → suite.mjs} +12 -11
  57. package/lib/{test.js → test.mjs} +5 -7
  58. package/lib/utils/regexp.mjs +14 -0
  59. package/mocha.js +7110 -7190
  60. package/mocha.js.map +1 -1
  61. package/package.json +12 -14
  62. package/lib/context.js +0 -91
  63. package/lib/interfaces/index.js +0 -6
package/bin/mocha.js CHANGED
@@ -4,22 +4,22 @@
4
4
 
5
5
  /**
6
6
  * This wrapper executable checks for known node flags and appends them when found,
7
- * before invoking the "real" executable (`lib/cli/cli.js`)
7
+ * before invoking the "real" executable (`lib/cli/cli.mjs`)
8
8
  *
9
9
  * @module bin/mocha
10
10
  * @private
11
11
  */
12
12
 
13
13
  const os = require("node:os");
14
- const { loadOptions } = require("../lib/cli/options");
14
+ const { loadOptions } = require("../lib/cli/options.mjs");
15
15
  const {
16
16
  unparseNodeFlags,
17
17
  isNodeFlag,
18
18
  impliesNoTimeouts,
19
- } = require("../lib/cli/node-flags");
19
+ } = require("../lib/cli/node-flags.mjs");
20
20
  const unparse = require("yargs-unparser");
21
21
  const debug = require("debug")("mocha:cli:mocha");
22
- const { aliases } = require("../lib/cli/run-option-metadata");
22
+ const { aliases } = require("../lib/cli/run-option-metadata.mjs");
23
23
 
24
24
  const mochaArgs = {};
25
25
  const nodeArgs = {};
@@ -81,7 +81,7 @@ if (mochaArgs._) {
81
81
 
82
82
  if (mochaArgs["node-option"] || Object.keys(nodeArgs).length || hasInspect) {
83
83
  const { spawn } = require("node:child_process");
84
- const mochaPath = require.resolve("../lib/cli/cli.js");
84
+ const mochaPath = require.resolve("../lib/cli/cli.mjs");
85
85
 
86
86
  const nodeArgv =
87
87
  (mochaArgs["node-option"] &&
@@ -146,5 +146,5 @@ if (mochaArgs["node-option"] || Object.keys(nodeArgs).length || hasInspect) {
146
146
  });
147
147
  } else {
148
148
  debug("running Mocha in-process");
149
- require("../lib/cli/cli").main([], mochaArgs);
149
+ require("../lib/cli/cli.mjs").main([], mochaArgs);
150
150
  }
package/browser-entry.js CHANGED
@@ -8,8 +8,8 @@
8
8
 
9
9
  process.stdout = require("browser-stdout")({ label: false });
10
10
 
11
- var parseQuery = require("./lib/browser/parse-query");
12
- var highlightTags = require("./lib/browser/highlight-tags");
11
+ var parseQuery = require("./lib/browser/parse-query.mjs").parseQuery;
12
+ var highlightTags = require("./lib/browser/highlight-tags.mjs").highlightTags;
13
13
  var Mocha = require("./lib/mocha");
14
14
 
15
15
  /**
@@ -1,5 +1,3 @@
1
- "use strict";
2
-
3
1
  /**
4
2
  * Highlight the given string of `js`.
5
3
  *
@@ -31,9 +29,9 @@ function highlight(js) {
31
29
  * @private
32
30
  * @param {string} name
33
31
  */
34
- module.exports = function highlightTags(name) {
32
+ export function highlightTags(name) {
35
33
  var code = document.getElementById("mocha").getElementsByTagName(name);
36
34
  for (var i = 0, len = code.length; i < len; ++i) {
37
35
  code[i].innerHTML = highlight(code[i].innerHTML);
38
36
  }
39
- };
37
+ }
@@ -1,5 +1,3 @@
1
- "use strict";
2
-
3
1
  /**
4
2
  * Parse the given `qs`.
5
3
  *
@@ -7,7 +5,7 @@
7
5
  * @param {string} qs
8
6
  * @return {Object<string, string>}
9
7
  */
10
- module.exports = function parseQuery(qs) {
8
+ export function parseQuery(qs) {
11
9
  return qs
12
10
  .replace("?", "")
13
11
  .split("&")
@@ -21,4 +19,4 @@ module.exports = function parseQuery(qs) {
21
19
 
22
20
  return obj;
23
21
  }, {});
24
- };
22
+ }
@@ -1,5 +1,3 @@
1
- "use strict";
2
-
3
1
  /**
4
2
  * Contains CLI entry point and public API for programmatic usage in Node.js.
5
3
  * - Option parsing is handled by {@link https://npm.im/yargs yargs}.
@@ -8,25 +6,20 @@
8
6
  * @module lib/cli
9
7
  */
10
8
 
11
- const debug = require("debug")("mocha:cli:cli");
12
- const yargs = require("yargs");
13
- const path = require("node:path");
14
- const {
15
- loadRc,
16
- loadPkgRc,
17
- loadOptions,
18
- YARGS_PARSER_CONFIG,
19
- } = require("./options");
20
- const lookupFiles = require("./lookup-files");
21
- const commands = require("./commands");
22
- const pc = require("picocolors");
23
- const {
24
- repository,
25
- homepage,
26
- version,
27
- discord,
28
- } = require("../../package.json");
29
- const { cwd, logSymbols } = require("../utils");
9
+ import debugModule from "debug";
10
+ import yargs from "yargs";
11
+ import { fileURLToPath } from "node:url";
12
+
13
+ import { loadOptions, YARGS_PARSER_CONFIG } from "./options.mjs";
14
+ import { run, init } from "./commands.mjs";
15
+ import pc from "picocolors";
16
+ import { logSymbols } from "../utils.js";
17
+
18
+ import packageJson from "../../package.json" with { type: "json" };
19
+
20
+ const __filename = fileURLToPath(import.meta.url);
21
+
22
+ const debug = debugModule("mocha:cli:cli");
30
23
 
31
24
  /**
32
25
  * - Accepts an `Array` of arguments
@@ -37,12 +30,8 @@ const { cwd, logSymbols } = require("../utils");
37
30
  * @param {string[]} argv - Array of arguments to parse, or by default the lovely `process.argv.slice(2)`
38
31
  * @param {object} [mochaArgs] - Object of already parsed Mocha arguments (by bin/mocha)
39
32
  */
40
- exports.main = (argv = process.argv.slice(2), mochaArgs) => {
33
+ export function main(argv = process.argv.slice(2), mochaArgs) {
41
34
  debug("entered main with raw args", argv);
42
- // ensure we can require() from current working directory
43
- if (typeof module.paths !== "undefined") {
44
- module.paths.push(cwd(), path.resolve("node_modules"));
45
- }
46
35
 
47
36
  try {
48
37
  Error.stackTraceLimit = Infinity; // configurable via --stack-trace-limit?
@@ -50,12 +39,12 @@ exports.main = (argv = process.argv.slice(2), mochaArgs) => {
50
39
  debug("unable to set Error.stackTraceLimit = Infinity", err);
51
40
  }
52
41
 
53
- var args = mochaArgs || loadOptions(argv);
42
+ const args = mochaArgs ?? loadOptions(argv);
54
43
 
55
44
  yargs()
56
45
  .scriptName("mocha")
57
- .command(commands.run)
58
- .command(commands.init)
46
+ .command(run)
47
+ .command(init)
59
48
  .updateStrings({
60
49
  "Positionals:": "Positional Arguments",
61
50
  "Options:": "Other Options",
@@ -74,27 +63,22 @@ exports.main = (argv = process.argv.slice(2), mochaArgs) => {
74
63
  })
75
64
  .help("help", "Show usage information & exit")
76
65
  .alias("help", "h")
77
- .version("version", "Show version number & exit", version)
66
+ .version("version", "Show version number & exit", packageJson.version)
78
67
  .alias("version", "V")
79
68
  .wrap(process.stdout.columns ? Math.min(process.stdout.columns, 80) : 80)
80
69
  .epilog(
81
70
  `${pc.reset("Mocha Resources")}
82
- Chat: ${pc.magenta(discord)}
83
- GitHub: ${pc.blue(repository.url)}
84
- Docs: ${pc.yellow(homepage)}
71
+ Chat: ${pc.magenta(packageJson.discord)}
72
+ GitHub: ${pc.blue(packageJson.repository.url)}
73
+ Docs: ${pc.yellow(packageJson.homepage)}
85
74
  `,
86
75
  )
87
76
  .parserConfiguration(YARGS_PARSER_CONFIG)
88
77
  .config(args)
89
78
  .parse(args._);
90
- };
91
-
92
- exports.lookupFiles = lookupFiles;
93
- exports.loadOptions = loadOptions;
94
- exports.loadPkgRc = loadPkgRc;
95
- exports.loadRc = loadRc;
79
+ }
96
80
 
97
81
  // allow direct execution
98
- if (require.main === module) {
99
- exports.main();
82
+ if (__filename === process.argv[1]) {
83
+ main();
100
84
  }
@@ -4,8 +4,8 @@ const path = require("node:path");
4
4
  const pc = require("picocolors");
5
5
  const debug = require("debug")("mocha:cli:run:helpers");
6
6
  const { minimatch } = require("minimatch");
7
- const { NO_FILES_MATCH_PATTERN } = require("../error-constants").constants;
8
- const lookupFiles = require("./lookup-files");
7
+ const { NO_FILES_MATCH_PATTERN } = require("../error-constants.mjs").constants;
8
+ const { lookupFiles } = require("./lookup-files.mjs");
9
9
  const { castArray } = require("../utils");
10
10
 
11
11
  /**
@@ -1,5 +1,3 @@
1
- "use strict";
2
-
3
1
  /**
4
2
  * Exports Yargs commands
5
3
  * @see https://github.com/yargs/yargs/blob/main/docs/advanced.md
@@ -7,8 +5,6 @@
7
5
  * @module
8
6
  */
9
7
 
10
- module.exports = {
11
- init: require("./init"),
12
- // default command
13
- run: require("./run"),
14
- };
8
+ export * as init from "./init.mjs";
9
+ // default command
10
+ export { default as run } from "./run.js";
package/lib/cli/config.js CHANGED
@@ -11,7 +11,7 @@ const fs = require("node:fs");
11
11
  const path = require("node:path");
12
12
  const debug = require("debug")("mocha:cli:config");
13
13
  const findUp = require("find-up");
14
- const { createUnparsableFileError } = require("../errors");
14
+ const { createUnparsableFileError } = require("../errors.mjs");
15
15
  const utils = require("../utils");
16
16
 
17
17
  /**
@@ -21,6 +21,7 @@ const utils = require("../utils");
21
21
  * The user should still be able to explicitly specify a file.
22
22
  * @private
23
23
  */
24
+ // This is documented publicly in `configuring.mdx`
24
25
  exports.CONFIG_FILES = [
25
26
  ".mocharc.cjs",
26
27
  ".mocharc.js",
package/lib/cli/index.js CHANGED
@@ -1,3 +1,3 @@
1
1
  "use strict";
2
2
 
3
- module.exports = require("./cli");
3
+ module.exports = require("./cli.mjs");
@@ -1,5 +1,3 @@
1
- "use strict";
2
-
3
1
  /**
4
2
  * Command module for "init" command
5
3
  *
@@ -7,22 +5,22 @@
7
5
  * @module
8
6
  */
9
7
 
10
- const fs = require("node:fs");
11
- const path = require("node:path");
8
+ import fs from "node:fs";
9
+ import path from "node:path";
12
10
 
13
- exports.command = "init <path>";
11
+ export const command = "init <path>";
14
12
 
15
- exports.description = "create a client-side Mocha setup at <path>";
13
+ export const description = "create a client-side Mocha setup at <path>";
16
14
 
17
- exports.builder = (yargs) =>
15
+ export const builder = (yargs) =>
18
16
  yargs.positional("path", {
19
17
  type: "string",
20
18
  normalize: true,
21
19
  });
22
20
 
23
- exports.handler = (argv) => {
21
+ export const handler = (argv) => {
24
22
  const destdir = argv.path;
25
- const srcdir = path.join(__dirname, "..", "..");
23
+ const srcdir = path.join(import.meta.dirname, "..", "..");
26
24
  fs.mkdirSync(destdir, { recursive: true });
27
25
  const css = fs.readFileSync(path.join(srcdir, "mocha.css"));
28
26
  const js = fs.readFileSync(path.join(srcdir, "mocha.js"));
@@ -1,17 +1,18 @@
1
- "use strict";
2
1
  /**
3
2
  * Contains `lookupFiles`, which takes some globs/dirs/options and returns a list of files.
4
3
  * @module
5
4
  * @private
6
5
  */
7
6
 
8
- var fs = require("node:fs");
9
- var path = require("node:path");
10
- var glob = require("glob");
11
- var errors = require("../errors");
12
- var createNoFilesMatchPatternError = errors.createNoFilesMatchPatternError;
13
- var createMissingArgumentError = errors.createMissingArgumentError;
14
- const debug = require("debug")("mocha:cli:lookup-files");
7
+ import fs from "node:fs";
8
+ import path from "node:path";
9
+ import * as glob from "glob";
10
+ import {
11
+ createNoFilesMatchPatternError,
12
+ createMissingArgumentError,
13
+ } from "../errors.mjs";
14
+ import debugModule from "debug";
15
+ const debug = debugModule("mocha:cli:lookup-files");
15
16
 
16
17
  /**
17
18
  * Determines if pathname would be a "hidden" file (or directory) on UN*X.
@@ -65,11 +66,7 @@ const hasMatchingExtname = (pathname, exts = []) =>
65
66
  * @throws {Error} if no files match pattern.
66
67
  * @throws {TypeError} if `filepath` is directory and `extensions` not provided.
67
68
  */
68
- module.exports = function lookupFiles(
69
- filepath,
70
- extensions = [],
71
- recursive = false,
72
- ) {
69
+ export function lookupFiles(filepath, extensions = [], recursive = false) {
73
70
  const files = [];
74
71
  let stat;
75
72
 
@@ -152,4 +149,4 @@ module.exports = function lookupFiles(
152
149
  });
153
150
 
154
151
  return files;
155
- };
152
+ }
@@ -1,5 +1,3 @@
1
- "use strict";
2
-
3
1
  /**
4
2
  * Some settings and code related to Mocha's handling of Node.js/V8 flags.
5
3
  * @private
@@ -7,8 +5,8 @@
7
5
  */
8
6
 
9
7
  const nodeFlags = process.allowedNodeEnvironmentFlags;
10
- const { isMochaFlag } = require("./run-option-metadata");
11
- const unparse = require("yargs-unparser");
8
+ import { isMochaFlag } from "./run-option-metadata.mjs";
9
+ import unparse from "yargs-unparser";
12
10
 
13
11
  /**
14
12
  * These flags are considered "debug" flags.
@@ -34,7 +32,7 @@ const debugFlags = new Set(["inspect", "inspect-brk"]);
34
32
  * @returns {boolean} If the flag is considered a "Node" flag.
35
33
  * @private
36
34
  */
37
- exports.isNodeFlag = (flag, bareword = true) => {
35
+ export function isNodeFlag(flag, bareword = true) {
38
36
  if (!bareword) {
39
37
  // check if the flag begins with dashes; if not, not a node flag.
40
38
  if (!/^--?/.test(flag)) {
@@ -53,7 +51,7 @@ exports.isNodeFlag = (flag, bareword = true) => {
53
51
  flag,
54
52
  )
55
53
  );
56
- };
54
+ }
57
55
 
58
56
  /**
59
57
  * Returns `true` if the flag is a "debug-like" flag. These require timeouts
@@ -62,7 +60,9 @@ exports.isNodeFlag = (flag, bareword = true) => {
62
60
  * @returns {boolean}
63
61
  * @private
64
62
  */
65
- exports.impliesNoTimeouts = (flag) => debugFlags.has(flag);
63
+ export function impliesNoTimeouts(flag) {
64
+ return debugFlags.has(flag);
65
+ }
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,7 +72,7 @@ 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
+ export function unparseNodeFlags(opts) {
76
76
  var args = unparse(opts);
77
77
  return args.length
78
78
  ? args
@@ -82,4 +82,4 @@ exports.unparseNodeFlags = (opts) => {
82
82
  .join("")
83
83
  .split(" ")
84
84
  : [];
85
- };
85
+ }
@@ -1,5 +1,3 @@
1
- "use strict";
2
-
3
1
  /**
4
2
  * Contains "command" code for "one-and-dones"--options passed
5
3
  * to Mocha which cause it to just dump some info and exit.
@@ -8,7 +6,7 @@
8
6
  * @private
9
7
  */
10
8
 
11
- const Mocha = require("../mocha");
9
+ import Mocha from "../mocha.js";
12
10
 
13
11
  /**
14
12
  * Dumps a sorted list of the enumerable, lower-case keys of some object
@@ -43,7 +41,7 @@ const showKeys = (obj) => {
43
41
  * @namespace
44
42
  * @private
45
43
  */
46
- exports.ONE_AND_DONES = {
44
+ const ONE_AND_DONES = {
47
45
  /**
48
46
  * Dump list of built-in interfaces
49
47
  * @private
@@ -65,6 +63,8 @@ exports.ONE_AND_DONES = {
65
63
  * @type Set<string>
66
64
  * @private
67
65
  */
68
- exports.ONE_AND_DONE_ARGS = new Set(
69
- ["help", "h", "version", "V"].concat(Object.keys(exports.ONE_AND_DONES)),
66
+ const ONE_AND_DONE_ARGS = new Set(
67
+ ["help", "h", "version", "V"].concat(Object.keys(ONE_AND_DONES)),
70
68
  );
69
+
70
+ export { ONE_AND_DONES, ONE_AND_DONE_ARGS };
@@ -1,5 +1,3 @@
1
- "use strict";
2
-
3
1
  /**
4
2
  * Main entry point for handling filesystem-based configuration,
5
3
  * whether that's a config file or `package.json` or whatever.
@@ -7,28 +5,29 @@
7
5
  * @private
8
6
  */
9
7
 
10
- const fs = require("node:fs");
11
- const pc = require("picocolors");
12
- const yargsParser = require("yargs-parser");
13
- const {
8
+ import { readFileSync } from "node:fs";
9
+ import pc from "picocolors";
10
+ import yargsParser from "yargs-parser";
11
+ import {
14
12
  types,
15
13
  aliases,
16
14
  isMochaFlag,
17
15
  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
- const {
16
+ } from "./run-option-metadata.mjs";
17
+ import { ONE_AND_DONE_ARGS } from "./one-and-dones.mjs";
18
+ import mocharc from "../mocharc.json" with { type: "json" };
19
+ import { list } from "./run-helpers.js";
20
+ import { loadConfig, findConfig } from "./config.js";
21
+ import { sync } from "find-up";
22
+ import debugModule from "debug";
23
+ const debug = debugModule("mocha:cli:options");
24
+ import { isNodeFlag } from "./node-flags.mjs";
25
+ import {
27
26
  createUnparsableFileError,
28
27
  createInvalidArgumentTypeError,
29
28
  createUnsupportedError,
30
- } = require("../errors");
31
- const { isNumeric } = require("../utils");
29
+ } from "../errors.mjs";
30
+ import { isNumeric } from "../utils.js";
32
31
 
33
32
  /**
34
33
  * The `yargs-parser` namespace
@@ -46,7 +45,7 @@ const { isNumeric } = require("../utils");
46
45
  * Base yargs parser configuration
47
46
  * @private
48
47
  */
49
- const YARGS_PARSER_CONFIG = {
48
+ export const YARGS_PARSER_CONFIG = {
50
49
  "combine-arrays": true,
51
50
  "short-option-groups": false,
52
51
  "dot-notation": false,
@@ -210,34 +209,33 @@ const parse = (args = [], defaultValues = {}, ...configObjects) => {
210
209
  * @alias module:lib/cli.loadRc
211
210
  * @returns {external:yargsParser.Arguments|void} Parsed config, or nothing if `args.config` is `false`
212
211
  */
213
- const loadRc = (args = {}) => {
212
+ export const loadRc = (args = {}) => {
214
213
  if (args.config !== false) {
215
214
  const config = args.config || findConfig();
216
215
  return config ? loadConfig(config) : {};
217
216
  }
218
217
  };
219
218
 
220
- module.exports.loadRc = loadRc;
221
-
222
219
  /**
223
220
  * Given path to `package.json` in `args.package`, attempt to load config from `mocha` prop.
221
+ * If `args.package` is falsy, attempts to load from default package location (`./package.json`)
224
222
  * @param {Object} [args] - Arguments object
225
- * @param {string|boolean} [args.config] - Path to `package.json` or `false` to skip
223
+ * @param {string|boolean} [args.config] - Path to `package.json` or `false` to use default
226
224
  * @public
227
225
  * @alias module:lib/cli.loadPkgRc
228
- * @returns {external:yargsParser.Arguments|void} Parsed config, or nothing if `args.package` is `false`
226
+ * @returns {external:yargsParser.Arguments|void} Parsed config. Throws if unparsableF. Empty object if file not found.
229
227
  */
230
- const loadPkgRc = (args = {}) => {
228
+ export const loadPkgRc = (args = {}) => {
231
229
  let result;
232
230
  if (args.package === false) {
233
231
  return result;
234
232
  }
235
233
  result = {};
236
- const filepath = args.package || findUp.sync(mocharc.package);
234
+ const filepath = args.package || sync(mocharc.package);
237
235
  if (filepath) {
238
236
  let configData;
239
237
  try {
240
- configData = fs.readFileSync(filepath, "utf8");
238
+ configData = readFileSync(filepath, "utf8");
241
239
  } catch (err) {
242
240
  // If `args.package` was explicitly specified, throw an error
243
241
  if (filepath == args.package) {
@@ -269,8 +267,6 @@ const loadPkgRc = (args = {}) => {
269
267
  return result;
270
268
  };
271
269
 
272
- module.exports.loadPkgRc = loadPkgRc;
273
-
274
270
  /**
275
271
  * Priority list:
276
272
  *
@@ -287,7 +283,7 @@ module.exports.loadPkgRc = loadPkgRc;
287
283
  * @alias module:lib/cli.loadOptions
288
284
  * @returns {external:yargsParser.Arguments} Parsed args from everything
289
285
  */
290
- const loadOptions = (argv = []) => {
286
+ export const loadOptions = (argv = []) => {
291
287
  let args = parse(argv);
292
288
  // short-circuit: look for a flag that would abort loading of options
293
289
  if (
@@ -332,6 +328,3 @@ const loadOptions = (argv = []) => {
332
328
 
333
329
  return args;
334
330
  };
335
-
336
- module.exports.loadOptions = loadOptions;
337
- module.exports.YARGS_PARSER_CONFIG = YARGS_PARSER_CONFIG;
@@ -21,9 +21,9 @@ const debug = require("debug")("mocha:cli:run:helpers");
21
21
  const { watchRun, watchParallelRun } = require("./watch-run");
22
22
  const collectFiles = require("./collect-files");
23
23
  const { format } = require("node:util");
24
- const { createInvalidLegacyPluginError } = require("../errors");
24
+ const { createInvalidLegacyPluginError } = require("../errors.mjs");
25
25
  const { requireOrImport } = require("../nodejs/esm-utils");
26
- const PluginLoader = require("../plugin-loader");
26
+ const { PluginLoader } = require("../plugin-loader.mjs");
27
27
 
28
28
  /**
29
29
  * Exits Mocha when tests + code under test has finished execution (default)
@@ -1,5 +1,3 @@
1
- "use strict";
2
-
3
1
  /**
4
2
  * Metadata about various options of the `run` command
5
3
  * @see module:lib/cli/run
@@ -12,7 +10,7 @@
12
10
  * @type {Record<string, string[]>}
13
11
  * @private
14
12
  */
15
- const TYPES = (exports.types = {
13
+ const types = {
16
14
  array: [
17
15
  "extension",
18
16
  "file",
@@ -63,7 +61,7 @@ const TYPES = (exports.types = {
63
61
  "slow",
64
62
  "timeout",
65
63
  ],
66
- });
64
+ };
67
65
 
68
66
  /**
69
67
  * Option aliases keyed by canonical option name.
@@ -71,7 +69,7 @@ const TYPES = (exports.types = {
71
69
  * @type {Record<string, string[]>}
72
70
  * @private
73
71
  */
74
- exports.aliases = {
72
+ const aliases = {
75
73
  "async-only": ["A"],
76
74
  bail: ["b"],
77
75
  color: ["c", "colors"],
@@ -94,13 +92,13 @@ exports.aliases = {
94
92
  watch: ["w"],
95
93
  };
96
94
 
97
- const ALL_MOCHA_FLAGS = Object.keys(TYPES).reduce((acc, key) => {
95
+ const ALL_MOCHA_FLAGS = Object.keys(types).reduce((acc, key) => {
98
96
  // gets all flags from each of the fields in `types`, adds those,
99
97
  // then adds aliases of each flag (if any)
100
- TYPES[key].forEach((flag) => {
98
+ types[key].forEach((flag) => {
101
99
  acc.add(flag);
102
- const aliases = exports.aliases[flag] || [];
103
- aliases.forEach((alias) => {
100
+ const flagAliases = aliases[flag] || [];
101
+ flagAliases.forEach((alias) => {
104
102
  acc.add(alias);
105
103
  });
106
104
  });
@@ -113,7 +111,7 @@ const ALL_MOCHA_FLAGS = Object.keys(TYPES).reduce((acc, key) => {
113
111
  * @returns {boolean} If `true`, this is a Mocha flag
114
112
  * @private
115
113
  */
116
- exports.isMochaFlag = (flag) => {
114
+ const isMochaFlag = (flag) => {
117
115
  return ALL_MOCHA_FLAGS.has(flag.replace(/^--?/, ""));
118
116
  };
119
117
 
@@ -123,17 +121,18 @@ exports.isMochaFlag = (flag) => {
123
121
  * @returns {string | undefined} - If flag is a valid mocha flag, the expected type of argument for this flag is returned, otherwise undefined is returned.
124
122
  * @private
125
123
  */
126
- exports.expectedTypeForFlag = (flag) => {
124
+ const expectedTypeForFlag = (flag) => {
127
125
  const normalizedName = flag.replace(/^--?/, "");
128
126
 
129
127
  // If flag is an alias, get it's full name.
130
- const aliases = exports.aliases;
131
128
  const fullFlagName =
132
129
  Object.keys(aliases).find((flagName) =>
133
130
  aliases[flagName].includes(normalizedName),
134
131
  ) || normalizedName;
135
132
 
136
- return Object.keys(TYPES).find((flagType) =>
137
- TYPES[flagType].includes(fullFlagName),
133
+ return Object.keys(types).find((flagType) =>
134
+ types[flagType].includes(fullFlagName),
138
135
  );
139
136
  };
137
+
138
+ export { types, aliases, isMochaFlag, expectedTypeForFlag };