mocha 10.3.0 → 10.5.0

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/mocha.js CHANGED
@@ -1,4 +1,4 @@
1
- // mocha@10.3.0 in javascript ES2018
1
+ // mocha@10.5.0 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) :
@@ -14433,11 +14433,22 @@
14433
14433
  err = thrown2Error(err);
14434
14434
  }
14435
14435
 
14436
- try {
14437
- err.stack =
14438
- this.fullStackTrace || !err.stack ? err.stack : stackFilter(err.stack);
14439
- } catch (ignore) {
14440
- // some environments do not take kindly to monkeying with the stack
14436
+ // Filter the stack traces
14437
+ if (!this.fullStackTrace) {
14438
+ const alreadyFiltered = new Set();
14439
+ let currentErr = err;
14440
+
14441
+ while (currentErr && currentErr.stack && !alreadyFiltered.has(currentErr)) {
14442
+ alreadyFiltered.add(currentErr);
14443
+
14444
+ try {
14445
+ currentErr.stack = stackFilter(currentErr.stack);
14446
+ } catch (ignore) {
14447
+ // some environments do not take kindly to monkeying with the stack
14448
+ }
14449
+
14450
+ currentErr = currentErr.cause;
14451
+ }
14441
14452
  }
14442
14453
 
14443
14454
  this.emit(constants$1.EVENT_TEST_FAIL, test, err);
@@ -15468,6 +15479,56 @@
15468
15479
  }
15469
15480
  });
15470
15481
 
15482
+ /**
15483
+ * Traverses err.cause and returns all stack traces
15484
+ *
15485
+ * @private
15486
+ * @param {Error} err
15487
+ * @param {Set<Error>} [seen]
15488
+ * @return {FullErrorStack}
15489
+ */
15490
+ var getFullErrorStack = function (err, seen) {
15491
+ if (seen && seen.has(err)) {
15492
+ return { message: '', msg: '<circular>', stack: '' };
15493
+ }
15494
+
15495
+ var message;
15496
+
15497
+ if (typeof err.inspect === 'function') {
15498
+ message = err.inspect() + '';
15499
+ } else if (err.message && typeof err.message.toString === 'function') {
15500
+ message = err.message + '';
15501
+ } else {
15502
+ message = '';
15503
+ }
15504
+
15505
+ var msg;
15506
+ var stack = err.stack || message;
15507
+ var index = message ? stack.indexOf(message) : -1;
15508
+
15509
+ if (index === -1) {
15510
+ msg = message;
15511
+ } else {
15512
+ index += message.length;
15513
+ msg = stack.slice(0, index);
15514
+ // remove msg from stack
15515
+ stack = stack.slice(index + 1);
15516
+
15517
+ if (err.cause) {
15518
+ seen = seen || new Set();
15519
+ seen.add(err);
15520
+ const causeStack = getFullErrorStack(err.cause, seen);
15521
+ stack += '\n Caused by: ' + causeStack.msg + (causeStack.stack ? '\n' + causeStack.stack : '');
15522
+ }
15523
+ }
15524
+
15525
+ return {
15526
+ message,
15527
+ msg,
15528
+ stack
15529
+ };
15530
+ };
15531
+
15471
15532
  /**
15472
15533
  * Outputs the given `failures` as a list.
15473
15534
  *
@@ -15488,7 +15549,6 @@
15488
15549
  color('error stack', '\n%s\n');
15489
15550
 
15490
15551
  // msg
15491
- var msg;
15492
15552
  var err;
15493
15553
  if (test.err && test.err.multiple) {
15494
15554
  if (multipleTest !== test) {
@@ -15499,25 +15559,8 @@
15499
15559
  } else {
15500
15560
  err = test.err;
15501
15561
  }
15502
- var message;
15503
- if (typeof err.inspect === 'function') {
15504
- message = err.inspect() + '';
15505
- } else if (err.message && typeof err.message.toString === 'function') {
15506
- message = err.message + '';
15507
- } else {
15508
- message = '';
15509
- }
15510
- var stack = err.stack || message;
15511
- var index = message ? stack.indexOf(message) : -1;
15512
15562
 
15513
- if (index === -1) {
15514
- msg = message;
15515
- } else {
15516
- index += message.length;
15517
- msg = stack.slice(0, index);
15518
- // remove msg from stack
15519
- stack = stack.slice(index + 1);
15520
- }
15563
+ var { message, msg, stack } = getFullErrorStack(err);
15521
15564
 
15522
15565
  // uncaught
15523
15566
  if (err.uncaught) {
@@ -15795,6 +15838,15 @@
15795
15838
  Base.consoleLog = consoleLog;
15796
15839
 
15797
15840
  Base.abstract = true;
15841
+
15842
+ /**
15843
+ * An object with all stack traces recursively mounted from each err.cause
15844
+ * @memberof module:lib/reporters/base
15845
+ * @typedef {Object} FullErrorStack
15846
+ * @property {string} message
15847
+ * @property {string} msg
15848
+ * @property {string} stack
15849
+ */
15798
15850
  }(base$1, base$1.exports));
15799
15851
 
15800
15852
  var dot = {exports: {}};
@@ -16455,143 +16507,6 @@
16455
16507
 
16456
16508
  var html = {exports: {}};
16457
16509
 
16458
- /**
16459
- @module browser/Progress
16460
- */
16461
-
16462
- /**
16463
- * Expose `Progress`.
16464
- */
16465
-
16466
- var progress$1 = Progress;
16467
-
16468
- /**
16469
- * Initialize a new `Progress` indicator.
16470
- */
16471
- function Progress() {
16472
- this.percent = 0;
16473
- this.size(0);
16474
- this.fontSize(11);
16475
- this.font('helvetica, arial, sans-serif');
16476
- }
16477
-
16478
- /**
16479
- * Set progress size to `size`.
16480
- *
16481
- * @public
16482
- * @param {number} size
16483
- * @return {Progress} Progress instance.
16484
- */
16485
- Progress.prototype.size = function (size) {
16486
- this._size = size;
16487
- return this;
16488
- };
16489
-
16490
- /**
16491
- * Set text to `text`.
16492
- *
16493
- * @public
16494
- * @param {string} text
16495
- * @return {Progress} Progress instance.
16496
- */
16497
- Progress.prototype.text = function (text) {
16498
- this._text = text;
16499
- return this;
16500
- };
16501
-
16502
- /**
16503
- * Set font size to `size`.
16504
- *
16505
- * @public
16506
- * @param {number} size
16507
- * @return {Progress} Progress instance.
16508
- */
16509
- Progress.prototype.fontSize = function (size) {
16510
- this._fontSize = size;
16511
- return this;
16512
- };
16513
-
16514
- /**
16515
- * Set font to `family`.
16516
- *
16517
- * @param {string} family
16518
- * @return {Progress} Progress instance.
16519
- */
16520
- Progress.prototype.font = function (family) {
16521
- this._font = family;
16522
- return this;
16523
- };
16524
-
16525
- /**
16526
- * Update percentage to `n`.
16527
- *
16528
- * @param {number} n
16529
- * @return {Progress} Progress instance.
16530
- */
16531
- Progress.prototype.update = function (n) {
16532
- this.percent = n;
16533
- return this;
16534
- };
16535
-
16536
- /**
16537
- * Draw on `ctx`.
16538
- *
16539
- * @param {CanvasRenderingContext2d} ctx
16540
- * @return {Progress} Progress instance.
16541
- */
16542
- Progress.prototype.draw = function (ctx) {
16543
- try {
16544
- var darkMatcher = window.matchMedia('(prefers-color-scheme: dark)');
16545
- var isDarkMode = !!darkMatcher.matches;
16546
- var lightColors = {
16547
- outerCircle: '#9f9f9f',
16548
- innerCircle: '#eee',
16549
- text: '#000'
16550
- };
16551
- var darkColors = {
16552
- outerCircle: '#888',
16553
- innerCircle: '#444',
16554
- text: '#fff'
16555
- };
16556
- var colors = isDarkMode ? darkColors : lightColors;
16557
-
16558
- var percent = Math.min(this.percent, 100);
16559
- var size = this._size;
16560
- var half = size / 2;
16561
- var x = half;
16562
- var y = half;
16563
- var rad = half - 1;
16564
- var fontSize = this._fontSize;
16565
-
16566
- ctx.font = fontSize + 'px ' + this._font;
16567
-
16568
- var angle = Math.PI * 2 * (percent / 100);
16569
- ctx.clearRect(0, 0, size, size);
16570
-
16571
- // outer circle
16572
- ctx.strokeStyle = colors.outerCircle;
16573
- ctx.beginPath();
16574
- ctx.arc(x, y, rad, 0, angle, false);
16575
- ctx.stroke();
16576
-
16577
- // inner circle
16578
- ctx.strokeStyle = colors.innerCircle;
16579
- ctx.beginPath();
16580
- ctx.arc(x, y, rad - 1, 0, angle, true);
16581
- ctx.stroke();
16582
-
16583
- // text
16584
- var text = this._text || (percent | 0) + '%';
16585
- var w = ctx.measureText(text).width;
16586
-
16587
- ctx.fillStyle = colors.text;
16588
- ctx.fillText(text, x - w / 2 + 1, y + fontSize / 2 - 1);
16589
- } catch (ignore) {
16590
- // don't fail if we can't render progress
16591
- }
16592
- return this;
16593
- };
16594
-
16595
16510
  (function (module, exports) {
16596
16511
 
16597
16512
  /* eslint-env browser */
@@ -16604,7 +16519,6 @@
16604
16519
 
16605
16520
  var Base = base$1.exports;
16606
16521
  var utils = utils$3;
16607
- var Progress = progress$1;
16608
16522
  var escapeRe = escapeStringRegexp;
16609
16523
  var constants = runner.constants;
16610
16524
  var EVENT_TEST_PASS = constants.EVENT_TEST_PASS;
@@ -16632,7 +16546,7 @@
16632
16546
 
16633
16547
  var statsTemplate =
16634
16548
  '<ul id="mocha-stats">' +
16635
- '<li class="progress"><canvas width="40" height="40"></canvas></li>' +
16549
+ '<li class="progress-contain"><progress class="progress-element" max="100" value="0"></progress><svg class="progress-ring"><circle class="ring-flatlight" stroke-dasharray="100%,0%"/><circle class="ring-highlight" stroke-dasharray="0%,100%"/></svg><div class="progress-text">0%</div></li>' +
16636
16550
  '<li class="passes"><a href="javascript:void(0);">passes:</a> <em>0</em></li>' +
16637
16551
  '<li class="failures"><a href="javascript:void(0);">failures:</a> <em>0</em></li>' +
16638
16552
  '<li class="duration">duration: <em>0</em>s</li>' +
@@ -16662,24 +16576,15 @@
16662
16576
  var failures = items[2].getElementsByTagName('em')[0];
16663
16577
  var failuresLink = items[2].getElementsByTagName('a')[0];
16664
16578
  var duration = items[3].getElementsByTagName('em')[0];
16665
- var canvas = stat.getElementsByTagName('canvas')[0];
16666
16579
  var report = fragment('<ul id="mocha-report"></ul>');
16667
16580
  var stack = [report];
16668
- var progress;
16669
- var ctx;
16581
+ var progressText = items[0].getElementsByTagName('div')[0];
16582
+ var progressBar = items[0].getElementsByTagName('progress')[0];
16583
+ var progressRing = [
16584
+ items[0].getElementsByClassName('ring-flatlight')[0],
16585
+ items[0].getElementsByClassName('ring-highlight')[0]];
16670
16586
  var root = document.getElementById('mocha');
16671
16587
 
16672
- if (canvas.getContext) {
16673
- var ratio = window.devicePixelRatio || 1;
16674
- canvas.style.width = canvas.width;
16675
- canvas.style.height = canvas.height;
16676
- canvas.width *= ratio;
16677
- canvas.height *= ratio;
16678
- ctx = canvas.getContext('2d');
16679
- ctx.scale(ratio, ratio);
16680
- progress = new Progress();
16681
- }
16682
-
16683
16588
  if (!root) {
16684
16589
  return error('#mocha div missing, add it to your document');
16685
16590
  }
@@ -16709,10 +16614,6 @@
16709
16614
  root.appendChild(stat);
16710
16615
  root.appendChild(report);
16711
16616
 
16712
- if (progress) {
16713
- progress.size(40);
16714
- }
16715
-
16716
16617
  runner.on(EVENT_SUITE_BEGIN, function (suite) {
16717
16618
  if (suite.root) {
16718
16619
  return;
@@ -16828,8 +16729,26 @@
16828
16729
  function updateStats() {
16829
16730
  // TODO: add to stats
16830
16731
  var percent = ((stats.tests / runner.total) * 100) | 0;
16831
- if (progress) {
16832
- progress.update(percent).draw(ctx);
16732
+ progressBar.value = percent;
16733
+ if (progressText) {
16734
+ // setting a toFixed that is too low, makes small changes to progress not shown
16735
+ // setting it too high, makes the progress text longer then it needs to
16736
+ // to address this, calculate the toFixed based on the magnitude of total
16737
+ var decimalPlaces = Math.ceil(Math.log10(runner.total / 100));
16738
+ text(
16739
+ progressText,
16740
+ percent.toFixed(Math.min(Math.max(decimalPlaces, 0), 100)) + '%'
16741
+ );
16742
+ }
16743
+ if (progressRing) {
16744
+ var radius = parseFloat(getComputedStyle(progressRing[0]).getPropertyValue('r'));
16745
+ var wholeArc = Math.PI * 2 * radius;
16746
+ var highlightArc = percent * (wholeArc / 100);
16747
+ // The progress ring is in 2 parts, the flatlight color and highlight color.
16748
+ // Rendering both on top of the other, seems to make a 3rd color on the edges.
16749
+ // To create 1 whole ring with 2 colors, both parts are inverse of the other.
16750
+ progressRing[0].style['stroke-dasharray'] = `0,${highlightArc}px,${wholeArc}px`;
16751
+ progressRing[1].style['stroke-dasharray'] = `${highlightArc}px,${wholeArc}px`;
16833
16752
  }
16834
16753
 
16835
16754
  // update stats
@@ -17658,6 +17577,7 @@
17658
17577
  var attrs = {
17659
17578
  classname: test.parent.fullTitle(),
17660
17579
  name: test.title,
17580
+ file: test.file,
17661
17581
  time: test.duration / 1000 || 0
17662
17582
  };
17663
17583
 
@@ -19066,7 +18986,7 @@
19066
18986
  };
19067
18987
 
19068
18988
  var name = "mocha";
19069
- var version = "10.3.0";
18989
+ var version = "10.5.0";
19070
18990
  var homepage = "https://mochajs.org/";
19071
18991
  var notifyLogo = "https://ibin.co/4QuRuGjXvl36.png";
19072
18992
  var require$$17 = {
@@ -20465,8 +20385,8 @@
20465
20385
 
20466
20386
  process.on = function (e, fn) {
20467
20387
  if (e === 'uncaughtException') {
20468
- commonjsGlobal.onerror = function (err, url, line) {
20469
- fn(new Error(err + ' (' + url + ':' + line + ')'));
20388
+ commonjsGlobal.onerror = function (msg, url, line, col, err) {
20389
+ fn(err || new Error(msg + ' (' + url + ':' + line + ':' + col + ')'));
20470
20390
  return !mocha.options.allowUncaught;
20471
20391
  };
20472
20392
  uncaughtExceptionHandlers.push(fn);