mocha 6.2.2 → 7.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/mocha.js CHANGED
@@ -1463,18 +1463,18 @@ exports.Test = require('./test');
1463
1463
  * @param {boolean} [options.allowUncaught] - Propagate uncaught errors?
1464
1464
  * @param {boolean} [options.asyncOnly] - Force `done` callback or promise?
1465
1465
  * @param {boolean} [options.bail] - Bail after first test failure?
1466
- * @param {boolean} [options.checkLeaks] - If true, check leaks.
1466
+ * @param {boolean} [options.checkLeaks] - Check for global variable leaks?
1467
+ * @param {boolean} [options.color] - Color TTY output from reporter?
1467
1468
  * @param {boolean} [options.delay] - Delay root suite execution?
1468
- * @param {boolean} [options.enableTimeouts] - Enable timeouts?
1469
+ * @param {boolean} [options.diff] - Show diff on failure?
1469
1470
  * @param {string} [options.fgrep] - Test filter given string.
1470
1471
  * @param {boolean} [options.forbidOnly] - Tests marked `only` fail the suite?
1471
1472
  * @param {boolean} [options.forbidPending] - Pending tests fail the suite?
1472
- * @param {boolean} [options.fullStackTrace] - Full stacktrace upon failure?
1473
+ * @param {boolean} [options.fullTrace] - Full stacktrace upon failure?
1473
1474
  * @param {string[]} [options.global] - Variables expected in global scope.
1474
1475
  * @param {RegExp|string} [options.grep] - Test filter given regular expression.
1475
1476
  * @param {boolean} [options.growl] - Enable desktop notifications?
1476
- * @param {boolean} [options.hideDiff] - Suppress diffs from failures?
1477
- * @param {boolean} [options.ignoreLeaks] - Ignore global leaks?
1477
+ * @param {boolean} [options.inlineDiffs] - Display inline diffs?
1478
1478
  * @param {boolean} [options.invert] - Invert test filter matches?
1479
1479
  * @param {boolean} [options.noHighlighting] - Disable syntax highlighting?
1480
1480
  * @param {string|constructor} [options.reporter] - Reporter name or constructor.
@@ -1483,8 +1483,6 @@ exports.Test = require('./test');
1483
1483
  * @param {number} [options.slow] - Slow threshold value.
1484
1484
  * @param {number|string} [options.timeout] - Timeout threshold value.
1485
1485
  * @param {string} [options.ui] - Interface name.
1486
- * @param {boolean} [options.color] - Color TTY output from reporter?
1487
- * @param {boolean} [options.useInlineDiffs] - Use inline diffs?
1488
1486
  */
1489
1487
  function Mocha(options) {
1490
1488
  options = utils.assign({}, mocharc, options || {});
@@ -1493,35 +1491,15 @@ function Mocha(options) {
1493
1491
  // root suite
1494
1492
  this.suite = new exports.Suite('', new exports.Context(), true);
1495
1493
 
1496
- if ('useColors' in options) {
1497
- utils.deprecate(
1498
- 'useColors is DEPRECATED and will be removed from a future version of Mocha. Instead, use the "color" option'
1499
- );
1500
- options.color = 'color' in options ? options.color : options.useColors;
1501
- }
1502
-
1503
- // Globals are passed in as options.global, with options.globals for backward compatibility.
1504
- options.globals = options.global || options.globals || [];
1505
- delete options.global;
1506
-
1507
1494
  this.grep(options.grep)
1508
1495
  .fgrep(options.fgrep)
1509
1496
  .ui(options.ui)
1510
- .bail(options.bail)
1511
- .reporter(options.reporter, options.reporterOptions)
1512
- .useColors(options.color)
1497
+ .reporter(
1498
+ options.reporter,
1499
+ options.reporterOption || options.reporterOptions // reporterOptions was previously the only way to specify options to reporter
1500
+ )
1513
1501
  .slow(options.slow)
1514
- .useInlineDiffs(options.inlineDiffs)
1515
- .globals(options.globals);
1516
-
1517
- if ('enableTimeouts' in options) {
1518
- utils.deprecate(
1519
- 'enableTimeouts is DEPRECATED and will be removed from a future version of Mocha. Instead, use "timeout: false" to disable timeouts.'
1520
- );
1521
- if (options.enableTimeouts === false) {
1522
- this.timeout(0);
1523
- }
1524
- }
1502
+ .global(options.global);
1525
1503
 
1526
1504
  // this guard exists because Suite#timeout does not consider `undefined` to be valid input
1527
1505
  if (typeof options.timeout !== 'undefined') {
@@ -1532,19 +1510,19 @@ function Mocha(options) {
1532
1510
  this.retries(options.retries);
1533
1511
  }
1534
1512
 
1535
- if ('diff' in options) {
1536
- this.hideDiff(!options.diff);
1537
- }
1538
-
1539
1513
  [
1540
1514
  'allowUncaught',
1541
1515
  'asyncOnly',
1516
+ 'bail',
1542
1517
  'checkLeaks',
1518
+ 'color',
1543
1519
  'delay',
1520
+ 'diff',
1544
1521
  'forbidOnly',
1545
1522
  'forbidPending',
1546
1523
  'fullTrace',
1547
1524
  'growl',
1525
+ 'inlineDiffs',
1548
1526
  'invert'
1549
1527
  ].forEach(function(opt) {
1550
1528
  if (options[opt]) {
@@ -1557,16 +1535,13 @@ function Mocha(options) {
1557
1535
  * Enables or disables bailing on the first failure.
1558
1536
  *
1559
1537
  * @public
1560
- * @see {@link /#-bail-b|CLI option}
1538
+ * @see [CLI option](../#-bail-b)
1561
1539
  * @param {boolean} [bail=true] - Whether to bail on first error.
1562
1540
  * @returns {Mocha} this
1563
1541
  * @chainable
1564
1542
  */
1565
1543
  Mocha.prototype.bail = function(bail) {
1566
- if (!arguments.length) {
1567
- bail = true;
1568
- }
1569
- this.suite.bail(bail);
1544
+ this.suite.bail(bail !== false);
1570
1545
  return this;
1571
1546
  };
1572
1547
 
@@ -1578,7 +1553,7 @@ Mocha.prototype.bail = function(bail) {
1578
1553
  * Useful for generic setup code that must be included within test suite.
1579
1554
  *
1580
1555
  * @public
1581
- * @see {@link /#-file-filedirectoryglob|CLI option}
1556
+ * @see [CLI option](../#-file-filedirectoryglob)
1582
1557
  * @param {string} file - Pathname of file to be loaded.
1583
1558
  * @returns {Mocha} this
1584
1559
  * @chainable
@@ -1592,8 +1567,8 @@ Mocha.prototype.addFile = function(file) {
1592
1567
  * Sets reporter to `reporter`, defaults to "spec".
1593
1568
  *
1594
1569
  * @public
1595
- * @see {@link /#-reporter-name-r-name|CLI option}
1596
- * @see {@link /#reporters|Reporters}
1570
+ * @see [CLI option](../#-reporter-name-r-name)
1571
+ * @see [Reporters](../#reporters)
1597
1572
  * @param {String|Function} reporter - Reporter name or constructor.
1598
1573
  * @param {Object} [reporterOptions] - Options used to configure the reporter.
1599
1574
  * @returns {Mocha} this
@@ -1651,6 +1626,8 @@ Mocha.prototype.reporter = function(reporter, reporterOptions) {
1651
1626
  }
1652
1627
  this._reporter = _reporter;
1653
1628
  }
1629
+ this.options.reporterOption = reporterOptions;
1630
+ // alias option name is used in public reporters xunit/tap/progress
1654
1631
  this.options.reporterOptions = reporterOptions;
1655
1632
  return this;
1656
1633
  };
@@ -1659,8 +1636,8 @@ Mocha.prototype.reporter = function(reporter, reporterOptions) {
1659
1636
  * Sets test UI `name`, defaults to "bdd".
1660
1637
  *
1661
1638
  * @public
1662
- * @see {@link /#-ui-name-u-name|CLI option}
1663
- * @see {@link /#interfaces|Interface DSLs}
1639
+ * @see [CLI option](../#-ui-name-u-name)
1640
+ * @see [Interface DSLs](../#interfaces)
1664
1641
  * @param {string|Function} [ui=bdd] - Interface name or class.
1665
1642
  * @returns {Mocha} this
1666
1643
  * @chainable
@@ -1753,8 +1730,6 @@ Mocha.unloadFile = function(file) {
1753
1730
  * <strong>Intended for consumers &mdash; not used internally</strong>
1754
1731
  *
1755
1732
  * @public
1756
- * @see {@link Mocha.unloadFile}
1757
- * @see {@link Mocha#loadFiles}
1758
1733
  * @see {@link Mocha#run}
1759
1734
  * @returns {Mocha} this
1760
1735
  * @chainable
@@ -1798,7 +1773,7 @@ Mocha.prototype.fgrep = function(str) {
1798
1773
  * <strong>Previous filter value will be overwritten on each call!</strong>
1799
1774
  *
1800
1775
  * @public
1801
- * @see {@link /#grep-regexp-g-regexp|CLI option}
1776
+ * @see [CLI option](../#-grep-regexp-g-regexp)
1802
1777
  * @see {@link Mocha#fgrep}
1803
1778
  * @see {@link Mocha#invert}
1804
1779
  * @param {RegExp|String} re - Regular expression used to select tests.
@@ -1849,32 +1824,32 @@ Mocha.prototype.invert = function() {
1849
1824
  /**
1850
1825
  * Enables or disables ignoring global leaks.
1851
1826
  *
1827
+ * @deprecated since v7.0.0
1852
1828
  * @public
1853
1829
  * @see {@link Mocha#checkLeaks}
1854
- * @param {boolean} ignoreLeaks - Whether to ignore global leaks.
1830
+ * @param {boolean} [ignoreLeaks=false] - Whether to ignore global leaks.
1855
1831
  * @return {Mocha} this
1856
1832
  * @chainable
1857
- * @example
1858
- *
1859
- * // Ignore global leaks
1860
- * mocha.ignoreLeaks(true);
1861
1833
  */
1862
1834
  Mocha.prototype.ignoreLeaks = function(ignoreLeaks) {
1863
- this.options.ignoreLeaks = Boolean(ignoreLeaks);
1835
+ utils.deprecate(
1836
+ '"ignoreLeaks()" is DEPRECATED, please use "checkLeaks()" instead.'
1837
+ );
1838
+ this.options.checkLeaks = !ignoreLeaks;
1864
1839
  return this;
1865
1840
  };
1866
1841
 
1867
1842
  /**
1868
- * Enables checking for global variables leaked while running tests.
1843
+ * Enables or disables checking for global variables leaked while running tests.
1869
1844
  *
1870
1845
  * @public
1871
- * @see {@link /#-check-leaks|CLI option}
1872
- * @see {@link Mocha#ignoreLeaks}
1846
+ * @see [CLI option](../#-check-leaks)
1847
+ * @param {boolean} [checkLeaks=true] - Whether to check for global variable leaks.
1873
1848
  * @return {Mocha} this
1874
1849
  * @chainable
1875
1850
  */
1876
- Mocha.prototype.checkLeaks = function() {
1877
- this.options.ignoreLeaks = false;
1851
+ Mocha.prototype.checkLeaks = function(checkLeaks) {
1852
+ this.options.checkLeaks = checkLeaks !== false;
1878
1853
  return this;
1879
1854
  };
1880
1855
 
@@ -1882,11 +1857,13 @@ Mocha.prototype.checkLeaks = function() {
1882
1857
  * Displays full stack trace upon test failure.
1883
1858
  *
1884
1859
  * @public
1860
+ * @see [CLI option](../#-full-trace)
1861
+ * @param {boolean} [fullTrace=true] - Whether to print full stacktrace upon failure.
1885
1862
  * @return {Mocha} this
1886
1863
  * @chainable
1887
1864
  */
1888
- Mocha.prototype.fullTrace = function() {
1889
- this.options.fullStackTrace = true;
1865
+ Mocha.prototype.fullTrace = function(fullTrace) {
1866
+ this.options.fullTrace = fullTrace !== false;
1890
1867
  return this;
1891
1868
  };
1892
1869
 
@@ -1894,8 +1871,7 @@ Mocha.prototype.fullTrace = function() {
1894
1871
  * Enables desktop notification support if prerequisite software installed.
1895
1872
  *
1896
1873
  * @public
1897
- * @see {@link Mocha#isGrowlCapable}
1898
- * @see {@link Mocha#_growl}
1874
+ * @see [CLI option](../#-growl-g)
1899
1875
  * @return {Mocha} this
1900
1876
  * @chainable
1901
1877
  */
@@ -1938,65 +1914,121 @@ Mocha.prototype._growl = growl.notify;
1938
1914
  * Specifies whitelist of variable names to be expected in global scope.
1939
1915
  *
1940
1916
  * @public
1941
- * @see {@link /#-global-variable-name|CLI option}
1917
+ * @see [CLI option](../#-global-variable-name)
1942
1918
  * @see {@link Mocha#checkLeaks}
1943
- * @param {String[]|String} globals - Accepted global variable name(s).
1919
+ * @param {String[]|String} global - Accepted global variable name(s).
1944
1920
  * @return {Mocha} this
1945
1921
  * @chainable
1946
1922
  * @example
1947
1923
  *
1948
1924
  * // Specify variables to be expected in global scope
1949
- * mocha.globals(['jQuery', 'MyLib']);
1925
+ * mocha.global(['jQuery', 'MyLib']);
1950
1926
  */
1951
- Mocha.prototype.globals = function(globals) {
1952
- this.options.globals = this.options.globals
1953
- .concat(globals)
1927
+ Mocha.prototype.global = function(global) {
1928
+ this.options.global = (this.options.global || [])
1929
+ .concat(global)
1954
1930
  .filter(Boolean)
1955
1931
  .filter(function(elt, idx, arr) {
1956
1932
  return arr.indexOf(elt) === idx;
1957
1933
  });
1958
1934
  return this;
1959
1935
  };
1936
+ // for backwards compability, 'globals' is an alias of 'global'
1937
+ Mocha.prototype.globals = Mocha.prototype.global;
1960
1938
 
1961
1939
  /**
1962
1940
  * Enables or disables TTY color output by screen-oriented reporters.
1963
1941
  *
1942
+ * @deprecated since v7.0.0
1964
1943
  * @public
1944
+ * @see {@link Mocha#color}
1965
1945
  * @param {boolean} colors - Whether to enable color output.
1966
1946
  * @return {Mocha} this
1967
1947
  * @chainable
1968
1948
  */
1969
1949
  Mocha.prototype.useColors = function(colors) {
1950
+ utils.deprecate('"useColors()" is DEPRECATED, please use "color()" instead.');
1970
1951
  if (colors !== undefined) {
1971
- this.options.useColors = colors;
1952
+ this.options.color = colors;
1972
1953
  }
1973
1954
  return this;
1974
1955
  };
1975
1956
 
1957
+ /**
1958
+ * Enables or disables TTY color output by screen-oriented reporters.
1959
+ *
1960
+ * @public
1961
+ * @see [CLI option](../#-color-c-colors)
1962
+ * @param {boolean} [color=true] - Whether to enable color output.
1963
+ * @return {Mocha} this
1964
+ * @chainable
1965
+ */
1966
+ Mocha.prototype.color = function(color) {
1967
+ this.options.color = color !== false;
1968
+ return this;
1969
+ };
1970
+
1976
1971
  /**
1977
1972
  * Determines if reporter should use inline diffs (rather than +/-)
1978
1973
  * in test failure output.
1979
1974
  *
1975
+ * @deprecated since v7.0.0
1980
1976
  * @public
1981
- * @param {boolean} inlineDiffs - Whether to use inline diffs.
1977
+ * @see {@link Mocha#inlineDiffs}
1978
+ * @param {boolean} [inlineDiffs=false] - Whether to use inline diffs.
1982
1979
  * @return {Mocha} this
1983
1980
  * @chainable
1984
1981
  */
1985
1982
  Mocha.prototype.useInlineDiffs = function(inlineDiffs) {
1986
- this.options.useInlineDiffs = inlineDiffs !== undefined && inlineDiffs;
1983
+ utils.deprecate(
1984
+ '"useInlineDiffs()" is DEPRECATED, please use "inlineDiffs()" instead.'
1985
+ );
1986
+ this.options.inlineDiffs = inlineDiffs !== undefined && inlineDiffs;
1987
+ return this;
1988
+ };
1989
+
1990
+ /**
1991
+ * Enables or disables reporter to use inline diffs (rather than +/-)
1992
+ * in test failure output.
1993
+ *
1994
+ * @public
1995
+ * @see [CLI option](../#-inline-diffs)
1996
+ * @param {boolean} [inlineDiffs=true] - Whether to use inline diffs.
1997
+ * @return {Mocha} this
1998
+ * @chainable
1999
+ */
2000
+ Mocha.prototype.inlineDiffs = function(inlineDiffs) {
2001
+ this.options.inlineDiffs = inlineDiffs !== false;
1987
2002
  return this;
1988
2003
  };
1989
2004
 
1990
2005
  /**
1991
2006
  * Determines if reporter should include diffs in test failure output.
1992
2007
  *
2008
+ * @deprecated since v7.0.0
1993
2009
  * @public
1994
- * @param {boolean} hideDiff - Whether to hide diffs.
2010
+ * @see {@link Mocha#diff}
2011
+ * @param {boolean} [hideDiff=false] - Whether to hide diffs.
1995
2012
  * @return {Mocha} this
1996
2013
  * @chainable
1997
2014
  */
1998
2015
  Mocha.prototype.hideDiff = function(hideDiff) {
1999
- this.options.hideDiff = hideDiff !== undefined && hideDiff;
2016
+ utils.deprecate('"hideDiff()" is DEPRECATED, please use "diff()" instead.');
2017
+ this.options.diff = !(hideDiff === true);
2018
+ return this;
2019
+ };
2020
+
2021
+ /**
2022
+ * Enables or disables reporter to include diff in test failure output.
2023
+ *
2024
+ * @public
2025
+ * @see [CLI option](../#-diff)
2026
+ * @param {boolean} [diff=true] - Whether to show diff on failure.
2027
+ * @return {Mocha} this
2028
+ * @chainable
2029
+ */
2030
+ Mocha.prototype.diff = function(diff) {
2031
+ this.options.diff = diff !== false;
2000
2032
  return this;
2001
2033
  };
2002
2034
 
@@ -2009,8 +2041,8 @@ Mocha.prototype.hideDiff = function(hideDiff) {
2009
2041
  * If the value is `0`, timeouts will be disabled.
2010
2042
  *
2011
2043
  * @public
2012
- * @see {@link /#-timeout-ms-t-ms|CLI option}
2013
- * @see {@link /#timeouts|Timeouts}
2044
+ * @see [CLI option](../#-timeout-ms-t-ms)
2045
+ * @see [Timeouts](../#timeouts)
2014
2046
  * @see {@link Mocha#enableTimeouts}
2015
2047
  * @param {number|string} msecs - Timeout threshold value.
2016
2048
  * @return {Mocha} this
@@ -2033,7 +2065,8 @@ Mocha.prototype.timeout = function(msecs) {
2033
2065
  * Sets the number of times to retry failed tests.
2034
2066
  *
2035
2067
  * @public
2036
- * @see {@link /#retry-tests|Retry Tests}
2068
+ * @see [CLI option](../#-retries-n)
2069
+ * @see [Retry Tests](../#retry-tests)
2037
2070
  * @param {number} retry - Number of times to retry failed tests.
2038
2071
  * @return {Mocha} this
2039
2072
  * @chainable
@@ -2051,7 +2084,7 @@ Mocha.prototype.retries = function(n) {
2051
2084
  * Sets slowness threshold value.
2052
2085
  *
2053
2086
  * @public
2054
- * @see {@link /#-slow-ms-s-ms|CLI option}
2087
+ * @see [CLI option](../#-slow-ms-s-ms)
2055
2088
  * @param {number} msecs - Slowness threshold value.
2056
2089
  * @return {Mocha} this
2057
2090
  * @chainable
@@ -2073,7 +2106,7 @@ Mocha.prototype.slow = function(msecs) {
2073
2106
  * Enables or disables timeouts.
2074
2107
  *
2075
2108
  * @public
2076
- * @see {@link /#-timeout-ms-t-ms|CLI option}
2109
+ * @see [CLI option](../#-timeout-ms-t-ms)
2077
2110
  * @param {boolean} enableTimeouts - Whether to enable timeouts.
2078
2111
  * @return {Mocha} this
2079
2112
  * @chainable
@@ -2089,11 +2122,13 @@ Mocha.prototype.enableTimeouts = function(enableTimeouts) {
2089
2122
  * Forces all tests to either accept a `done` callback or return a promise.
2090
2123
  *
2091
2124
  * @public
2125
+ * @see [CLI option](../#-async-only-a)
2126
+ * @param {boolean} [asyncOnly=true] - Wether to force `done` callback or promise.
2092
2127
  * @return {Mocha} this
2093
2128
  * @chainable
2094
2129
  */
2095
- Mocha.prototype.asyncOnly = function() {
2096
- this.options.asyncOnly = true;
2130
+ Mocha.prototype.asyncOnly = function(asyncOnly) {
2131
+ this.options.asyncOnly = asyncOnly !== false;
2097
2132
  return this;
2098
2133
  };
2099
2134
 
@@ -2110,14 +2145,16 @@ Mocha.prototype.noHighlighting = function() {
2110
2145
  };
2111
2146
 
2112
2147
  /**
2113
- * Enables uncaught errors to propagate (in browser).
2148
+ * Enables or disables uncaught errors to propagate.
2114
2149
  *
2115
2150
  * @public
2151
+ * @see [CLI option](../#-allow-uncaught)
2152
+ * @param {boolean} [allowUncaught=true] - Whether to propagate uncaught errors.
2116
2153
  * @return {Mocha} this
2117
2154
  * @chainable
2118
2155
  */
2119
- Mocha.prototype.allowUncaught = function() {
2120
- this.options.allowUncaught = true;
2156
+ Mocha.prototype.allowUncaught = function(allowUncaught) {
2157
+ this.options.allowUncaught = allowUncaught !== false;
2121
2158
  return this;
2122
2159
  };
2123
2160
 
@@ -2129,7 +2166,7 @@ Mocha.prototype.allowUncaught = function() {
2129
2166
  * Used to perform asynch operations before any suites are run.
2130
2167
  *
2131
2168
  * @public
2132
- * @see {@link /#delayed-root-suite|delayed root suite}
2169
+ * @see [delayed root suite](../#delayed-root-suite)
2133
2170
  * @returns {Mocha} this
2134
2171
  * @chainable
2135
2172
  */
@@ -2142,11 +2179,13 @@ Mocha.prototype.delay = function delay() {
2142
2179
  * Causes tests marked `only` to fail the suite.
2143
2180
  *
2144
2181
  * @public
2182
+ * @see [CLI option](../#-forbid-only)
2183
+ * @param {boolean} [forbidOnly=true] - Whether tests marked `only` fail the suite.
2145
2184
  * @returns {Mocha} this
2146
2185
  * @chainable
2147
2186
  */
2148
- Mocha.prototype.forbidOnly = function() {
2149
- this.options.forbidOnly = true;
2187
+ Mocha.prototype.forbidOnly = function(forbidOnly) {
2188
+ this.options.forbidOnly = forbidOnly !== false;
2150
2189
  return this;
2151
2190
  };
2152
2191
 
@@ -2154,11 +2193,13 @@ Mocha.prototype.forbidOnly = function() {
2154
2193
  * Causes pending tests and tests marked `skip` to fail the suite.
2155
2194
  *
2156
2195
  * @public
2196
+ * @see [CLI option](../#-forbid-pending)
2197
+ * @param {boolean} [forbidPending=true] - Whether pending tests fail the suite.
2157
2198
  * @returns {Mocha} this
2158
2199
  * @chainable
2159
2200
  */
2160
- Mocha.prototype.forbidPending = function() {
2161
- this.options.forbidPending = true;
2201
+ Mocha.prototype.forbidPending = function(forbidPending) {
2202
+ this.options.forbidPending = forbidPending !== false;
2162
2203
  return this;
2163
2204
  };
2164
2205
 
@@ -2192,7 +2233,6 @@ Object.defineProperty(Mocha.prototype, 'version', {
2192
2233
  * the cache first!
2193
2234
  *
2194
2235
  * @public
2195
- * @see {@link Mocha#loadFiles}
2196
2236
  * @see {@link Mocha#unloadFiles}
2197
2237
  * @see {@link Runner#run}
2198
2238
  * @param {DoneCB} [fn] - Callback invoked when test execution completed.
@@ -2208,8 +2248,8 @@ Mocha.prototype.run = function(fn) {
2208
2248
  var runner = new exports.Runner(suite, options.delay);
2209
2249
  createStatsCollector(runner);
2210
2250
  var reporter = new this._reporter(runner, options);
2211
- runner.ignoreLeaks = options.ignoreLeaks !== false;
2212
- runner.fullStackTrace = options.fullStackTrace;
2251
+ runner.checkLeaks = options.checkLeaks === true;
2252
+ runner.fullStackTrace = options.fullTrace;
2213
2253
  runner.asyncOnly = options.asyncOnly;
2214
2254
  runner.allowUncaught = options.allowUncaught;
2215
2255
  runner.forbidOnly = options.forbidOnly;
@@ -2217,17 +2257,17 @@ Mocha.prototype.run = function(fn) {
2217
2257
  if (options.grep) {
2218
2258
  runner.grep(options.grep, options.invert);
2219
2259
  }
2220
- if (options.globals) {
2221
- runner.globals(options.globals);
2260
+ if (options.global) {
2261
+ runner.globals(options.global);
2222
2262
  }
2223
2263
  if (options.growl) {
2224
2264
  this._growl(runner);
2225
2265
  }
2226
- if (options.useColors !== undefined) {
2227
- exports.reporters.Base.useColors = options.useColors;
2266
+ if (options.color !== undefined) {
2267
+ exports.reporters.Base.useColors = options.color;
2228
2268
  }
2229
- exports.reporters.Base.inlineDiffs = options.useInlineDiffs;
2230
- exports.reporters.Base.hideDiff = options.hideDiff;
2269
+ exports.reporters.Base.inlineDiffs = options.inlineDiffs;
2270
+ exports.reporters.Base.hideDiff = !options.diff;
2231
2271
 
2232
2272
  function done(failures) {
2233
2273
  fn = fn || utils.noop;
@@ -2251,7 +2291,8 @@ module.exports={
2251
2291
  "reporter": "spec",
2252
2292
  "slow": 75,
2253
2293
  "timeout": 2000,
2254
- "ui": "bdd"
2294
+ "ui": "bdd",
2295
+ "watch-ignore": ["node_modules", ".git"]
2255
2296
  }
2256
2297
 
2257
2298
  },{}],16:[function(require,module,exports){
@@ -2426,14 +2467,14 @@ exports.cursor = {
2426
2467
  }
2427
2468
  };
2428
2469
 
2429
- function showDiff(err) {
2470
+ var showDiff = (exports.showDiff = function(err) {
2430
2471
  return (
2431
2472
  err &&
2432
2473
  err.showDiff !== false &&
2433
2474
  sameType(err.actual, err.expected) &&
2434
2475
  err.expected !== undefined
2435
2476
  );
2436
- }
2477
+ });
2437
2478
 
2438
2479
  function stringifyDiffObjs(err) {
2439
2480
  if (!utils.isString(err.actual) || !utils.isString(err.expected)) {
@@ -2454,9 +2495,19 @@ function stringifyDiffObjs(err) {
2454
2495
  * @return {string} Diff
2455
2496
  */
2456
2497
  var generateDiff = (exports.generateDiff = function(actual, expected) {
2457
- return exports.inlineDiffs
2458
- ? inlineDiff(actual, expected)
2459
- : unifiedDiff(actual, expected);
2498
+ try {
2499
+ return exports.inlineDiffs
2500
+ ? inlineDiff(actual, expected)
2501
+ : unifiedDiff(actual, expected);
2502
+ } catch (err) {
2503
+ var msg =
2504
+ '\n ' +
2505
+ color('diff added', '+ expected') +
2506
+ ' ' +
2507
+ color('diff removed', '- actual: failed to generate Mocha diff') +
2508
+ '\n';
2509
+ return msg;
2510
+ }
2460
2511
  });
2461
2512
 
2462
2513
  /**
@@ -4929,9 +4980,9 @@ XUnit.prototype.test = function(test) {
4929
4980
  if (test.state === STATE_FAILED) {
4930
4981
  var err = test.err;
4931
4982
  var diff =
4932
- Base.hideDiff || !err.actual || !err.expected
4933
- ? ''
4934
- : '\n' + Base.generateDiff(err.actual, err.expected);
4983
+ !Base.hideDiff && Base.showDiff(err)
4984
+ ? '\n' + Base.generateDiff(err.actual, err.expected)
4985
+ : '';
4935
4986
  this.write(
4936
4987
  tag(
4937
4988
  'testcase',
@@ -5121,7 +5172,8 @@ Runnable.prototype.enableTimeouts = function(enabled) {
5121
5172
  * @public
5122
5173
  */
5123
5174
  Runnable.prototype.skip = function() {
5124
- throw new Pending('sync skip');
5175
+ this.pending = true;
5176
+ throw new Pending('sync skip; aborting execution');
5125
5177
  };
5126
5178
 
5127
5179
  /**
@@ -5320,43 +5372,45 @@ Runnable.prototype.run = function(fn) {
5320
5372
  fn(err);
5321
5373
  }
5322
5374
 
5323
- // for .resetTimeout()
5375
+ // for .resetTimeout() and Runner#uncaught()
5324
5376
  this.callback = done;
5325
5377
 
5378
+ if (this.fn && typeof this.fn.call !== 'function') {
5379
+ done(
5380
+ new TypeError(
5381
+ 'A runnable must be passed a function as its second argument.'
5382
+ )
5383
+ );
5384
+ return;
5385
+ }
5386
+
5326
5387
  // explicit async with `done` argument
5327
5388
  if (this.async) {
5328
5389
  this.resetTimeout();
5329
5390
 
5330
5391
  // allows skip() to be used in an explicit async context
5331
5392
  this.skip = function asyncSkip() {
5332
- done(new Pending('async skip call'));
5333
- // halt execution. the Runnable will be marked pending
5334
- // by the previous call, and the uncaught handler will ignore
5335
- // the failure.
5393
+ this.pending = true;
5394
+ done();
5395
+ // halt execution, the uncaught handler will ignore the failure.
5336
5396
  throw new Pending('async skip; aborting execution');
5337
5397
  };
5338
5398
 
5339
- if (this.allowUncaught) {
5340
- return callFnAsync(this.fn);
5341
- }
5342
5399
  try {
5343
5400
  callFnAsync(this.fn);
5344
5401
  } catch (err) {
5402
+ // handles async runnables which actually run synchronously
5345
5403
  emitted = true;
5404
+ if (err instanceof Pending) {
5405
+ return; // done() is already called in this.skip()
5406
+ } else if (this.allowUncaught) {
5407
+ throw err;
5408
+ }
5346
5409
  done(Runnable.toValueOrError(err));
5347
5410
  }
5348
5411
  return;
5349
5412
  }
5350
5413
 
5351
- if (this.allowUncaught) {
5352
- if (this.isPending()) {
5353
- done();
5354
- } else {
5355
- callFn(this.fn);
5356
- }
5357
- return;
5358
- }
5359
-
5360
5414
  // sync or promise-returning
5361
5415
  try {
5362
5416
  if (this.isPending()) {
@@ -5366,6 +5420,11 @@ Runnable.prototype.run = function(fn) {
5366
5420
  }
5367
5421
  } catch (err) {
5368
5422
  emitted = true;
5423
+ if (err instanceof Pending) {
5424
+ return done();
5425
+ } else if (this.allowUncaught) {
5426
+ throw err;
5427
+ }
5369
5428
  done(Runnable.toValueOrError(err));
5370
5429
  }
5371
5430
 
@@ -5510,8 +5569,9 @@ var sQuote = utils.sQuote;
5510
5569
  var stackFilter = utils.stackTraceFilter();
5511
5570
  var stringify = utils.stringify;
5512
5571
  var type = utils.type;
5513
- var createInvalidExceptionError = require('./errors')
5514
- .createInvalidExceptionError;
5572
+ var errors = require('./errors');
5573
+ var createInvalidExceptionError = errors.createInvalidExceptionError;
5574
+ var createUnsupportedError = errors.createUnsupportedError;
5515
5575
 
5516
5576
  /**
5517
5577
  * Non-enumerable globals.
@@ -5730,7 +5790,7 @@ Runner.prototype.globals = function(arr) {
5730
5790
  * @private
5731
5791
  */
5732
5792
  Runner.prototype.checkGlobals = function(test) {
5733
- if (this.ignoreLeaks) {
5793
+ if (!this.checkLeaks) {
5734
5794
  return;
5735
5795
  }
5736
5796
  var ok = this._globals;
@@ -5801,8 +5861,7 @@ Runner.prototype.fail = function(test, err) {
5801
5861
  * - Failed `before each` hook skips remaining tests in a
5802
5862
  * suite and jumps to corresponding `after each` hook,
5803
5863
  * which is run only once
5804
- * - Failed `after` hook does not alter
5805
- * execution order
5864
+ * - Failed `after` hook does not alter execution order
5806
5865
  * - Failed `after each` hook skips remaining tests in a
5807
5866
  * suite and subsuites, but executes other `after each`
5808
5867
  * hooks
@@ -5872,34 +5931,37 @@ Runner.prototype.hook = function(name, fn) {
5872
5931
  if (testError) {
5873
5932
  self.fail(self.test, testError);
5874
5933
  }
5875
- if (err) {
5876
- if (err instanceof Pending) {
5877
- if (name === HOOK_TYPE_AFTER_ALL) {
5878
- utils.deprecate(
5879
- 'Skipping a test within an "after all" hook is DEPRECATED and will throw an exception in a future version of Mocha. ' +
5880
- 'Use a return statement or other means to abort hook execution.'
5881
- );
5934
+ // conditional skip
5935
+ if (hook.pending) {
5936
+ if (name === HOOK_TYPE_AFTER_EACH) {
5937
+ // TODO define and implement use case
5938
+ if (self.test) {
5939
+ self.test.pending = true;
5882
5940
  }
5883
- if (name === HOOK_TYPE_BEFORE_EACH || name === HOOK_TYPE_AFTER_EACH) {
5884
- if (self.test) {
5885
- self.test.pending = true;
5886
- }
5887
- } else {
5888
- suite.tests.forEach(function(test) {
5889
- test.pending = true;
5890
- });
5891
- suite.suites.forEach(function(suite) {
5892
- suite.pending = true;
5893
- });
5894
- // a pending hook won't be executed twice.
5895
- hook.pending = true;
5941
+ } else if (name === HOOK_TYPE_BEFORE_EACH) {
5942
+ if (self.test) {
5943
+ self.test.pending = true;
5896
5944
  }
5945
+ self.emit(constants.EVENT_HOOK_END, hook);
5946
+ hook.pending = false; // activates hook for next test
5947
+ return fn(new Error('abort hookDown'));
5948
+ } else if (name === HOOK_TYPE_BEFORE_ALL) {
5949
+ suite.tests.forEach(function(test) {
5950
+ test.pending = true;
5951
+ });
5952
+ suite.suites.forEach(function(suite) {
5953
+ suite.pending = true;
5954
+ });
5897
5955
  } else {
5898
- self.failHook(hook, err);
5899
-
5900
- // stop executing hooks, notify callee of hook err
5901
- return fn(err);
5956
+ hook.pending = false;
5957
+ var errForbid = createUnsupportedError('`this.skip` forbidden');
5958
+ self.failHook(hook, errForbid);
5959
+ return fn(errForbid);
5902
5960
  }
5961
+ } else if (err) {
5962
+ self.failHook(hook, err);
5963
+ // stop executing hooks, notify callee of hook err
5964
+ return fn(err);
5903
5965
  }
5904
5966
  self.emit(constants.EVENT_HOOK_END, hook);
5905
5967
  delete hook.ctx.currentTest;
@@ -6011,6 +6073,9 @@ Runner.prototype.runTest = function(fn) {
6011
6073
  test.asyncOnly = true;
6012
6074
  }
6013
6075
  test.on('error', function(err) {
6076
+ if (err instanceof Pending) {
6077
+ return;
6078
+ }
6014
6079
  self.fail(test, err);
6015
6080
  });
6016
6081
  if (this.allowUncaught) {
@@ -6106,6 +6171,7 @@ Runner.prototype.runTests = function(suite, fn) {
6106
6171
  return;
6107
6172
  }
6108
6173
 
6174
+ // static skip, no hooks are executed
6109
6175
  if (test.isPending()) {
6110
6176
  if (self.forbidPending) {
6111
6177
  test.isPending = alwaysFalse;
@@ -6121,6 +6187,7 @@ Runner.prototype.runTests = function(suite, fn) {
6121
6187
  // execute test and hook(s)
6122
6188
  self.emit(constants.EVENT_TEST_BEGIN, (self.test = test));
6123
6189
  self.hookDown(HOOK_TYPE_BEFORE_EACH, function(err, errSuite) {
6190
+ // conditional skip within beforeEach
6124
6191
  if (test.isPending()) {
6125
6192
  if (self.forbidPending) {
6126
6193
  test.isPending = alwaysFalse;
@@ -6130,7 +6197,13 @@ Runner.prototype.runTests = function(suite, fn) {
6130
6197
  self.emit(constants.EVENT_TEST_PENDING, test);
6131
6198
  }
6132
6199
  self.emit(constants.EVENT_TEST_END, test);
6133
- return next();
6200
+ // skip inner afterEach hooks below errSuite level
6201
+ var origSuite = self.suite;
6202
+ self.suite = errSuite || self.suite;
6203
+ return self.hookUp(HOOK_TYPE_AFTER_EACH, function(e, eSuite) {
6204
+ self.suite = origSuite;
6205
+ next(e, eSuite);
6206
+ });
6134
6207
  }
6135
6208
  if (err) {
6136
6209
  return hookErr(err, errSuite, false);
@@ -6138,14 +6211,20 @@ Runner.prototype.runTests = function(suite, fn) {
6138
6211
  self.currentRunnable = self.test;
6139
6212
  self.runTest(function(err) {
6140
6213
  test = self.test;
6141
- if (err) {
6142
- var retry = test.currentRetry();
6143
- if (err instanceof Pending && self.forbidPending) {
6214
+ // conditional skip within it
6215
+ if (test.pending) {
6216
+ if (self.forbidPending) {
6217
+ test.isPending = alwaysFalse;
6144
6218
  self.fail(test, new Error('Pending test forbidden'));
6145
- } else if (err instanceof Pending) {
6146
- test.pending = true;
6219
+ delete test.isPending;
6220
+ } else {
6147
6221
  self.emit(constants.EVENT_TEST_PENDING, test);
6148
- } else if (retry < test.retries()) {
6222
+ }
6223
+ self.emit(constants.EVENT_TEST_END, test);
6224
+ return self.hookUp(HOOK_TYPE_AFTER_EACH, next);
6225
+ } else if (err) {
6226
+ var retry = test.currentRetry();
6227
+ if (retry < test.retries()) {
6149
6228
  var clonedTest = test.clone();
6150
6229
  clonedTest.currentRetry(retry + 1);
6151
6230
  tests.unshift(clonedTest);
@@ -6159,11 +6238,6 @@ Runner.prototype.runTests = function(suite, fn) {
6159
6238
  self.fail(test, err);
6160
6239
  }
6161
6240
  self.emit(constants.EVENT_TEST_END, test);
6162
-
6163
- if (err instanceof Pending) {
6164
- return next();
6165
- }
6166
-
6167
6241
  return self.hookUp(HOOK_TYPE_AFTER_EACH, next);
6168
6242
  }
6169
6243
 
@@ -6195,7 +6269,6 @@ Runner.prototype.runSuite = function(suite, fn) {
6195
6269
  var i = 0;
6196
6270
  var self = this;
6197
6271
  var total = this.grepTotal(suite);
6198
- var afterAllHookCalled = false;
6199
6272
 
6200
6273
  debug('run suite %s', suite.fullTitle());
6201
6274
 
@@ -6243,21 +6316,13 @@ Runner.prototype.runSuite = function(suite, fn) {
6243
6316
  self.suite = suite;
6244
6317
  self.nextSuite = next;
6245
6318
 
6246
- if (afterAllHookCalled) {
6247
- fn(errSuite);
6248
- } else {
6249
- // mark that the afterAll block has been called once
6250
- // and so can be skipped if there is an error in it.
6251
- afterAllHookCalled = true;
6252
-
6253
- // remove reference to test
6254
- delete self.test;
6319
+ // remove reference to test
6320
+ delete self.test;
6255
6321
 
6256
- self.hook(HOOK_TYPE_AFTER_ALL, function() {
6257
- self.emit(constants.EVENT_SUITE_END, suite);
6258
- fn(errSuite);
6259
- });
6260
- }
6322
+ self.hook(HOOK_TYPE_AFTER_ALL, function() {
6323
+ self.emit(constants.EVENT_SUITE_END, suite);
6324
+ fn(errSuite);
6325
+ });
6261
6326
  }
6262
6327
 
6263
6328
  this.nextSuite = next;
@@ -6271,7 +6336,7 @@ Runner.prototype.runSuite = function(suite, fn) {
6271
6336
  };
6272
6337
 
6273
6338
  /**
6274
- * Handle uncaught exceptions.
6339
+ * Handle uncaught exceptions within runner.
6275
6340
  *
6276
6341
  * @param {Error} err
6277
6342
  * @private
@@ -6280,6 +6345,10 @@ Runner.prototype.uncaught = function(err) {
6280
6345
  if (err instanceof Pending) {
6281
6346
  return;
6282
6347
  }
6348
+ if (this.allowUncaught) {
6349
+ throw err;
6350
+ }
6351
+
6283
6352
  if (err) {
6284
6353
  debug('uncaught exception %O', err);
6285
6354
  } else {
@@ -6315,43 +6384,37 @@ Runner.prototype.uncaught = function(err) {
6315
6384
 
6316
6385
  runnable.clearTimeout();
6317
6386
 
6318
- // Ignore errors if already failed or pending
6319
- // See #3226
6320
- if (runnable.isFailed() || runnable.isPending()) {
6387
+ if (runnable.isFailed()) {
6388
+ // Ignore error if already failed
6389
+ return;
6390
+ } else if (runnable.isPending()) {
6391
+ // report 'pending test' retrospectively as failed
6392
+ runnable.isPending = alwaysFalse;
6393
+ this.fail(runnable, err);
6394
+ delete runnable.isPending;
6321
6395
  return;
6322
6396
  }
6397
+
6323
6398
  // we cannot recover gracefully if a Runnable has already passed
6324
6399
  // then fails asynchronously
6325
- var alreadyPassed = runnable.isPassed();
6326
- // this will change the state to "failed" regardless of the current value
6327
- this.fail(runnable, err);
6328
- if (!alreadyPassed) {
6329
- // recover from test
6330
- if (runnable.type === constants.EVENT_TEST_BEGIN) {
6331
- this.emit(constants.EVENT_TEST_END, runnable);
6332
- this.hookUp(HOOK_TYPE_AFTER_EACH, this.next);
6333
- return;
6334
- }
6400
+ if (runnable.isPassed()) {
6401
+ this.fail(runnable, err);
6402
+ this.abort();
6403
+ } else {
6335
6404
  debug(runnable);
6336
-
6337
- // recover from hooks
6338
- var errSuite = this.suite;
6339
-
6340
- // XXX how about a less awful way to determine this?
6341
- // if hook failure is in afterEach block
6342
- if (runnable.fullTitle().indexOf('after each') > -1) {
6343
- return this.hookErr(err, errSuite, true);
6344
- }
6345
- // if hook failure is in beforeEach block
6346
- if (runnable.fullTitle().indexOf('before each') > -1) {
6347
- return this.hookErr(err, errSuite, false);
6348
- }
6349
- // if hook failure is in after or before blocks
6350
- return this.nextSuite(errSuite);
6405
+ return runnable.callback(err);
6351
6406
  }
6407
+ };
6352
6408
 
6353
- // bail
6354
- this.abort();
6409
+ /**
6410
+ * Handle uncaught exceptions after runner's end event.
6411
+ *
6412
+ * @param {Error} err
6413
+ * @private
6414
+ */
6415
+ Runner.prototype.uncaughtEnd = function uncaughtEnd(err) {
6416
+ if (err instanceof Pending) return;
6417
+ throw err;
6355
6418
  };
6356
6419
 
6357
6420
  /**
@@ -6401,10 +6464,12 @@ Runner.prototype.run = function(fn) {
6401
6464
  this.on(constants.EVENT_RUN_END, function() {
6402
6465
  debug(constants.EVENT_RUN_END);
6403
6466
  process.removeListener('uncaughtException', uncaught);
6467
+ process.on('uncaughtException', self.uncaughtEnd);
6404
6468
  fn(self.failures);
6405
6469
  });
6406
6470
 
6407
6471
  // uncaught exception
6472
+ process.removeListener('uncaughtException', self.uncaughtEnd);
6408
6473
  process.on('uncaughtException', uncaught);
6409
6474
 
6410
6475
  if (this._delay) {
@@ -7352,80 +7417,6 @@ exports.isString = function(obj) {
7352
7417
  return typeof obj === 'string';
7353
7418
  };
7354
7419
 
7355
- /**
7356
- * Watch the given `files` for changes
7357
- * and invoke `fn(file)` on modification.
7358
- *
7359
- * @private
7360
- * @param {Array} files
7361
- * @param {Function} fn
7362
- */
7363
- exports.watch = function(files, fn) {
7364
- var options = {interval: 100};
7365
- var debug = require('debug')('mocha:watch');
7366
- files.forEach(function(file) {
7367
- debug('file %s', file);
7368
- fs.watchFile(file, options, function(curr, prev) {
7369
- if (prev.mtime < curr.mtime) {
7370
- fn(file);
7371
- }
7372
- });
7373
- });
7374
- };
7375
-
7376
- /**
7377
- * Predicate to screen `pathname` for further consideration.
7378
- *
7379
- * @description
7380
- * Returns <code>false</code> for pathname referencing:
7381
- * <ul>
7382
- * <li>'npm' package installation directory
7383
- * <li>'git' version control directory
7384
- * </ul>
7385
- *
7386
- * @private
7387
- * @param {string} pathname - File or directory name to screen
7388
- * @return {boolean} whether pathname should be further considered
7389
- * @example
7390
- * ['node_modules', 'test.js'].filter(considerFurther); // => ['test.js']
7391
- */
7392
- function considerFurther(pathname) {
7393
- var ignore = ['node_modules', '.git'];
7394
-
7395
- return !~ignore.indexOf(pathname);
7396
- }
7397
-
7398
- /**
7399
- * Lookup files in the given `dir`.
7400
- *
7401
- * @description
7402
- * Filenames are returned in _traversal_ order by the OS/filesystem.
7403
- * **Make no assumption that the names will be sorted in any fashion.**
7404
- *
7405
- * @private
7406
- * @param {string} dir
7407
- * @param {string[]} [exts=['js']]
7408
- * @param {Array} [ret=[]]
7409
- * @return {Array}
7410
- */
7411
- exports.files = function(dir, exts, ret) {
7412
- ret = ret || [];
7413
- exts = exts || ['js'];
7414
-
7415
- fs.readdirSync(dir)
7416
- .filter(considerFurther)
7417
- .forEach(function(dirent) {
7418
- var pathname = path.join(dir, dirent);
7419
- if (fs.lstatSync(pathname).isDirectory()) {
7420
- exports.files(pathname, exts, ret);
7421
- } else if (hasMatchingExtname(pathname, exts)) {
7422
- ret.push(pathname);
7423
- }
7424
- });
7425
-
7426
- return ret;
7427
- };
7428
-
7429
7420
  /**
7430
7421
  * Compute a slug from the given `str`.
7431
7422
  *
@@ -8206,7 +8197,7 @@ exports.defineConstants = function(obj) {
8206
8197
  };
8207
8198
 
8208
8199
  }).call(this,require('_process'),require("buffer").Buffer)
8209
- },{"./errors":6,"_process":69,"buffer":43,"debug":45,"fs":42,"glob":42,"he":54,"object.assign":65,"path":42,"util":89}],39:[function(require,module,exports){
8200
+ },{"./errors":6,"_process":69,"buffer":43,"fs":42,"glob":42,"he":54,"object.assign":65,"path":42,"util":89}],39:[function(require,module,exports){
8210
8201
  'use strict'
8211
8202
 
8212
8203
  exports.byteLength = byteLength
@@ -18086,7 +18077,7 @@ function hasOwnProperty(obj, prop) {
18086
18077
  },{"./support/isBuffer":88,"_process":69,"inherits":56}],90:[function(require,module,exports){
18087
18078
  module.exports={
18088
18079
  "name": "mocha",
18089
- "version": "6.2.2",
18080
+ "version": "7.0.1",
18090
18081
  "homepage": "https://mochajs.org/",
18091
18082
  "notifyLogo": "https://ibin.co/4QuRuGjXvl36.png"
18092
18083
  }