mocha 9.2.1 → 9.2.2

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.
@@ -225,18 +225,18 @@ exports.validateLegacyPlugin = (opts, pluginType, map = {}) => {
225
225
 
226
226
  // if this exists, then it's already loaded, so nothing more to do.
227
227
  if (!map[pluginId]) {
228
+ let foundId;
228
229
  try {
229
- map[pluginId] = require(pluginId);
230
+ foundId = require.resolve(pluginId);
231
+ map[pluginId] = require(foundId);
230
232
  } catch (err) {
231
- if (err.code === 'MODULE_NOT_FOUND') {
232
- // Try to load reporters from a path (absolute or relative)
233
- try {
234
- map[pluginId] = require(path.resolve(pluginId));
235
- } catch (err) {
236
- throw createUnknownError(err);
237
- }
238
- } else {
239
- throw createUnknownError(err);
233
+ if (foundId) throw createUnknownError(err);
234
+
235
+ // Try to load reporters from a cwd-relative path
236
+ try {
237
+ map[pluginId] = require(path.resolve(pluginId));
238
+ } catch (e) {
239
+ throw createUnknownError(e);
240
240
  }
241
241
  }
242
242
  }
package/lib/mocha.js CHANGED
@@ -16,7 +16,6 @@ var Suite = require('./suite');
16
16
  var esmUtils = require('./nodejs/esm-utils');
17
17
  var createStatsCollector = require('./stats-collector');
18
18
  const {
19
- warn,
20
19
  createInvalidReporterError,
21
20
  createInvalidInterfaceError,
22
21
  createMochaInstanceAlreadyDisposedError,
@@ -335,35 +334,26 @@ Mocha.prototype.reporter = function (reporterName, reporterOptions) {
335
334
  }
336
335
  // Try to load reporters from process.cwd() and node_modules
337
336
  if (!reporter) {
337
+ let foundReporter;
338
338
  try {
339
- reporter = require(reporterName);
339
+ foundReporter = require.resolve(reporterName);
340
+ reporter = require(foundReporter);
340
341
  } catch (err) {
341
- if (err.code === 'MODULE_NOT_FOUND') {
342
- // Try to load reporters from a path (absolute or relative)
343
- try {
344
- reporter = require(path.resolve(utils.cwd(), reporterName));
345
- } catch (_err) {
346
- _err.code === 'MODULE_NOT_FOUND'
347
- ? warn(`'${reporterName}' reporter not found`)
348
- : warn(
349
- `'${reporterName}' reporter blew up with error:\n ${err.stack}`
350
- );
351
- }
352
- } else {
353
- warn(`'${reporterName}' reporter blew up with error:\n ${err.stack}`);
342
+ if (foundReporter) {
343
+ throw createInvalidReporterError(err.message, foundReporter);
344
+ }
345
+ // Try to load reporters from a cwd-relative path
346
+ try {
347
+ reporter = require(path.resolve(reporterName));
348
+ } catch (e) {
349
+ throw createInvalidReporterError(e.message, reporterName);
354
350
  }
355
351
  }
356
352
  }
357
- if (!reporter) {
358
- throw createInvalidReporterError(
359
- `invalid reporter '${reporterName}'`,
360
- reporterName
361
- );
362
- }
363
353
  this._reporter = reporter;
364
354
  }
365
355
  this.options.reporterOption = reporterOptions;
366
- // alias option name is used in public reporters xunit/tap/progress
356
+ // alias option name is used in built-in reporters xunit/tap/progress
367
357
  this.options.reporterOptions = reporterOptions;
368
358
  return this;
369
359
  };
package/lib/runner.js CHANGED
@@ -655,7 +655,7 @@ Runner.prototype.parents = function () {
655
655
  * @private
656
656
  */
657
657
  Runner.prototype.runTest = function (fn) {
658
- if (this._opts.dryRun) return fn();
658
+ if (this._opts.dryRun) return Runner.immediately(fn);
659
659
 
660
660
  var self = this;
661
661
  var test = this.test;
package/mocha-es2018.js CHANGED
@@ -1,4 +1,4 @@
1
- // mocha@9.2.1 in javascript ES2018
1
+ // mocha@9.2.2 in javascript ES2018
2
2
  (function (global, factory) {
3
3
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
4
4
  typeof define === 'function' && define.amd ? define(factory) :
@@ -9427,8 +9427,8 @@
9427
9427
 
9428
9428
  let urlAlphabet =
9429
9429
  'useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict';
9430
- let customAlphabet = (alphabet, size) => {
9431
- return () => {
9430
+ let customAlphabet = (alphabet, defaultSize = 21) => {
9431
+ return (size = defaultSize) => {
9432
9432
  let id = '';
9433
9433
  let i = size;
9434
9434
  while (i--) {
@@ -13609,7 +13609,7 @@
13609
13609
  * @private
13610
13610
  */
13611
13611
  Runner.prototype.runTest = function (fn) {
13612
- if (this._opts.dryRun) return fn();
13612
+ if (this._opts.dryRun) return Runner.immediately(fn);
13613
13613
 
13614
13614
  var self = this;
13615
13615
  var test = this.test;
@@ -16500,9 +16500,14 @@
16500
16500
 
16501
16501
  if (options && options.reporterOptions) {
16502
16502
  if (options.reporterOptions.output) {
16503
- {
16503
+ if (!fs.createWriteStream) {
16504
16504
  throw createUnsupportedError('file output not supported in browser');
16505
16505
  }
16506
+
16507
+ fs.mkdirSync(path.dirname(options.reporterOptions.output), {
16508
+ recursive: true
16509
+ });
16510
+ self.fileStream = fs.createWriteStream(options.reporterOptions.output);
16506
16511
  }
16507
16512
 
16508
16513
  // get the suite name from the reporter options (if provided)
@@ -17109,7 +17114,7 @@
17109
17114
  });
17110
17115
 
17111
17116
  var name = "mocha";
17112
- var version = "9.2.1";
17117
+ var version = "9.2.2";
17113
17118
  var homepage = "https://mochajs.org/";
17114
17119
  var notifyLogo = "https://ibin.co/4QuRuGjXvl36.png";
17115
17120
  var _package = {
@@ -18213,7 +18218,6 @@
18213
18218
 
18214
18219
 
18215
18220
  const {
18216
- warn,
18217
18221
  createInvalidReporterError,
18218
18222
  createInvalidInterfaceError,
18219
18223
  createMochaInstanceAlreadyDisposedError,
@@ -18532,35 +18536,26 @@
18532
18536
  }
18533
18537
  // Try to load reporters from process.cwd() and node_modules
18534
18538
  if (!reporter) {
18539
+ let foundReporter;
18535
18540
  try {
18536
- reporter = commonjsRequire(reporterName);
18541
+ foundReporter = require.resolve(reporterName);
18542
+ reporter = commonjsRequire(foundReporter);
18537
18543
  } catch (err) {
18538
- if (err.code === 'MODULE_NOT_FOUND') {
18539
- // Try to load reporters from a path (absolute or relative)
18540
- try {
18541
- reporter = commonjsRequire(path.resolve(utils.cwd(), reporterName));
18542
- } catch (_err) {
18543
- _err.code === 'MODULE_NOT_FOUND'
18544
- ? warn(`'${reporterName}' reporter not found`)
18545
- : warn(
18546
- `'${reporterName}' reporter blew up with error:\n ${err.stack}`
18547
- );
18548
- }
18549
- } else {
18550
- warn(`'${reporterName}' reporter blew up with error:\n ${err.stack}`);
18544
+ if (foundReporter) {
18545
+ throw createInvalidReporterError(err.message, foundReporter);
18546
+ }
18547
+ // Try to load reporters from a cwd-relative path
18548
+ try {
18549
+ reporter = commonjsRequire(path.resolve(reporterName));
18550
+ } catch (e) {
18551
+ throw createInvalidReporterError(e.message, reporterName);
18551
18552
  }
18552
18553
  }
18553
18554
  }
18554
- if (!reporter) {
18555
- throw createInvalidReporterError(
18556
- `invalid reporter '${reporterName}'`,
18557
- reporterName
18558
- );
18559
- }
18560
18555
  this._reporter = reporter;
18561
18556
  }
18562
18557
  this.options.reporterOption = reporterOptions;
18563
- // alias option name is used in public reporters xunit/tap/progress
18558
+ // alias option name is used in built-in reporters xunit/tap/progress
18564
18559
  this.options.reporterOptions = reporterOptions;
18565
18560
  return this;
18566
18561
  };