mocha 7.1.1 → 8.0.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/test.js CHANGED
@@ -26,9 +26,9 @@ function Test(title, fn) {
26
26
  'string'
27
27
  );
28
28
  }
29
- Runnable.call(this, title, fn);
30
- this.pending = !fn;
31
29
  this.type = 'test';
30
+ Runnable.call(this, title, fn);
31
+ this.reset();
32
32
  }
33
33
 
34
34
  /**
@@ -36,6 +36,15 @@ function Test(title, fn) {
36
36
  */
37
37
  utils.inherits(Test, Runnable);
38
38
 
39
+ /**
40
+ * Resets the state initially or for a next run.
41
+ */
42
+ Test.prototype.reset = function() {
43
+ Runnable.prototype.reset.call(this);
44
+ this.pending = !this.fn;
45
+ delete this.state;
46
+ };
47
+
39
48
  /**
40
49
  * Set or get retried test
41
50
  *
@@ -48,11 +57,19 @@ Test.prototype.retriedTest = function(n) {
48
57
  this._retriedTest = n;
49
58
  };
50
59
 
60
+ /**
61
+ * Add test to the list of tests marked `only`.
62
+ *
63
+ * @private
64
+ */
65
+ Test.prototype.markOnly = function() {
66
+ this.parent.appendOnlyTest(this);
67
+ };
68
+
51
69
  Test.prototype.clone = function() {
52
70
  var test = new Test(this.title, this.fn);
53
71
  test.timeout(this.timeout());
54
72
  test.slow(this.slow());
55
- test.enableTimeouts(this.enableTimeouts());
56
73
  test.retries(this.retries());
57
74
  test.currentRetry(this.currentRetry());
58
75
  test.retriedTest(this.retriedTest() || this);
@@ -62,3 +79,31 @@ Test.prototype.clone = function() {
62
79
  test.ctx = this.ctx;
63
80
  return test;
64
81
  };
82
+
83
+ /**
84
+ * Returns an minimal object suitable for transmission over IPC.
85
+ * Functions are represented by keys beginning with `$$`.
86
+ * @private
87
+ * @returns {Object}
88
+ */
89
+ Test.prototype.serialize = function serialize() {
90
+ return {
91
+ $$currentRetry: this._currentRetry,
92
+ $$fullTitle: this.fullTitle(),
93
+ $$isPending: this.pending,
94
+ $$retriedTest: this._retriedTest || null,
95
+ $$slow: this._slow,
96
+ $$titlePath: this.titlePath(),
97
+ body: this.body,
98
+ duration: this.duration,
99
+ err: this.err,
100
+ parent: {
101
+ $$fullTitle: this.parent.fullTitle()
102
+ },
103
+ speed: this.speed,
104
+ state: this.state,
105
+ title: this.title,
106
+ type: this.type,
107
+ file: this.file
108
+ };
109
+ };
package/lib/utils.js CHANGED
@@ -63,8 +63,9 @@ exports.isString = function(obj) {
63
63
  exports.slug = function(str) {
64
64
  return str
65
65
  .toLowerCase()
66
- .replace(/ +/g, '-')
67
- .replace(/[^-\w]/g, '');
66
+ .replace(/\s+/g, '-')
67
+ .replace(/[^-\w]/g, '')
68
+ .replace(/-{2,}/g, '-');
68
69
  };
69
70
 
70
71
  /**
@@ -487,7 +488,6 @@ function isHiddenOnUnix(pathname) {
487
488
  * **Make no assumption that the names will be sorted in any fashion.**
488
489
  *
489
490
  * @public
490
- * @memberof Mocha.utils
491
491
  * @param {string} filepath - Base path to start searching from.
492
492
  * @param {string[]} [extensions=[]] - File extensions to look for.
493
493
  * @param {boolean} [recursive=false] - Whether to recurse into subdirectories.
@@ -637,7 +637,7 @@ exports.stackTraceFilter = function() {
637
637
  var slash = path.sep;
638
638
  var cwd;
639
639
  if (is.node) {
640
- cwd = process.cwd() + slash;
640
+ cwd = exports.cwd() + slash;
641
641
  } else {
642
642
  cwd = (typeof location === 'undefined'
643
643
  ? window.location
@@ -753,38 +753,6 @@ exports.dQuote = function(str) {
753
753
  return '"' + str + '"';
754
754
  };
755
755
 
756
- /**
757
- * Provides simplistic message translation for dealing with plurality.
758
- *
759
- * @description
760
- * Use this to create messages which need to be singular or plural.
761
- * Some languages have several plural forms, so _complete_ message clauses
762
- * are preferable to generating the message on the fly.
763
- *
764
- * @private
765
- * @param {number} n - Non-negative integer
766
- * @param {string} msg1 - Message to be used in English for `n = 1`
767
- * @param {string} msg2 - Message to be used in English for `n = 0, 2, 3, ...`
768
- * @returns {string} message corresponding to value of `n`
769
- * @example
770
- * var sprintf = require('util').format;
771
- * var pkgs = ['one', 'two'];
772
- * var msg = sprintf(
773
- * ngettext(
774
- * pkgs.length,
775
- * 'cannot load package: %s',
776
- * 'cannot load packages: %s'
777
- * ),
778
- * pkgs.map(sQuote).join(', ')
779
- * );
780
- * console.log(msg); // => cannot load packages: 'one', 'two'
781
- */
782
- exports.ngettext = function(n, msg1, msg2) {
783
- if (typeof n === 'number' && n >= 0) {
784
- return n === 1 ? msg1 : msg2;
785
- }
786
- };
787
-
788
756
  /**
789
757
  * It's a noop.
790
758
  * @public
@@ -840,16 +808,40 @@ exports.defineConstants = function(obj) {
840
808
  * This function returns whether Node.JS has ES Module supports that is compatible with Mocha's needs,
841
809
  * which is version >=12.11.
842
810
  *
811
+ * @param {partialSupport} whether the full Node.js ESM support is available (>= 12) or just something that supports the runtime (>= 10)
812
+ *
843
813
  * @returns {Boolean} whether the current version of Node.JS supports ES Modules in a way that is compatible with Mocha
844
814
  */
845
- exports.supportsEsModules = function() {
846
- if (!process.browser && process.versions && process.versions.node) {
815
+ exports.supportsEsModules = function(partialSupport) {
816
+ if (!exports.isBrowser() && process.versions && process.versions.node) {
847
817
  var versionFields = process.versions.node.split('.');
848
818
  var major = +versionFields[0];
849
819
  var minor = +versionFields[1];
850
820
 
851
- if (major >= 13 || (major === 12 && minor >= 11)) {
852
- return true;
821
+ if (!partialSupport) {
822
+ return major >= 13 || (major === 12 && minor >= 11);
823
+ } else {
824
+ return major >= 10;
853
825
  }
854
826
  }
855
827
  };
828
+
829
+ /**
830
+ * Returns current working directory
831
+ *
832
+ * Wrapper around `process.cwd()` for isolation
833
+ * @private
834
+ */
835
+ exports.cwd = function cwd() {
836
+ return process.cwd();
837
+ };
838
+
839
+ /**
840
+ * Returns `true` if Mocha is running in a browser.
841
+ * Checks for `process.browser`.
842
+ * @returns {boolean}
843
+ * @private
844
+ */
845
+ exports.isBrowser = function isBrowser() {
846
+ return Boolean(process.browser);
847
+ };