mocha 9.2.0 → 9.2.1

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.
package/lib/cli/config.js CHANGED
@@ -30,10 +30,6 @@ exports.CONFIG_FILES = [
30
30
  '.mocharc.json'
31
31
  ];
32
32
 
33
- const isModuleNotFoundError = err =>
34
- err.code === 'MODULE_NOT_FOUND' ||
35
- err.message.indexOf('Cannot find module') !== -1;
36
-
37
33
  /**
38
34
  * Parsers for various config filetypes. Each accepts a filepath and
39
35
  * returns an object (but could throw)
@@ -41,17 +37,16 @@ const isModuleNotFoundError = err =>
41
37
  const parsers = (exports.parsers = {
42
38
  yaml: filepath => require('js-yaml').load(fs.readFileSync(filepath, 'utf8')),
43
39
  js: filepath => {
44
- const cwdFilepath = path.resolve(filepath);
40
+ let cwdFilepath;
45
41
  try {
46
- debug('parsers: load using cwd-relative path: "%s"', cwdFilepath);
42
+ debug('parsers: load cwd-relative path: "%s"', path.resolve(filepath));
43
+ cwdFilepath = require.resolve(path.resolve(filepath)); // evtl. throws
47
44
  return require(cwdFilepath);
48
45
  } catch (err) {
49
- if (isModuleNotFoundError(err)) {
50
- debug('parsers: retry load as module-relative path: "%s"', filepath);
51
- return require(filepath);
52
- } else {
53
- throw err; // rethrow
54
- }
46
+ if (cwdFilepath) throw err;
47
+
48
+ debug('parsers: retry load as module-relative path: "%s"', filepath);
49
+ return require(filepath);
55
50
  }
56
51
  },
57
52
  json: filepath =>
@@ -56,6 +56,11 @@ exports.useColors =
56
56
 
57
57
  exports.inlineDiffs = false;
58
58
 
59
+ /**
60
+ * Truncate diffs longer than this value to avoid slow performance
61
+ */
62
+ exports.maxDiffSize = 8192;
63
+
59
64
  /**
60
65
  * Default color map.
61
66
  */
@@ -188,18 +193,23 @@ function stringifyDiffObjs(err) {
188
193
  * @param {string} expected
189
194
  * @return {string} Diff
190
195
  */
196
+
191
197
  var generateDiff = (exports.generateDiff = function (actual, expected) {
192
198
  try {
193
- const diffSize = 2048;
194
- if (actual.length > diffSize) {
195
- actual = actual.substring(0, diffSize) + ' ... Lines skipped';
199
+ var maxLen = exports.maxDiffSize;
200
+ var skipped = 0;
201
+ if (maxLen > 0) {
202
+ skipped = Math.max(actual.length - maxLen, expected.length - maxLen);
203
+ actual = actual.slice(0, maxLen);
204
+ expected = expected.slice(0, maxLen);
196
205
  }
197
- if (expected.length > diffSize) {
198
- expected = expected.substring(0, diffSize) + ' ... Lines skipped';
199
- }
200
- return exports.inlineDiffs
206
+ let result = exports.inlineDiffs
201
207
  ? inlineDiff(actual, expected)
202
208
  : unifiedDiff(actual, expected);
209
+ if (skipped > 0) {
210
+ result = `${result}\n [mocha] output truncated to ${maxLen} characters, see "maxDiffSize" reporter-option\n`;
211
+ }
212
+ return result;
203
213
  } catch (err) {
204
214
  var msg =
205
215
  '\n ' +
@@ -318,6 +328,12 @@ function Base(runner, options) {
318
328
  this.runner = runner;
319
329
  this.stats = runner.stats; // assigned so Reporters keep a closer reference
320
330
 
331
+ var maxDiffSizeOpt =
332
+ this.options.reporterOption && this.options.reporterOption.maxDiffSize;
333
+ if (maxDiffSizeOpt !== undefined && !isNaN(Number(maxDiffSizeOpt))) {
334
+ exports.maxDiffSize = Number(maxDiffSizeOpt);
335
+ }
336
+
321
337
  runner.on(EVENT_TEST_PASS, function (test) {
322
338
  if (test.duration > test.slow()) {
323
339
  test.speed = 'slow';
package/mocha-es2018.js CHANGED
@@ -1,4 +1,4 @@
1
- // mocha@9.2.0 in javascript ES2018
1
+ // mocha@9.2.1 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) :
@@ -14279,6 +14279,11 @@
14279
14279
 
14280
14280
  exports.inlineDiffs = false;
14281
14281
 
14282
+ /**
14283
+ * Truncate diffs longer than this value to avoid slow performance
14284
+ */
14285
+ exports.maxDiffSize = 8192;
14286
+
14282
14287
  /**
14283
14288
  * Default color map.
14284
14289
  */
@@ -14411,18 +14416,23 @@
14411
14416
  * @param {string} expected
14412
14417
  * @return {string} Diff
14413
14418
  */
14419
+
14414
14420
  var generateDiff = (exports.generateDiff = function (actual, expected) {
14415
14421
  try {
14416
- const diffSize = 2048;
14417
- if (actual.length > diffSize) {
14418
- actual = actual.substring(0, diffSize) + ' ... Lines skipped';
14419
- }
14420
- if (expected.length > diffSize) {
14421
- expected = expected.substring(0, diffSize) + ' ... Lines skipped';
14422
- }
14423
- return exports.inlineDiffs
14422
+ var maxLen = exports.maxDiffSize;
14423
+ var skipped = 0;
14424
+ if (maxLen > 0) {
14425
+ skipped = Math.max(actual.length - maxLen, expected.length - maxLen);
14426
+ actual = actual.slice(0, maxLen);
14427
+ expected = expected.slice(0, maxLen);
14428
+ }
14429
+ let result = exports.inlineDiffs
14424
14430
  ? inlineDiff(actual, expected)
14425
14431
  : unifiedDiff(actual, expected);
14432
+ if (skipped > 0) {
14433
+ result = `${result}\n [mocha] output truncated to ${maxLen} characters, see "maxDiffSize" reporter-option\n`;
14434
+ }
14435
+ return result;
14426
14436
  } catch (err) {
14427
14437
  var msg =
14428
14438
  '\n ' +
@@ -14541,6 +14551,12 @@
14541
14551
  this.runner = runner;
14542
14552
  this.stats = runner.stats; // assigned so Reporters keep a closer reference
14543
14553
 
14554
+ var maxDiffSizeOpt =
14555
+ this.options.reporterOption && this.options.reporterOption.maxDiffSize;
14556
+ if (maxDiffSizeOpt !== undefined && !isNaN(Number(maxDiffSizeOpt))) {
14557
+ exports.maxDiffSize = Number(maxDiffSizeOpt);
14558
+ }
14559
+
14544
14560
  runner.on(EVENT_TEST_PASS, function (test) {
14545
14561
  if (test.duration > test.slow()) {
14546
14562
  test.speed = 'slow';
@@ -17093,7 +17109,7 @@
17093
17109
  });
17094
17110
 
17095
17111
  var name = "mocha";
17096
- var version = "9.2.0";
17112
+ var version = "9.2.1";
17097
17113
  var homepage = "https://mochajs.org/";
17098
17114
  var notifyLogo = "https://ibin.co/4QuRuGjXvl36.png";
17099
17115
  var _package = {
package/mocha.js CHANGED
@@ -1,4 +1,4 @@
1
- // mocha@9.2.0 transpiled to javascript ES5
1
+ // mocha@9.2.1 transpiled to javascript ES5
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) :
@@ -25532,6 +25532,11 @@
25532
25532
  */
25533
25533
 
25534
25534
  exports.inlineDiffs = false;
25535
+ /**
25536
+ * Truncate diffs longer than this value to avoid slow performance
25537
+ */
25538
+
25539
+ exports.maxDiffSize = 8192;
25535
25540
  /**
25536
25541
  * Default color map.
25537
25542
  */
@@ -25658,17 +25663,22 @@
25658
25663
 
25659
25664
  var generateDiff = exports.generateDiff = function (actual, expected) {
25660
25665
  try {
25661
- var diffSize = 2048;
25666
+ var maxLen = exports.maxDiffSize;
25667
+ var skipped = 0;
25662
25668
 
25663
- if (actual.length > diffSize) {
25664
- actual = actual.substring(0, diffSize) + ' ... Lines skipped';
25669
+ if (maxLen > 0) {
25670
+ skipped = Math.max(actual.length - maxLen, expected.length - maxLen);
25671
+ actual = actual.slice(0, maxLen);
25672
+ expected = expected.slice(0, maxLen);
25665
25673
  }
25666
25674
 
25667
- if (expected.length > diffSize) {
25668
- expected = expected.substring(0, diffSize) + ' ... Lines skipped';
25675
+ var result = exports.inlineDiffs ? inlineDiff(actual, expected) : unifiedDiff(actual, expected);
25676
+
25677
+ if (skipped > 0) {
25678
+ result = "".concat(result, "\n [mocha] output truncated to ").concat(maxLen, " characters, see \"maxDiffSize\" reporter-option\n");
25669
25679
  }
25670
25680
 
25671
- return exports.inlineDiffs ? inlineDiff(actual, expected) : unifiedDiff(actual, expected);
25681
+ return result;
25672
25682
  } catch (err) {
25673
25683
  var msg = '\n ' + color('diff added', '+ expected') + ' ' + color('diff removed', '- actual: failed to generate Mocha diff') + '\n';
25674
25684
  return msg;
@@ -25785,6 +25795,12 @@
25785
25795
  this.runner = runner;
25786
25796
  this.stats = runner.stats; // assigned so Reporters keep a closer reference
25787
25797
 
25798
+ var maxDiffSizeOpt = this.options.reporterOption && this.options.reporterOption.maxDiffSize;
25799
+
25800
+ if (maxDiffSizeOpt !== undefined && !isNaN(Number(maxDiffSizeOpt))) {
25801
+ exports.maxDiffSize = Number(maxDiffSizeOpt);
25802
+ }
25803
+
25788
25804
  runner.on(EVENT_TEST_PASS, function (test) {
25789
25805
  if (test.duration > test.slow()) {
25790
25806
  test.speed = 'slow';
@@ -28308,7 +28324,7 @@
28308
28324
  });
28309
28325
 
28310
28326
  var name = "mocha";
28311
- var version = "9.2.0";
28327
+ var version = "9.2.1";
28312
28328
  var homepage = "https://mochajs.org/";
28313
28329
  var notifyLogo = "https://ibin.co/4QuRuGjXvl36.png";
28314
28330
  var _package = {