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
@@ -1,4 +1,4 @@
1
- 'use strict';
1
+ "use strict";
2
2
 
3
3
  /**
4
4
  * Helper scripts for the `run` command
@@ -14,16 +14,16 @@
14
14
  * @typedef {import('../runner.js')} Runner
15
15
  */
16
16
 
17
- const fs = require('node:fs');
18
- const path = require('node:path');
19
- const pc = require('picocolors');
20
- const debug = require('debug')('mocha:cli:run:helpers');
21
- const {watchRun, watchParallelRun} = require('./watch-run');
22
- const collectFiles = require('./collect-files');
23
- const {format} = require('node:util');
24
- const {createInvalidLegacyPluginError} = require('../errors');
25
- const {requireOrImport} = require('../nodejs/esm-utils');
26
- const PluginLoader = require('../plugin-loader');
17
+ const fs = require("node:fs");
18
+ const path = require("node:path");
19
+ const pc = require("picocolors");
20
+ const debug = require("debug")("mocha:cli:run:helpers");
21
+ const { watchRun, watchParallelRun } = require("./watch-run");
22
+ const collectFiles = require("./collect-files");
23
+ const { format } = require("node:util");
24
+ const { createInvalidLegacyPluginError } = require("../errors");
25
+ const { requireOrImport } = require("../nodejs/esm-utils");
26
+ const PluginLoader = require("../plugin-loader");
27
27
 
28
28
  /**
29
29
  * Exits Mocha when tests + code under test has finished execution (default)
@@ -31,9 +31,12 @@ const PluginLoader = require('../plugin-loader');
31
31
  * @ignore
32
32
  * @private
33
33
  */
34
- const exitMochaLater = clampedCode => {
35
- process.on('exit', () => {
36
- process.exitCode = Math.min(clampedCode, process.argv.includes('--posix-exit-codes') ? 1 : 255);
34
+ const exitMochaLater = (clampedCode) => {
35
+ process.on("exit", () => {
36
+ process.exitCode = Math.min(
37
+ clampedCode,
38
+ process.argv.includes("--posix-exit-codes") ? 1 : 255,
39
+ );
37
40
  });
38
41
  };
39
42
 
@@ -44,8 +47,8 @@ const exitMochaLater = clampedCode => {
44
47
  * @ignore
45
48
  * @private
46
49
  */
47
- const exitMocha = clampedCode => {
48
- const usePosixExitCodes = process.argv.includes('--posix-exit-codes');
50
+ const exitMocha = (clampedCode) => {
51
+ const usePosixExitCodes = process.argv.includes("--posix-exit-codes");
49
52
  clampedCode = Math.min(clampedCode, usePosixExitCodes ? 1 : 255);
50
53
  let draining = 0;
51
54
 
@@ -64,10 +67,10 @@ const exitMocha = clampedCode => {
64
67
 
65
68
  const streams = [process.stdout, process.stderr];
66
69
 
67
- streams.forEach(stream => {
70
+ streams.forEach((stream) => {
68
71
  // submit empty write request and wait for completion
69
72
  draining += 1;
70
- stream.write('', done);
73
+ stream.write("", done);
71
74
  });
72
75
 
73
76
  done();
@@ -80,8 +83,8 @@ const exitMocha = clampedCode => {
80
83
  * @returns {string[]} Array of strings
81
84
  * @private
82
85
  */
83
- exports.list = str =>
84
- Array.isArray(str) ? exports.list(str.join(',')) : str.split(/ *, */);
86
+ exports.list = (str) =>
87
+ Array.isArray(str) ? exports.list(str.join(",")) : str.split(/ *, */);
85
88
 
86
89
  /**
87
90
  * `require()` the modules as required by `--require <require>`.
@@ -91,26 +94,29 @@ exports.list = str =>
91
94
  * @returns {Promise<object>} Plugin implementations
92
95
  * @private
93
96
  */
94
- exports.handleRequires = async (requires = [], {ignoredPlugins = []} = {}) => {
95
- const pluginLoader = PluginLoader.create({ignore: ignoredPlugins});
97
+ exports.handleRequires = async (
98
+ requires = [],
99
+ { ignoredPlugins = [] } = {},
100
+ ) => {
101
+ const pluginLoader = PluginLoader.create({ ignore: ignoredPlugins });
96
102
  for await (const mod of requires) {
97
103
  let modpath = mod;
98
104
  // this is relative to cwd
99
105
  if (fs.existsSync(mod) || fs.existsSync(`${mod}.js`)) {
100
106
  modpath = path.resolve(mod);
101
- debug('resolved required file %s to %s', mod, modpath);
107
+ debug("resolved required file %s to %s", mod, modpath);
102
108
  }
103
109
  const requiredModule = await requireOrImport(modpath);
104
- if (requiredModule && typeof requiredModule === 'object') {
110
+ if (requiredModule && typeof requiredModule === "object") {
105
111
  if (pluginLoader.load(requiredModule)) {
106
- debug('found one or more plugin implementations in %s', modpath);
112
+ debug("found one or more plugin implementations in %s", modpath);
107
113
  }
108
114
  }
109
115
  debug('loaded required module "%s"', mod);
110
116
  }
111
117
  const plugins = await pluginLoader.finalize();
112
118
  if (Object.keys(plugins).length) {
113
- debug('finalized plugin implementations: %O', plugins);
119
+ debug("finalized plugin implementations: %O", plugins);
114
120
  }
115
121
  return plugins;
116
122
  };
@@ -127,15 +133,15 @@ const handleUnmatchedFiles = (mocha, unmatchedFiles) => {
127
133
  return;
128
134
  }
129
135
 
130
- unmatchedFiles.forEach(({pattern, absolutePath}) => {
136
+ unmatchedFiles.forEach(({ pattern, absolutePath }) => {
131
137
  console.error(
132
138
  pc.yellow(
133
- `Warning: Cannot find any files matching pattern "${pattern}" at the absolute path "${absolutePath}"`
134
- )
139
+ `Warning: Cannot find any files matching pattern "${pattern}" at the absolute path "${absolutePath}"`,
140
+ ),
135
141
  );
136
142
  });
137
143
  console.log(
138
- 'No test file(s) found with the given pattern, exiting with code 1'
144
+ "No test file(s) found with the given pattern, exiting with code 1",
139
145
  );
140
146
 
141
147
  return mocha.run(exitMocha(1));
@@ -152,8 +158,8 @@ const handleUnmatchedFiles = (mocha, unmatchedFiles) => {
152
158
  */
153
159
  const singleRun = async (
154
160
  mocha,
155
- {exit, passOnFailingTestSuite},
156
- fileCollectParams
161
+ { exit, passOnFailingTestSuite },
162
+ fileCollectParams,
157
163
  ) => {
158
164
  const fileCollectionObj = collectFiles(fileCollectParams);
159
165
 
@@ -161,14 +167,12 @@ const singleRun = async (
161
167
  return handleUnmatchedFiles(mocha, fileCollectionObj.unmatchedFiles);
162
168
  }
163
169
 
164
- debug('single run with %d file(s)', fileCollectionObj.files.length);
170
+ debug("single run with %d file(s)", fileCollectionObj.files.length);
165
171
  mocha.files = fileCollectionObj.files;
166
172
 
167
173
  // handles ESM modules
168
174
  await mocha.loadFilesAsync();
169
- return mocha.run(
170
- createExitHandler({exit, passOnFailingTestSuite})
171
- );
175
+ return mocha.run(createExitHandler({ exit, passOnFailingTestSuite }));
172
176
  };
173
177
 
174
178
  /**
@@ -192,15 +196,13 @@ const parallelRun = async (mocha, options, fileCollectParams) => {
192
196
  }
193
197
 
194
198
  debug(
195
- 'executing %d test file(s) in parallel mode',
196
- fileCollectionObj.files.length
199
+ "executing %d test file(s) in parallel mode",
200
+ fileCollectionObj.files.length,
197
201
  );
198
202
  mocha.files = fileCollectionObj.files;
199
203
 
200
204
  // note that we DO NOT load any files here; this is handled by the worker
201
- return mocha.run(
202
- createExitHandler(options)
203
- );
205
+ return mocha.run(createExitHandler(options));
204
206
  };
205
207
 
206
208
  /**
@@ -223,7 +225,7 @@ exports.runMocha = async (mocha, options) => {
223
225
  parallel = false,
224
226
  recursive = false,
225
227
  sort = false,
226
- spec = []
228
+ spec = [],
227
229
  } = options;
228
230
 
229
231
  const fileCollectParams = {
@@ -232,7 +234,7 @@ exports.runMocha = async (mocha, options) => {
232
234
  file,
233
235
  recursive,
234
236
  sort,
235
- spec
237
+ spec,
236
238
  };
237
239
 
238
240
  let run;
@@ -267,15 +269,15 @@ exports.validateLegacyPlugin = (opts, pluginType, map = {}) => {
267
269
  if (Array.isArray(pluginId)) {
268
270
  throw createInvalidLegacyPluginError(
269
271
  `"--${pluginType}" can only be specified once`,
270
- pluginType
272
+ pluginType,
271
273
  );
272
274
  }
273
275
 
274
- const createUnknownError = err =>
276
+ const createUnknownError = (err) =>
275
277
  createInvalidLegacyPluginError(
276
278
  format('Could not load %s "%s":\n\n %O', pluginType, pluginId, err),
277
279
  pluginType,
278
- pluginId
280
+ pluginId,
279
281
  );
280
282
 
281
283
  // if this exists, then it's already loaded, so nothing more to do.
@@ -298,13 +300,9 @@ exports.validateLegacyPlugin = (opts, pluginType, map = {}) => {
298
300
  };
299
301
 
300
302
  const createExitHandler = ({ exit, passOnFailingTestSuite }) => {
301
- return code => {
302
- const clampedCode = passOnFailingTestSuite
303
- ? 0
304
- : Math.min(code, 255);
305
-
306
- return exit
307
- ? exitMocha(clampedCode)
308
- : exitMochaLater(clampedCode);
303
+ return (code) => {
304
+ const clampedCode = passOnFailingTestSuite ? 0 : Math.min(code, 255);
305
+
306
+ return exit ? exitMocha(clampedCode) : exitMochaLater(clampedCode);
309
307
  };
310
308
  };
@@ -1,4 +1,4 @@
1
- 'use strict';
1
+ "use strict";
2
2
 
3
3
  /**
4
4
  * Metadata about various options of the `run` command
@@ -14,54 +14,54 @@
14
14
  */
15
15
  const TYPES = (exports.types = {
16
16
  array: [
17
- 'extension',
18
- 'file',
19
- 'global',
20
- 'ignore',
21
- 'node-option',
22
- 'reporter-option',
23
- 'require',
24
- 'spec',
25
- 'watch-files',
26
- 'watch-ignore'
17
+ "extension",
18
+ "file",
19
+ "global",
20
+ "ignore",
21
+ "node-option",
22
+ "reporter-option",
23
+ "require",
24
+ "spec",
25
+ "watch-files",
26
+ "watch-ignore",
27
27
  ],
28
28
  boolean: [
29
- 'allow-uncaught',
30
- 'async-only',
31
- 'bail',
32
- 'check-leaks',
33
- 'color',
34
- 'delay',
35
- 'diff',
36
- 'dry-run',
37
- 'exit',
38
- 'pass-on-failing-test-suite',
39
- 'fail-zero',
40
- 'forbid-only',
41
- 'forbid-pending',
42
- 'full-trace',
43
- 'inline-diffs',
44
- 'invert',
45
- 'list-interfaces',
46
- 'list-reporters',
47
- 'no-colors',
48
- 'parallel',
49
- 'posix-exit-codes',
50
- 'recursive',
51
- 'sort',
52
- 'watch'
29
+ "allow-uncaught",
30
+ "async-only",
31
+ "bail",
32
+ "check-leaks",
33
+ "color",
34
+ "delay",
35
+ "diff",
36
+ "dry-run",
37
+ "exit",
38
+ "pass-on-failing-test-suite",
39
+ "fail-zero",
40
+ "forbid-only",
41
+ "forbid-pending",
42
+ "full-trace",
43
+ "inline-diffs",
44
+ "invert",
45
+ "list-interfaces",
46
+ "list-reporters",
47
+ "no-colors",
48
+ "parallel",
49
+ "posix-exit-codes",
50
+ "recursive",
51
+ "sort",
52
+ "watch",
53
53
  ],
54
- number: ['retries', 'jobs'],
54
+ number: ["retries", "jobs"],
55
55
  string: [
56
- 'config',
57
- 'fgrep',
58
- 'grep',
59
- 'package',
60
- 'reporter',
61
- 'ui',
62
- 'slow',
63
- 'timeout'
64
- ]
56
+ "config",
57
+ "fgrep",
58
+ "grep",
59
+ "package",
60
+ "reporter",
61
+ "ui",
62
+ "slow",
63
+ "timeout",
64
+ ],
65
65
  });
66
66
 
67
67
  /**
@@ -71,35 +71,35 @@ const TYPES = (exports.types = {
71
71
  * @private
72
72
  */
73
73
  exports.aliases = {
74
- 'async-only': ['A'],
75
- bail: ['b'],
76
- color: ['c', 'colors'],
77
- fgrep: ['f'],
78
- global: ['globals'],
79
- grep: ['g'],
80
- ignore: ['exclude'],
81
- invert: ['i'],
82
- jobs: ['j'],
83
- 'no-colors': ['C'],
84
- 'node-option': ['n'],
85
- parallel: ['p'],
86
- reporter: ['R'],
87
- 'reporter-option': ['reporter-options', 'O'],
88
- require: ['r'],
89
- slow: ['s'],
90
- sort: ['S'],
91
- timeout: ['t', 'timeouts'],
92
- ui: ['u'],
93
- watch: ['w']
74
+ "async-only": ["A"],
75
+ bail: ["b"],
76
+ color: ["c", "colors"],
77
+ fgrep: ["f"],
78
+ global: ["globals"],
79
+ grep: ["g"],
80
+ ignore: ["exclude"],
81
+ invert: ["i"],
82
+ jobs: ["j"],
83
+ "no-colors": ["C"],
84
+ "node-option": ["n"],
85
+ parallel: ["p"],
86
+ reporter: ["R"],
87
+ "reporter-option": ["reporter-options", "O"],
88
+ require: ["r"],
89
+ slow: ["s"],
90
+ sort: ["S"],
91
+ timeout: ["t", "timeouts"],
92
+ ui: ["u"],
93
+ watch: ["w"],
94
94
  };
95
95
 
96
96
  const ALL_MOCHA_FLAGS = Object.keys(TYPES).reduce((acc, key) => {
97
97
  // gets all flags from each of the fields in `types`, adds those,
98
98
  // then adds aliases of each flag (if any)
99
- TYPES[key].forEach(flag => {
99
+ TYPES[key].forEach((flag) => {
100
100
  acc.add(flag);
101
101
  const aliases = exports.aliases[flag] || [];
102
- aliases.forEach(alias => {
102
+ aliases.forEach((alias) => {
103
103
  acc.add(alias);
104
104
  });
105
105
  });
@@ -112,8 +112,8 @@ const ALL_MOCHA_FLAGS = Object.keys(TYPES).reduce((acc, key) => {
112
112
  * @returns {boolean} If `true`, this is a Mocha flag
113
113
  * @private
114
114
  */
115
- exports.isMochaFlag = flag => {
116
- return ALL_MOCHA_FLAGS.has(flag.replace(/^--?/, ''));
115
+ exports.isMochaFlag = (flag) => {
116
+ return ALL_MOCHA_FLAGS.has(flag.replace(/^--?/, ""));
117
117
  };
118
118
 
119
119
  /**
@@ -122,17 +122,17 @@ exports.isMochaFlag = flag => {
122
122
  * @returns {string | undefined} - If flag is a valid mocha flag, the expected type of argument for this flag is returned, otherwise undefined is returned.
123
123
  * @private
124
124
  */
125
- exports.expectedTypeForFlag = flag => {
126
- const normalizedName = flag.replace(/^--?/, '');
125
+ exports.expectedTypeForFlag = (flag) => {
126
+ const normalizedName = flag.replace(/^--?/, "");
127
127
 
128
128
  // If flag is an alias, get it's full name.
129
129
  const aliases = exports.aliases;
130
130
  const fullFlagName =
131
- Object.keys(aliases).find(flagName =>
132
- aliases[flagName].includes(normalizedName)
131
+ Object.keys(aliases).find((flagName) =>
132
+ aliases[flagName].includes(normalizedName),
133
133
  ) || normalizedName;
134
134
 
135
- return Object.keys(TYPES).find(flagType =>
136
- TYPES[flagType].includes(fullFlagName)
135
+ return Object.keys(TYPES).find((flagType) =>
136
+ TYPES[flagType].includes(fullFlagName),
137
137
  );
138
138
  };