mocha 4.0.1 → 4.1.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
@@ -366,7 +366,7 @@ Context.prototype.runnable = function (runnable) {
366
366
  };
367
367
 
368
368
  /**
369
- * Set test timeout `ms`.
369
+ * Set or get test timeout `ms`.
370
370
  *
371
371
  * @api private
372
372
  * @param {number} ms
@@ -388,18 +388,24 @@ Context.prototype.timeout = function (ms) {
388
388
  * @return {Context} self
389
389
  */
390
390
  Context.prototype.enableTimeouts = function (enabled) {
391
+ if (!arguments.length) {
392
+ return this.runnable().enableTimeouts();
393
+ }
391
394
  this.runnable().enableTimeouts(enabled);
392
395
  return this;
393
396
  };
394
397
 
395
398
  /**
396
- * Set test slowness threshold `ms`.
399
+ * Set or get test slowness threshold `ms`.
397
400
  *
398
401
  * @api private
399
402
  * @param {number} ms
400
403
  * @return {Context} self
401
404
  */
402
405
  Context.prototype.slow = function (ms) {
406
+ if (!arguments.length) {
407
+ return this.runnable().slow();
408
+ }
403
409
  this.runnable().slow(ms);
404
410
  return this;
405
411
  };
@@ -415,7 +421,7 @@ Context.prototype.skip = function () {
415
421
  };
416
422
 
417
423
  /**
418
- * Allow a number of retries on failed tests
424
+ * Set or get a number of allowed retries on failed tests
419
425
  *
420
426
  * @api private
421
427
  * @param {number} n
@@ -429,18 +435,6 @@ Context.prototype.retries = function (n) {
429
435
  return this;
430
436
  };
431
437
 
432
- /**
433
- * Inspect the context void of `._runnable`.
434
- *
435
- * @api private
436
- * @return {string}
437
- */
438
- Context.prototype.inspect = function () {
439
- return JSON.stringify(this, function (key, val) {
440
- return key === 'runnable' || key === 'test' ? undefined : val;
441
- }, 2);
442
- };
443
-
444
438
  },{}],6:[function(require,module,exports){
445
439
  'use strict';
446
440
 
@@ -596,7 +590,7 @@ module.exports = function (suite) {
596
590
  */
597
591
 
598
592
  context.xit = context.xspecify = context.it.skip = function (title) {
599
- context.it(title);
593
+ return context.it(title);
600
594
  };
601
595
 
602
596
  /**
@@ -1440,6 +1434,20 @@ Mocha.prototype.useInlineDiffs = function (inlineDiffs) {
1440
1434
  return this;
1441
1435
  };
1442
1436
 
1437
+ /**
1438
+ * Do not show diffs at all.
1439
+ *
1440
+ * @param {Boolean} hideDiff
1441
+ * @return {Mocha}
1442
+ * @api public
1443
+ * @param {boolean} hideDiff
1444
+ * @return {Mocha}
1445
+ */
1446
+ Mocha.prototype.hideDiff = function (hideDiff) {
1447
+ this.options.hideDiff = hideDiff !== undefined && hideDiff;
1448
+ return this;
1449
+ };
1450
+
1443
1451
  /**
1444
1452
  * Set the timeout in milliseconds.
1445
1453
  *
@@ -1556,6 +1564,14 @@ Mocha.prototype.forbidPending = function () {
1556
1564
  /**
1557
1565
  * Run tests and invoke `fn()` when complete.
1558
1566
  *
1567
+ * Note that `loadFiles` relies on Node's `require` to execute
1568
+ * the test interface functions and will be subject to the
1569
+ * cache - if the files are already in the `require` cache,
1570
+ * they will effectively be skipped. Therefore, to run tests
1571
+ * multiple times or to run tests in files that are already
1572
+ * in the `require` cache, make sure to clear them from the
1573
+ * cache first in whichever manner best suits your needs.
1574
+ *
1559
1575
  * @api public
1560
1576
  * @param {Function} fn
1561
1577
  * @return {Runner}
@@ -1588,6 +1604,7 @@ Mocha.prototype.run = function (fn) {
1588
1604
  exports.reporters.Base.useColors = options.useColors;
1589
1605
  }
1590
1606
  exports.reporters.Base.inlineDiffs = options.useInlineDiffs;
1607
+ exports.reporters.Base.hideDiff = options.hideDiff;
1591
1608
 
1592
1609
  function done (failures) {
1593
1610
  if (reporter.done) {
@@ -1617,22 +1634,15 @@ var y = d * 365.25;
1617
1634
  /**
1618
1635
  * Parse or format the given `val`.
1619
1636
  *
1620
- * Options:
1621
- *
1622
- * - `long` verbose formatting [false]
1623
- *
1624
1637
  * @api public
1625
1638
  * @param {string|number} val
1626
- * @param {Object} options
1627
1639
  * @return {string|number}
1628
1640
  */
1629
- module.exports = function (val, options) {
1630
- options = options || {};
1641
+ module.exports = function (val) {
1631
1642
  if (typeof val === 'string') {
1632
1643
  return parse(val);
1633
1644
  }
1634
- // https://github.com/mochajs/mocha/pull/1035
1635
- return options['long'] ? longFormat(val) : shortFormat(val);
1645
+ return format(val);
1636
1646
  };
1637
1647
 
1638
1648
  /**
@@ -1678,13 +1688,13 @@ function parse (str) {
1678
1688
  }
1679
1689
 
1680
1690
  /**
1681
- * Short format for `ms`.
1691
+ * Format for `ms`.
1682
1692
  *
1683
1693
  * @api private
1684
1694
  * @param {number} ms
1685
1695
  * @return {string}
1686
1696
  */
1687
- function shortFormat (ms) {
1697
+ function format (ms) {
1688
1698
  if (ms >= d) {
1689
1699
  return Math.round(ms / d) + 'd';
1690
1700
  }
@@ -1700,39 +1710,6 @@ function shortFormat (ms) {
1700
1710
  return ms + 'ms';
1701
1711
  }
1702
1712
 
1703
- /**
1704
- * Long format for `ms`.
1705
- *
1706
- * @api private
1707
- * @param {number} ms
1708
- * @return {string}
1709
- */
1710
- function longFormat (ms) {
1711
- return plural(ms, d, 'day') ||
1712
- plural(ms, h, 'hour') ||
1713
- plural(ms, m, 'minute') ||
1714
- plural(ms, s, 'second') ||
1715
- ms + ' ms';
1716
- }
1717
-
1718
- /**
1719
- * Pluralization helper.
1720
- *
1721
- * @api private
1722
- * @param {number} ms
1723
- * @param {number} n
1724
- * @param {string} name
1725
- */
1726
- function plural (ms, n, name) {
1727
- if (ms < n) {
1728
- return;
1729
- }
1730
- if (ms < n * 1.5) {
1731
- return Math.floor(ms / n) + ' ' + name;
1732
- }
1733
- return Math.ceil(ms / n) + ' ' + name + 's';
1734
- }
1735
-
1736
1713
  },{}],15:[function(require,module,exports){
1737
1714
  'use strict';
1738
1715
 
@@ -1910,6 +1887,17 @@ exports.cursor = {
1910
1887
  }
1911
1888
  };
1912
1889
 
1890
+ function showDiff (err) {
1891
+ return err && err.showDiff !== false && sameType(err.actual, err.expected) && err.expected !== undefined;
1892
+ }
1893
+
1894
+ function stringifyDiffObjs (err) {
1895
+ if (!utils.isString(err.actual) || !utils.isString(err.expected)) {
1896
+ err.actual = utils.stringify(err.actual);
1897
+ err.expected = utils.stringify(err.expected);
1898
+ }
1899
+ }
1900
+
1913
1901
  /**
1914
1902
  * Output the given `failures` as a list.
1915
1903
  *
@@ -1938,9 +1926,6 @@ exports.list = function (failures) {
1938
1926
  }
1939
1927
  var stack = err.stack || message;
1940
1928
  var index = message ? stack.indexOf(message) : -1;
1941
- var actual = err.actual;
1942
- var expected = err.expected;
1943
- var escape = true;
1944
1929
 
1945
1930
  if (index === -1) {
1946
1931
  msg = message;
@@ -1956,21 +1941,16 @@ exports.list = function (failures) {
1956
1941
  msg = 'Uncaught ' + msg;
1957
1942
  }
1958
1943
  // explicitly show diff
1959
- if (err.showDiff !== false && sameType(actual, expected) && expected !== undefined) {
1960
- escape = false;
1961
- if (!(utils.isString(actual) && utils.isString(expected))) {
1962
- err.actual = actual = utils.stringify(actual);
1963
- err.expected = expected = utils.stringify(expected);
1964
- }
1965
-
1944
+ if (!exports.hideDiff && showDiff(err)) {
1945
+ stringifyDiffObjs(err);
1966
1946
  fmt = color('error title', ' %s) %s:\n%s') + color('error stack', '\n%s\n');
1967
1947
  var match = message.match(/^([^:]+): expected/);
1968
1948
  msg = '\n ' + color('error message', match ? match[1] : msg);
1969
1949
 
1970
1950
  if (exports.inlineDiffs) {
1971
- msg += inlineDiff(err, escape);
1951
+ msg += inlineDiff(err);
1972
1952
  } else {
1973
- msg += unifiedDiff(err, escape);
1953
+ msg += unifiedDiff(err);
1974
1954
  }
1975
1955
  }
1976
1956
 
@@ -2047,6 +2027,9 @@ function Base (runner) {
2047
2027
  runner.on('fail', function (test, err) {
2048
2028
  stats.failures = stats.failures || 0;
2049
2029
  stats.failures++;
2030
+ if (showDiff(err)) {
2031
+ stringifyDiffObjs(err);
2032
+ }
2050
2033
  test.err = err;
2051
2034
  failures.push(test);
2052
2035
  });
@@ -2121,11 +2104,10 @@ function pad (str, len) {
2121
2104
  *
2122
2105
  * @api private
2123
2106
  * @param {Error} err with actual/expected
2124
- * @param {boolean} escape
2125
2107
  * @return {string} Diff
2126
2108
  */
2127
- function inlineDiff (err, escape) {
2128
- var msg = errorDiff(err, 'WordsWithSpace', escape);
2109
+ function inlineDiff (err) {
2110
+ var msg = errorDiff(err);
2129
2111
 
2130
2112
  // linenos
2131
2113
  var lines = msg.split('\n');
@@ -2155,15 +2137,11 @@ function inlineDiff (err, escape) {
2155
2137
  *
2156
2138
  * @api private
2157
2139
  * @param {Error} err with actual/expected
2158
- * @param {boolean} escape
2159
2140
  * @return {string} The diff.
2160
2141
  */
2161
- function unifiedDiff (err, escape) {
2142
+ function unifiedDiff (err) {
2162
2143
  var indent = ' ';
2163
2144
  function cleanUp (line) {
2164
- if (escape) {
2165
- line = escapeInvisibles(line);
2166
- }
2167
2145
  if (line[0] === '+') {
2168
2146
  return indent + colorLines('diff added', line);
2169
2147
  }
@@ -2195,14 +2173,10 @@ function unifiedDiff (err, escape) {
2195
2173
  *
2196
2174
  * @api private
2197
2175
  * @param {Error} err
2198
- * @param {string} type
2199
- * @param {boolean} escape
2200
2176
  * @return {string}
2201
2177
  */
2202
- function errorDiff (err, type, escape) {
2203
- var actual = escape ? escapeInvisibles(err.actual) : err.actual;
2204
- var expected = escape ? escapeInvisibles(err.expected) : err.expected;
2205
- return diff['diff' + type](actual, expected).map(function (str) {
2178
+ function errorDiff (err) {
2179
+ return diff.diffWordsWithSpace(err.actual, err.expected).map(function (str) {
2206
2180
  if (str.added) {
2207
2181
  return colorLines('diff added', str.value);
2208
2182
  }
@@ -2213,19 +2187,6 @@ function errorDiff (err, type, escape) {
2213
2187
  }).join('');
2214
2188
  }
2215
2189
 
2216
- /**
2217
- * Returns a string with all invisible characters in plain text
2218
- *
2219
- * @api private
2220
- * @param {string} line
2221
- * @return {string}
2222
- */
2223
- function escapeInvisibles (line) {
2224
- return line.replace(/\t/g, '<tab>')
2225
- .replace(/\r/g, '<CR>')
2226
- .replace(/\n/g, '<LF>\n');
2227
- }
2228
-
2229
2190
  /**
2230
2191
  * Color lines for `str`, using the color `name`.
2231
2192
  *
@@ -3551,11 +3512,13 @@ function Progress (runner, options) {
3551
3512
 
3552
3513
  // default chars
3553
3514
  options = options || {};
3554
- options.open = options.open || '[';
3555
- options.complete = options.complete || '▬';
3556
- options.incomplete = options.incomplete || Base.symbols.dot;
3557
- options.close = options.close || ']';
3558
- options.verbose = false;
3515
+ var reporterOptions = options.reporterOptions || {};
3516
+
3517
+ options.open = reporterOptions.open || '[';
3518
+ options.complete = reporterOptions.complete || '';
3519
+ options.incomplete = reporterOptions.incomplete || Base.symbols.dot;
3520
+ options.close = reporterOptions.close || ']';
3521
+ options.verbose = reporterOptions.verbose || false;
3559
3522
 
3560
3523
  // tests started
3561
3524
  runner.on('start', function () {
@@ -4040,14 +4003,14 @@ Runnable.prototype.timeout = function (ms) {
4040
4003
  };
4041
4004
 
4042
4005
  /**
4043
- * Set & get slow `ms`.
4006
+ * Set or get slow `ms`.
4044
4007
  *
4045
4008
  * @api private
4046
4009
  * @param {number|string} ms
4047
4010
  * @return {Runnable|number} ms or Runnable instance.
4048
4011
  */
4049
4012
  Runnable.prototype.slow = function (ms) {
4050
- if (typeof ms === 'undefined') {
4013
+ if (!arguments.length || typeof ms === 'undefined') {
4051
4014
  return this._slow;
4052
4015
  }
4053
4016
  if (typeof ms === 'string') {
@@ -4093,7 +4056,7 @@ Runnable.prototype.isPending = function () {
4093
4056
  };
4094
4057
 
4095
4058
  /**
4096
- * Set number of retries.
4059
+ * Set or get number of retries.
4097
4060
  *
4098
4061
  * @api private
4099
4062
  */
@@ -4105,7 +4068,7 @@ Runnable.prototype.retries = function (n) {
4105
4068
  };
4106
4069
 
4107
4070
  /**
4108
- * Get current retry
4071
+ * Set or get current retry
4109
4072
  *
4110
4073
  * @api private
4111
4074
  */
@@ -4191,7 +4154,7 @@ Runnable.prototype.resetTimeout = function () {
4191
4154
  };
4192
4155
 
4193
4156
  /**
4194
- * Whitelist a list of globals for this test run.
4157
+ * Set or get a list of whitelisted globals for this test run.
4195
4158
  *
4196
4159
  * @api private
4197
4160
  * @param {string[]} globals
@@ -5422,7 +5385,7 @@ Suite.prototype.clone = function () {
5422
5385
  };
5423
5386
 
5424
5387
  /**
5425
- * Set timeout `ms` or short-hand such as "2s".
5388
+ * Set or get timeout `ms` or short-hand such as "2s".
5426
5389
  *
5427
5390
  * @api private
5428
5391
  * @param {number|string} ms
@@ -5444,7 +5407,7 @@ Suite.prototype.timeout = function (ms) {
5444
5407
  };
5445
5408
 
5446
5409
  /**
5447
- * Set number of times to retry a failed test.
5410
+ * Set or get number of times to retry a failed test.
5448
5411
  *
5449
5412
  * @api private
5450
5413
  * @param {number|string} n
@@ -5460,7 +5423,7 @@ Suite.prototype.retries = function (n) {
5460
5423
  };
5461
5424
 
5462
5425
  /**
5463
- * Set timeout to `enabled`.
5426
+ * Set or get timeout to `enabled`.
5464
5427
  *
5465
5428
  * @api private
5466
5429
  * @param {boolean} enabled
@@ -5476,7 +5439,7 @@ Suite.prototype.enableTimeouts = function (enabled) {
5476
5439
  };
5477
5440
 
5478
5441
  /**
5479
- * Set slow `ms` or short-hand such as "2s".
5442
+ * Set or get slow `ms` or short-hand such as "2s".
5480
5443
  *
5481
5444
  * @api private
5482
5445
  * @param {number|string} ms
@@ -5495,7 +5458,7 @@ Suite.prototype.slow = function (ms) {
5495
5458
  };
5496
5459
 
5497
5460
  /**
5498
- * Sets whether to bail after first error.
5461
+ * Set or get whether to bail after first error.
5499
5462
  *
5500
5463
  * @api private
5501
5464
  * @param {boolean} bail
@@ -6275,7 +6238,6 @@ exports.canonicalize = function canonicalize (value, stack, typeHint) {
6275
6238
  */
6276
6239
  exports.lookupFiles = function lookupFiles (path, extensions, recursive) {
6277
6240
  var files = [];
6278
- var re = new RegExp('\\.(' + extensions.join('|') + ')$');
6279
6241
 
6280
6242
  if (!exists(path)) {
6281
6243
  if (exists(path + '.js')) {
@@ -6313,6 +6275,7 @@ exports.lookupFiles = function lookupFiles (path, extensions, recursive) {
6313
6275
  // ignore error
6314
6276
  return;
6315
6277
  }
6278
+ var re = new RegExp('\\.(?:' + extensions.join('|') + ')$');
6316
6279
  if (!stat.isFile() || !re.test(file) || basename(file)[0] === '.') {
6317
6280
  return;
6318
6281
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mocha",
3
- "version": "4.0.1",
3
+ "version": "4.1.0",
4
4
  "description": "simple, flexible, fun test framework",
5
5
  "keywords": [
6
6
  "mocha",
@@ -198,6 +198,7 @@
198
198
  "Nathan Houle <nathan+github@nathanhoule.com> (https://github.com/ndhoule)",
199
199
  "Nathan Rajlich <nathan@tootallnate.net> (https://github.com/TooTallNate)",
200
200
  "Nick Fitzgerald (https://github.com/fitzgen)",
201
+ "Nikolaos Georgiou (https://github.com/ngeor)",
201
202
  "noirlab (https://github.com/noirlab)",
202
203
  "Noshir Patel <nosh@blackpiano.com> (https://github.com/noshir-patel)",
203
204
  "OlegTsyba <oleg.tsyba.ua@gmail.com> (https://github.com/OlegTsyba)",
@@ -295,14 +296,18 @@
295
296
  "_mocha": "./bin/_mocha"
296
297
  },
297
298
  "engines": {
298
- "node": ">= 4.0.0",
299
- "npm": ">= 2.15.11"
299
+ "node": ">= 4.0.0"
300
300
  },
301
301
  "scripts": {
302
302
  "lint": "eslint . bin/*",
303
303
  "test": "make clean && make test",
304
304
  "prepublishOnly": "npm test && make clean && make mocha.js",
305
- "coveralls": "nyc report --reporter=text-lcov | coveralls"
305
+ "coveralls": "nyc report --reporter=text-lcov | coveralls",
306
+ "prebuildDocs": "rm -rf docs/_dist && node scripts/docs-update-toc.js",
307
+ "buildDocs": "bundle exec jekyll build --source ./docs --destination ./docs/_site --config ./docs/_config.yml --safe --drafts",
308
+ "postbuildDocs": "buildProduction docs/_site/index.html --outroot docs/_dist --canonicalroot https://mochajs.org/ --optimizeimages --svgo --inlinehtmlimage 9400 --inlinehtmlscript 0 --asyncscripts && cp docs/_headers docs/_dist/_headers && node scripts/netlify-headers.js >> docs/_dist/_headers",
309
+ "prewatchDocs": "node scripts/docs-update-toc.js",
310
+ "watchDocs": "bundle exec jekyll serve --source ./docs --destination ./docs/_site --config ./docs/_config.yml --safe --drafts --watch"
306
311
  },
307
312
  "dependencies": {
308
313
  "browser-stdout": "1.3.0",
@@ -318,6 +323,7 @@
318
323
  },
319
324
  "devDependencies": {
320
325
  "assert": "^1.4.1",
326
+ "assetgraph-builder": "^5.6.4",
321
327
  "browserify": "^14.4.0",
322
328
  "buffer": "^4.9.1",
323
329
  "coffee-script": "^1.10.0",
@@ -339,9 +345,10 @@
339
345
  "karma-mocha-reporter": "^2.2.4",
340
346
  "karma-phantomjs-launcher": "^1.0.4",
341
347
  "karma-sauce-launcher": "^1.2.0",
348
+ "markdown-toc": "^1.2.0",
342
349
  "nyc": "^11.2.1",
343
350
  "rimraf": "^2.5.2",
344
- "should": "^13.1.0",
351
+ "svgo": "^0.7.2",
345
352
  "through2": "^2.0.1",
346
353
  "watchify": "^3.7.0"
347
354
  },