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/errors.js CHANGED
@@ -1,4 +1,4 @@
1
- 'use strict';
1
+ "use strict";
2
2
 
3
3
  /**
4
4
  * @typedef {import('./mocha.js')} Mocha
@@ -7,8 +7,8 @@
7
7
  * @typedef {import('./types.d.ts').PluginDefinition} PluginDefinition
8
8
  */
9
9
 
10
- const {format} = require('node:util');
11
- const { constants } = require('./error-constants.js');
10
+ const { format } = require("node:util");
11
+ const { constants } = require("./error-constants.js");
12
12
 
13
13
  /**
14
14
  * Contains error codes, factory functions to create throwable error objects,
@@ -27,7 +27,7 @@ const emitWarning = (msg, type) => {
27
27
  } else {
28
28
  /* istanbul ignore next */
29
29
  process.nextTick(function () {
30
- console.warn(type + ': ' + msg);
30
+ console.warn(type + ": " + msg);
31
31
  });
32
32
  }
33
33
  };
@@ -39,11 +39,11 @@ const emitWarning = (msg, type) => {
39
39
  * @param {string} [msg] - Warning to print
40
40
  * @private
41
41
  */
42
- const deprecate = msg => {
42
+ const deprecate = (msg) => {
43
43
  msg = String(msg);
44
44
  if (msg && !deprecate.cache[msg]) {
45
45
  deprecate.cache[msg] = true;
46
- emitWarning(msg, 'DeprecationWarning');
46
+ emitWarning(msg, "DeprecationWarning");
47
47
  }
48
48
  };
49
49
  deprecate.cache = {};
@@ -55,7 +55,7 @@ deprecate.cache = {};
55
55
  * @param {string} [msg] - Warning to print
56
56
  * @private
57
57
  */
58
- const warn = msg => {
58
+ const warn = (msg) => {
59
59
  if (msg) {
60
60
  emitWarning(msg);
61
61
  }
@@ -177,7 +177,7 @@ function createInvalidArgumentValueError(message, argument, value, reason) {
177
177
  err.code = constants.INVALID_ARG_VALUE;
178
178
  err.argument = argument;
179
179
  err.value = value;
180
- err.reason = typeof reason !== 'undefined' ? reason : 'is invalid';
180
+ err.reason = typeof reason !== "undefined" ? reason : "is invalid";
181
181
  return err;
182
182
  }
183
183
 
@@ -225,9 +225,9 @@ function createFatalError(message, value) {
225
225
  */
226
226
  function createInvalidLegacyPluginError(message, pluginType, pluginId) {
227
227
  switch (pluginType) {
228
- case 'reporter':
228
+ case "reporter":
229
229
  return createInvalidReporterError(message, pluginId);
230
- case 'ui':
230
+ case "ui":
231
231
  return createInvalidInterfaceError(message, pluginId);
232
232
  default:
233
233
  throw new Error('unknown pluginType "' + pluginType + '"');
@@ -246,7 +246,7 @@ function createInvalidLegacyPluginError(message, pluginType, pluginId) {
246
246
  * @returns {Error}
247
247
  */
248
248
  function createInvalidPluginError(...args) {
249
- deprecate('Use createInvalidLegacyPluginError() instead');
249
+ deprecate("Use createInvalidLegacyPluginError() instead");
250
250
  return createInvalidLegacyPluginError(...args);
251
251
  }
252
252
 
@@ -260,7 +260,7 @@ function createInvalidPluginError(...args) {
260
260
  function createMochaInstanceAlreadyDisposedError(
261
261
  message,
262
262
  cleanReferencesAfterRun,
263
- instance
263
+ instance,
264
264
  ) {
265
265
  var err = new Error(message);
266
266
  err.code = constants.INSTANCE_ALREADY_DISPOSED;
@@ -294,23 +294,23 @@ function createMochaInstanceAlreadyRunningError(message, instance) {
294
294
  function createMultipleDoneError(runnable, originalErr) {
295
295
  var title;
296
296
  try {
297
- title = format('<%s>', runnable.fullTitle());
297
+ title = format("<%s>", runnable.fullTitle());
298
298
  if (runnable.parent.root) {
299
- title += ' (of root suite)';
299
+ title += " (of root suite)";
300
300
  }
301
301
  } catch (ignored) {
302
- title = format('<%s> (of unknown suite)', runnable.title);
302
+ title = format("<%s> (of unknown suite)", runnable.title);
303
303
  }
304
304
  var message = format(
305
- 'done() called multiple times in %s %s',
306
- runnable.type ? runnable.type : 'unknown runnable',
307
- title
305
+ "done() called multiple times in %s %s",
306
+ runnable.type ? runnable.type : "unknown runnable",
307
+ title,
308
308
  );
309
309
  if (runnable.file) {
310
- message += format(' of file %s', runnable.file);
310
+ message += format(" of file %s", runnable.file);
311
311
  }
312
312
  if (originalErr) {
313
- message += format('; in addition, done() received error: %s', originalErr);
313
+ message += format("; in addition, done() received error: %s", originalErr);
314
314
  }
315
315
 
316
316
  var err = new Error(message);
@@ -331,8 +331,8 @@ function createMultipleDoneError(runnable, originalErr) {
331
331
  function createForbiddenExclusivityError(mocha) {
332
332
  var err = new Error(
333
333
  mocha.isWorker
334
- ? '`.only` is not supported in parallel mode'
335
- : '`.only` forbidden by --forbid-only'
334
+ ? "`.only` is not supported in parallel mode"
335
+ : "`.only` forbidden by --forbid-only",
336
336
  );
337
337
  err.code = constants.FORBIDDEN_EXCLUSIVITY;
338
338
  return err;
@@ -365,7 +365,7 @@ function createInvalidPluginDefinitionError(msg, pluginDef) {
365
365
  */
366
366
  function createInvalidPluginImplementationError(
367
367
  msg,
368
- {pluginDef, pluginImpl} = {}
368
+ { pluginDef, pluginImpl } = {},
369
369
  ) {
370
370
  const err = new Error(msg);
371
371
  err.code = constants.INVALID_PLUGIN_IMPLEMENTATION;
@@ -411,8 +411,8 @@ function createUnparsableFileError(message) {
411
411
  * @param {*} err - Error, or anything
412
412
  * @returns {boolean}
413
413
  */
414
- const isMochaError = err =>
415
- Boolean(err && typeof err === 'object' && MOCHA_ERRORS.has(err.code));
414
+ const isMochaError = (err) =>
415
+ Boolean(err && typeof err === "object" && MOCHA_ERRORS.has(err.code));
416
416
 
417
417
  module.exports = {
418
418
  createFatalError,
@@ -436,5 +436,5 @@ module.exports = {
436
436
  createUnsupportedError,
437
437
  deprecate,
438
438
  isMochaError,
439
- warn
439
+ warn,
440
440
  };
package/lib/hook.js CHANGED
@@ -1,8 +1,8 @@
1
- 'use strict';
1
+ "use strict";
2
2
 
3
- var Runnable = require('./runnable');
4
- const {inherits, constants} = require('./utils');
5
- const {MOCHA_ID_PROP_NAME} = constants;
3
+ var Runnable = require("./runnable");
4
+ const { inherits, constants } = require("./utils");
5
+ const { MOCHA_ID_PROP_NAME } = constants;
6
6
 
7
7
  /**
8
8
  * Expose `Hook`.
@@ -20,7 +20,7 @@ module.exports = Hook;
20
20
  */
21
21
  function Hook(title, fn) {
22
22
  Runnable.call(this, title, fn);
23
- this.type = 'hook';
23
+ this.type = "hook";
24
24
  }
25
25
 
26
26
  /**
@@ -71,19 +71,19 @@ Hook.prototype.serialize = function serialize() {
71
71
  ? {
72
72
  currentTest: {
73
73
  title: this.ctx.currentTest.title,
74
- [MOCHA_ID_PROP_NAME]: this.ctx.currentTest.id
75
- }
74
+ [MOCHA_ID_PROP_NAME]: this.ctx.currentTest.id,
75
+ },
76
76
  }
77
77
  : {},
78
78
  duration: this.duration,
79
79
  file: this.file,
80
80
  parent: {
81
81
  $$fullTitle: this.parent.fullTitle(),
82
- [MOCHA_ID_PROP_NAME]: this.parent.id
82
+ [MOCHA_ID_PROP_NAME]: this.parent.id,
83
83
  },
84
84
  state: this.state,
85
85
  title: this.title,
86
86
  type: this.type,
87
- [MOCHA_ID_PROP_NAME]: this.id
87
+ [MOCHA_ID_PROP_NAME]: this.id,
88
88
  };
89
89
  };
@@ -1,12 +1,12 @@
1
- 'use strict';
1
+ "use strict";
2
2
 
3
3
  /**
4
4
  * @typedef {import('../suite.js')} Suite
5
5
  */
6
6
 
7
- var Test = require('../test');
7
+ var Test = require("../test");
8
8
  var EVENT_FILE_PRE_REQUIRE =
9
- require('../suite').constants.EVENT_FILE_PRE_REQUIRE;
9
+ require("../suite").constants.EVENT_FILE_PRE_REQUIRE;
10
10
 
11
11
  /**
12
12
  * BDD-style interface:
@@ -29,7 +29,7 @@ module.exports = function bddInterface(suite) {
29
29
  var suites = [suite];
30
30
 
31
31
  suite.on(EVENT_FILE_PRE_REQUIRE, function (context, file, mocha) {
32
- var common = require('./common')(suites, context, mocha);
32
+ var common = require("./common")(suites, context, mocha);
33
33
 
34
34
  context.before = common.before;
35
35
  context.after = common.after;
@@ -46,7 +46,7 @@ module.exports = function bddInterface(suite) {
46
46
  return common.suite.create({
47
47
  title,
48
48
  file,
49
- fn
49
+ fn,
50
50
  });
51
51
  };
52
52
 
@@ -61,7 +61,7 @@ module.exports = function bddInterface(suite) {
61
61
  return common.suite.skip({
62
62
  title,
63
63
  file,
64
- fn
64
+ fn,
65
65
  });
66
66
  };
67
67
 
@@ -73,7 +73,7 @@ module.exports = function bddInterface(suite) {
73
73
  return common.suite.only({
74
74
  title,
75
75
  file,
76
- fn
76
+ fn,
77
77
  });
78
78
  };
79
79
 
@@ -115,4 +115,4 @@ module.exports = function bddInterface(suite) {
115
115
  });
116
116
  };
117
117
 
118
- module.exports.description = 'BDD or RSpec style [default]';
118
+ module.exports.description = "BDD or RSpec style [default]";
@@ -1,4 +1,4 @@
1
- 'use strict';
1
+ "use strict";
2
2
 
3
3
  /**
4
4
  * @typedef {import('../context.js')} Context
@@ -9,8 +9,8 @@
9
9
  @module interfaces/common
10
10
  */
11
11
 
12
- var Suite = require('../suite');
13
- var errors = require('../errors');
12
+ var Suite = require("../suite");
13
+ var errors = require("../errors");
14
14
  var createMissingArgumentError = errors.createMissingArgumentError;
15
15
  var createUnsupportedError = errors.createUnsupportedError;
16
16
  var createForbiddenExclusivityError = errors.createForbiddenExclusivityError;
@@ -147,26 +147,26 @@ module.exports = function (suites, context, mocha) {
147
147
  mocha.options.forbidPending &&
148
148
  shouldBeTested(suite)
149
149
  ) {
150
- throw createUnsupportedError('Pending test forbidden');
150
+ throw createUnsupportedError("Pending test forbidden");
151
151
  }
152
- if (typeof opts.fn === 'function') {
152
+ if (typeof opts.fn === "function") {
153
153
  opts.fn.call(suite);
154
154
  suites.shift();
155
- } else if (typeof opts.fn === 'undefined' && !suite.pending) {
155
+ } else if (typeof opts.fn === "undefined" && !suite.pending) {
156
156
  throw createMissingArgumentError(
157
157
  'Suite "' +
158
158
  suite.fullTitle() +
159
159
  '" was defined but no callback was supplied. ' +
160
- 'Supply a callback or explicitly skip the suite.',
161
- 'callback',
162
- 'function'
160
+ "Supply a callback or explicitly skip the suite.",
161
+ "callback",
162
+ "function",
163
163
  );
164
164
  } else if (!opts.fn && suite.pending) {
165
165
  suites.shift();
166
166
  }
167
167
 
168
168
  return suite;
169
- }
169
+ },
170
170
  },
171
171
 
172
172
  test: {
@@ -192,7 +192,7 @@ module.exports = function (suites, context, mocha) {
192
192
  */
193
193
  skip: function (title) {
194
194
  context.test(title);
195
- }
196
- }
195
+ },
196
+ },
197
197
  };
198
198
  };
@@ -1,6 +1,6 @@
1
- 'use strict';
2
- var Suite = require('../suite');
3
- var Test = require('../test');
1
+ "use strict";
2
+ var Suite = require("../suite");
3
+ var Test = require("../test");
4
4
 
5
5
  /**
6
6
  * Exports-style (as Node.js module) interface:
@@ -27,19 +27,19 @@ module.exports = function (suite) {
27
27
  function visit(obj, file) {
28
28
  var suite;
29
29
  for (var key in obj) {
30
- if (typeof obj[key] === 'function') {
30
+ if (typeof obj[key] === "function") {
31
31
  var fn = obj[key];
32
32
  switch (key) {
33
- case 'before':
33
+ case "before":
34
34
  suites[0].beforeAll(fn);
35
35
  break;
36
- case 'after':
36
+ case "after":
37
37
  suites[0].afterAll(fn);
38
38
  break;
39
- case 'beforeEach':
39
+ case "beforeEach":
40
40
  suites[0].beforeEach(fn);
41
41
  break;
42
- case 'afterEach':
42
+ case "afterEach":
43
43
  suites[0].afterEach(fn);
44
44
  break;
45
45
  default:
@@ -1,6 +1,6 @@
1
- 'use strict';
1
+ "use strict";
2
2
 
3
- exports.bdd = require('./bdd');
4
- exports.tdd = require('./tdd');
5
- exports.qunit = require('./qunit');
6
- exports.exports = require('./exports');
3
+ exports.bdd = require("./bdd");
4
+ exports.tdd = require("./tdd");
5
+ exports.qunit = require("./qunit");
6
+ exports.exports = require("./exports");
@@ -1,11 +1,11 @@
1
- 'use strict';
1
+ "use strict";
2
2
  /**
3
3
  * @typedef {import('../suite.js')} Suite
4
4
  */
5
5
 
6
- var Test = require('../test');
6
+ var Test = require("../test");
7
7
  var EVENT_FILE_PRE_REQUIRE =
8
- require('../suite').constants.EVENT_FILE_PRE_REQUIRE;
8
+ require("../suite").constants.EVENT_FILE_PRE_REQUIRE;
9
9
 
10
10
  /**
11
11
  * QUnit-style interface:
@@ -36,7 +36,7 @@ module.exports = function qUnitInterface(suite) {
36
36
  var suites = [suite];
37
37
 
38
38
  suite.on(EVENT_FILE_PRE_REQUIRE, function (context, file, mocha) {
39
- var common = require('./common')(suites, context, mocha);
39
+ var common = require("./common")(suites, context, mocha);
40
40
 
41
41
  context.before = common.before;
42
42
  context.after = common.after;
@@ -54,7 +54,7 @@ module.exports = function qUnitInterface(suite) {
54
54
  return common.suite.create({
55
55
  title,
56
56
  file,
57
- fn: false
57
+ fn: false,
58
58
  });
59
59
  };
60
60
 
@@ -69,7 +69,7 @@ module.exports = function qUnitInterface(suite) {
69
69
  return common.suite.only({
70
70
  title,
71
71
  file,
72
- fn: false
72
+ fn: false,
73
73
  });
74
74
  };
75
75
 
@@ -98,4 +98,4 @@ module.exports = function qUnitInterface(suite) {
98
98
  });
99
99
  };
100
100
 
101
- module.exports.description = 'QUnit style';
101
+ module.exports.description = "QUnit style";
@@ -1,12 +1,12 @@
1
- 'use strict';
1
+ "use strict";
2
2
 
3
3
  /**
4
4
  * @typedef {import('../suite.js')} Suite
5
5
  */
6
6
 
7
- var Test = require('../test');
7
+ var Test = require("../test");
8
8
  var EVENT_FILE_PRE_REQUIRE =
9
- require('../suite').constants.EVENT_FILE_PRE_REQUIRE;
9
+ require("../suite").constants.EVENT_FILE_PRE_REQUIRE;
10
10
 
11
11
  /**
12
12
  * TDD-style interface:
@@ -37,7 +37,7 @@ module.exports = function (suite) {
37
37
  var suites = [suite];
38
38
 
39
39
  suite.on(EVENT_FILE_PRE_REQUIRE, function (context, file, mocha) {
40
- var common = require('./common')(suites, context, mocha);
40
+ var common = require("./common")(suites, context, mocha);
41
41
 
42
42
  context.setup = common.beforeEach;
43
43
  context.teardown = common.afterEach;
@@ -53,7 +53,7 @@ module.exports = function (suite) {
53
53
  return common.suite.create({
54
54
  title,
55
55
  file,
56
- fn
56
+ fn,
57
57
  });
58
58
  };
59
59
 
@@ -64,7 +64,7 @@ module.exports = function (suite) {
64
64
  return common.suite.skip({
65
65
  title,
66
66
  file,
67
- fn
67
+ fn,
68
68
  });
69
69
  };
70
70
 
@@ -75,7 +75,7 @@ module.exports = function (suite) {
75
75
  return common.suite.only({
76
76
  title,
77
77
  file,
78
- fn
78
+ fn,
79
79
  });
80
80
  };
81
81