mocha 2.2.0 → 2.2.5

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/utils.js CHANGED
@@ -46,6 +46,17 @@ exports.forEach = function(arr, fn, scope){
46
46
  fn.call(scope, arr[i], i);
47
47
  };
48
48
 
49
+ /**
50
+ * Test if the given obj is type of string
51
+ *
52
+ * @param {Object} obj
53
+ * @returns Boolean
54
+ */
55
+
56
+ exports.isString = function(obj) {
57
+ return 'string' === typeof obj;
58
+ };
59
+
49
60
  /**
50
61
  * Array#map (<=IE8)
51
62
  *
@@ -237,7 +248,7 @@ exports.slug = function(str){
237
248
  exports.clean = function(str) {
238
249
  str = str
239
250
  .replace(/\r\n?|[\n\u2028\u2029]/g, "\n").replace(/^\uFEFF/, '')
240
- .replace(/^function *\(.*\) *{|\(.*\) *=> *{?/, '')
251
+ .replace(/^function *\(.*\)\s*{|\(.*\) *=> *{?/, '')
241
252
  .replace(/\s+\}$/, '');
242
253
 
243
254
  var spaces = str.match(/^\n?( *)/)[1].length
@@ -444,7 +455,10 @@ function jsonStringify(object, spaces, depth) {
444
455
  : val.toString();
445
456
  break;
446
457
  case 'date':
447
- val = '[Date: ' + val.toISOString() + ']';
458
+ var sDate = isNaN(val.getTime()) // Invalid date
459
+ ? val.toString()
460
+ : val.toISOString();
461
+ val = '[Date: ' + sDate + ']';
448
462
  break;
449
463
  case 'buffer':
450
464
  var json = val.toJSON();
@@ -455,7 +469,7 @@ function jsonStringify(object, spaces, depth) {
455
469
  default:
456
470
  val = (val == '[Function]' || val == '[Circular]')
457
471
  ? val
458
- : '"' + val + '"'; //string
472
+ : JSON.stringify(val); //string
459
473
  }
460
474
  return val;
461
475
  }
@@ -629,3 +643,68 @@ exports.getError = function(err) {
629
643
  return err || exports.undefinedError();
630
644
  };
631
645
 
646
+
647
+ /**
648
+ * @summary
649
+ * This Filter based on `mocha-clean` module.(see: `github.com/rstacruz/mocha-clean`)
650
+ * @description
651
+ * When invoking this function you get a filter function that get the Error.stack as an input,
652
+ * and return a prettify output.
653
+ * (i.e: strip Mocha, node_modules, bower and componentJS from stack trace).
654
+ * @returns {Function}
655
+ */
656
+
657
+ exports.stackTraceFilter = function() {
658
+ var slash = '/'
659
+ , is = typeof document === 'undefined'
660
+ ? { node: true }
661
+ : { browser: true }
662
+ , cwd = is.node
663
+ ? process.cwd() + slash
664
+ : location.href.replace(/\/[^\/]*$/, '/');
665
+
666
+ function isNodeModule (line) {
667
+ return (~line.indexOf('node_modules'));
668
+ }
669
+
670
+ function isMochaInternal (line) {
671
+ return (~line.indexOf('node_modules' + slash + 'mocha')) ||
672
+ (~line.indexOf('components' + slash + 'mochajs')) ||
673
+ (~line.indexOf('components' + slash + 'mocha'));
674
+ }
675
+
676
+ // node_modules, bower, componentJS
677
+ function isBrowserModule(line) {
678
+ return (~line.indexOf('node_modules')) ||
679
+ (~line.indexOf('components'));
680
+ }
681
+
682
+ function isNodeInternal (line) {
683
+ return (~line.indexOf('(timers.js:')) ||
684
+ (~line.indexOf('(events.js:')) ||
685
+ (~line.indexOf('(node.js:')) ||
686
+ (~line.indexOf('(module.js:')) ||
687
+ (~line.indexOf('GeneratorFunctionPrototype.next (native)')) ||
688
+ false
689
+ }
690
+
691
+ return function(stack) {
692
+ stack = stack.split('\n');
693
+
694
+ stack = exports.reduce(stack, function(list, line) {
695
+ if (is.node && (isNodeModule(line) ||
696
+ isMochaInternal(line) ||
697
+ isNodeInternal(line)))
698
+ return list;
699
+
700
+ if (is.browser && (isBrowserModule(line)))
701
+ return list;
702
+
703
+ // Clean up cwd(absolute)
704
+ list.push(line.replace(cwd, ''));
705
+ return list;
706
+ }, []);
707
+
708
+ return stack.join('\n');
709
+ }
710
+ };
package/mocha.js CHANGED
@@ -1470,6 +1470,7 @@ function image(name) {
1470
1470
  * - `bail` bail on the first test failure
1471
1471
  * - `slow` milliseconds to wait before considering a test slow
1472
1472
  * - `ignoreLeaks` ignore global leaks
1473
+ * - `fullTrace` display the full stack-trace on failing
1473
1474
  * - `grep` string or regexp to filter tests with
1474
1475
  *
1475
1476
  * @param {Object} options
@@ -1487,7 +1488,7 @@ function Mocha(options) {
1487
1488
  this.bail(options.bail);
1488
1489
  this.reporter(options.reporter, options.reporterOptions);
1489
1490
  if (null != options.timeout) this.timeout(options.timeout);
1490
- this.useColors(options.useColors)
1491
+ this.useColors(options.useColors);
1491
1492
  if (options.enableTimeouts !== null) this.enableTimeouts(options.enableTimeouts);
1492
1493
  if (options.slow) this.slow(options.slow);
1493
1494
 
@@ -1546,8 +1547,12 @@ Mocha.prototype.reporter = function(reporter, reporterOptions){
1546
1547
  } else {
1547
1548
  reporter = reporter || 'spec';
1548
1549
  var _reporter;
1549
- try { _reporter = require('./reporters/' + reporter); } catch (err) {};
1550
- if (!_reporter) try { _reporter = require(reporter); } catch (err) {};
1550
+ try { _reporter = require('./reporters/' + reporter); } catch (err) {}
1551
+ if (!_reporter) try { _reporter = require(reporter); } catch (err) {
1552
+ err.message.indexOf('Cannot find module') !== -1
1553
+ ? console.warn('"' + reporter + '" reporter not found')
1554
+ : console.warn('"' + reporter + '" reporter blew up with error:\n' + err.stack);
1555
+ }
1551
1556
  if (!_reporter && reporter === 'teamcity')
1552
1557
  console.warn('The Teamcity reporter was moved to a package named ' +
1553
1558
  'mocha-teamcity-reporter ' +
@@ -1569,7 +1574,7 @@ Mocha.prototype.reporter = function(reporter, reporterOptions){
1569
1574
  Mocha.prototype.ui = function(name){
1570
1575
  name = name || 'bdd';
1571
1576
  this._ui = exports.interfaces[name];
1572
- if (!this._ui) try { this._ui = require(name); } catch (err) {};
1577
+ if (!this._ui) try { this._ui = require(name); } catch (err) {}
1573
1578
  if (!this._ui) throw new Error('invalid interface "' + name + '"');
1574
1579
  this._ui = this._ui(this.suite);
1575
1580
  return this;
@@ -1670,6 +1675,18 @@ Mocha.prototype.checkLeaks = function(){
1670
1675
  return this;
1671
1676
  };
1672
1677
 
1678
+ /**
1679
+ * Display long stack-trace on failing
1680
+ *
1681
+ * @return {Mocha}
1682
+ * @api public
1683
+ */
1684
+
1685
+ Mocha.prototype.fullTrace = function() {
1686
+ this.options.fullStackTrace = true;
1687
+ return this;
1688
+ };
1689
+
1673
1690
  /**
1674
1691
  * Enable growl support.
1675
1692
  *
@@ -1813,6 +1830,7 @@ Mocha.prototype.run = function(fn){
1813
1830
  var runner = new exports.Runner(suite, options.delay);
1814
1831
  var reporter = new this._reporter(runner, options);
1815
1832
  runner.ignoreLeaks = false !== options.ignoreLeaks;
1833
+ runner.fullStackTrace = options.fullStackTrace;
1816
1834
  runner.asyncOnly = options.asyncOnly;
1817
1835
  if (options.grep) runner.grep(options.grep, options.invert);
1818
1836
  if (options.globals) runner.globals(options.globals);
@@ -2137,18 +2155,26 @@ exports.list = function(failures){
2137
2155
  var err = test.err
2138
2156
  , message = err.message || ''
2139
2157
  , stack = err.stack || message
2140
- , index = stack.indexOf(message) + message.length
2141
- , msg = stack.slice(0, index)
2158
+ , index = stack.indexOf(message)
2142
2159
  , actual = err.actual
2143
2160
  , expected = err.expected
2144
2161
  , escape = true;
2162
+ if (index === -1) {
2163
+ msg = message;
2164
+ } else {
2165
+ index += message.length;
2166
+ msg = stack.slice(0, index);
2167
+ // remove msg from stack
2168
+ stack = stack.slice(index + 1);
2169
+ }
2145
2170
 
2146
2171
  // uncaught
2147
2172
  if (err.uncaught) {
2148
2173
  msg = 'Uncaught ' + msg;
2149
2174
  }
2150
2175
  // explicitly show diff
2151
- if (err.showDiff && sameType(actual, expected)) {
2176
+ if (err.showDiff !== false && sameType(actual, expected)
2177
+ && expected !== undefined) {
2152
2178
 
2153
2179
  if ('string' !== typeof actual) {
2154
2180
  escape = false;
@@ -2167,9 +2193,8 @@ exports.list = function(failures){
2167
2193
  }
2168
2194
  }
2169
2195
 
2170
- // indent stack trace without msg
2171
- stack = stack.slice(index ? index + 1 : index)
2172
- .replace(/^/gm, ' ');
2196
+ // indent stack trace
2197
+ stack = stack.replace(/^/gm, ' ');
2173
2198
 
2174
2199
  console.log(fmt, (i + 1), test.fullTitle(), msg, stack);
2175
2200
  });
@@ -2525,7 +2550,7 @@ function Dot(runner) {
2525
2550
  , n = -1;
2526
2551
 
2527
2552
  runner.on('start', function(){
2528
- process.stdout.write('\n ');
2553
+ process.stdout.write('\n');
2529
2554
  });
2530
2555
 
2531
2556
  runner.on('pending', function(test){
@@ -3998,14 +4023,14 @@ function Spec(runner) {
3998
4023
  if ('fast' == test.speed) {
3999
4024
  var fmt = indent()
4000
4025
  + color('checkmark', ' ' + Base.symbols.ok)
4001
- + color('pass', ' %s ');
4026
+ + color('pass', ' %s');
4002
4027
  cursor.CR();
4003
4028
  console.log(fmt, test.title);
4004
4029
  } else {
4005
4030
  var fmt = indent()
4006
4031
  + color('checkmark', ' ' + Base.symbols.ok)
4007
- + color('pass', ' %s ')
4008
- + color(test.speed, '(%dms)');
4032
+ + color('pass', ' %s')
4033
+ + color(test.speed, ' (%dms)');
4009
4034
  cursor.CR();
4010
4035
  console.log(fmt, test.title, test.duration);
4011
4036
  }
@@ -4565,7 +4590,8 @@ var EventEmitter = require('browser/events').EventEmitter
4565
4590
  , filter = utils.filter
4566
4591
  , keys = utils.keys
4567
4592
  , type = utils.type
4568
- , stringify = utils.stringify;
4593
+ , stringify = utils.stringify
4594
+ , stackFilter = utils.stackTraceFilter();
4569
4595
 
4570
4596
  /**
4571
4597
  * Non-enumerable globals.
@@ -4756,16 +4782,18 @@ Runner.prototype.checkGlobals = function(test){
4756
4782
  * @api private
4757
4783
  */
4758
4784
 
4759
- Runner.prototype.fail = function(test, err){
4785
+ Runner.prototype.fail = function(test, err) {
4760
4786
  ++this.failures;
4761
4787
  test.state = 'failed';
4762
4788
 
4763
- if ('string' == typeof err) {
4764
- err = new Error('the string "' + err + '" was thrown, throw an Error :)');
4765
- } else if (!(err instanceof Error)) {
4789
+ if (!(err instanceof Error)) {
4766
4790
  err = new Error('the ' + type(err) + ' ' + stringify(err) + ' was thrown, throw an Error :)');
4767
4791
  }
4768
4792
 
4793
+ err.stack = (this.fullStackTrace || !err.stack)
4794
+ ? err.stack
4795
+ : stackFilter(err.stack);
4796
+
4769
4797
  this.emit('fail', test, err);
4770
4798
  };
4771
4799
 
@@ -5253,24 +5281,24 @@ function filterLeaks(ok, globals) {
5253
5281
  * @api private
5254
5282
  */
5255
5283
 
5256
- function extraGlobals() {
5257
- if (typeof(process) === 'object' &&
5258
- typeof(process.version) === 'string') {
5284
+ function extraGlobals() {
5285
+ if (typeof(process) === 'object' &&
5286
+ typeof(process.version) === 'string') {
5259
5287
 
5260
- var nodeVersion = process.version.split('.').reduce(function(a, v) {
5261
- return a << 8 | v;
5262
- });
5288
+ var nodeVersion = process.version.split('.').reduce(function(a, v) {
5289
+ return a << 8 | v;
5290
+ });
5263
5291
 
5264
- // 'errno' was renamed to process._errno in v0.9.11.
5292
+ // 'errno' was renamed to process._errno in v0.9.11.
5265
5293
 
5266
- if (nodeVersion < 0x00090B) {
5267
- return ['errno'];
5268
- }
5269
- }
5270
-
5271
- return [];
5294
+ if (nodeVersion < 0x00090B) {
5295
+ return ['errno'];
5296
+ }
5272
5297
  }
5273
5298
 
5299
+ return [];
5300
+ }
5301
+
5274
5302
  }); // module: runner.js
5275
5303
 
5276
5304
  require.register("suite.js", function(module, exports, require){
@@ -5915,7 +5943,7 @@ exports.slug = function(str){
5915
5943
  exports.clean = function(str) {
5916
5944
  str = str
5917
5945
  .replace(/\r\n?|[\n\u2028\u2029]/g, "\n").replace(/^\uFEFF/, '')
5918
- .replace(/^function *\(.*\) *{|\(.*\) *=> *{?/, '')
5946
+ .replace(/^function *\(.*\)\s*{|\(.*\) *=> *{?/, '')
5919
5947
  .replace(/\s+\}$/, '');
5920
5948
 
5921
5949
  var spaces = str.match(/^\n?( *)/)[1].length
@@ -6308,6 +6336,70 @@ exports.getError = function(err) {
6308
6336
  };
6309
6337
 
6310
6338
 
6339
+ /**
6340
+ * @summary
6341
+ * This Filter based on `mocha-clean` module.(see: `github.com/rstacruz/mocha-clean`)
6342
+ * @description
6343
+ * When invoking this function you get a filter function that get the Error.stack as an input,
6344
+ * and return a prettify output.
6345
+ * (i.e: strip Mocha, node_modules, bower and componentJS from stack trace).
6346
+ * @returns {Function}
6347
+ */
6348
+
6349
+ exports.stackTraceFilter = function() {
6350
+ var slash = '/'
6351
+ , is = typeof document === 'undefined'
6352
+ ? { node: true }
6353
+ : { browser: true }
6354
+ , cwd = is.node
6355
+ ? process.cwd() + slash
6356
+ : location.href.replace(/\/[^\/]*$/, '/');
6357
+
6358
+ function isNodeModule (line) {
6359
+ return (~line.indexOf('node_modules'));
6360
+ }
6361
+
6362
+ function isMochaInternal (line) {
6363
+ return (~line.indexOf('node_modules' + slash + 'mocha')) ||
6364
+ (~line.indexOf('components' + slash + 'mochajs')) ||
6365
+ (~line.indexOf('components' + slash + 'mocha'));
6366
+ }
6367
+
6368
+ // node_modules, bower, componentJS
6369
+ function isBrowserModule(line) {
6370
+ return (~line.indexOf('node_modules')) ||
6371
+ (~line.indexOf('components'));
6372
+ }
6373
+
6374
+ function isNodeInternal (line) {
6375
+ return (~line.indexOf('(timers.js:')) ||
6376
+ (~line.indexOf('(events.js:')) ||
6377
+ (~line.indexOf('(node.js:')) ||
6378
+ (~line.indexOf('(module.js:')) ||
6379
+ (~line.indexOf('GeneratorFunctionPrototype.next (native)')) ||
6380
+ false
6381
+ }
6382
+
6383
+ return function(stack) {
6384
+ stack = stack.split('\n');
6385
+
6386
+ stack = exports.reduce(stack, function(list, line) {
6387
+ if (is.node && (isNodeModule(line) ||
6388
+ isMochaInternal(line) ||
6389
+ isNodeInternal(line)))
6390
+ return list;
6391
+
6392
+ if (is.browser && (isBrowserModule(line)))
6393
+ return list;
6394
+
6395
+ // Clean up cwd(absolute)
6396
+ list.push(line.replace(cwd, ''));
6397
+ return list;
6398
+ }, []);
6399
+
6400
+ return stack.join('\n');
6401
+ }
6402
+ };
6311
6403
  }); // module: utils.js
6312
6404
  // The global object is "self" in Web Workers.
6313
6405
  var global = (function() { return this; })();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mocha",
3
- "version": "2.2.0",
3
+ "version": "2.2.5",
4
4
  "description": "simple, flexible, fun test framework",
5
5
  "keywords": [
6
6
  "mocha",
@@ -12,14 +12,15 @@
12
12
  "author": "TJ Holowaychuk <tj@vision-media.ca>",
13
13
  "contributors": [
14
14
  "Joshua Appelman <joshua@jbna.nl>",
15
- "Oleg Gaidarenko <markelog@gmail.com>",
16
15
  "Christoffer Hallas <christoffer.hallas@gmail.com>",
17
16
  "Christopher Hiller <chiller@badwing.com>",
18
17
  "Travis Jeffery <tj@travisjeffery.com>",
19
- "Johnathan Ong <me@jongleberry.com>",
20
- "Guillermo Rauch <rauchg@gmail.com>",
21
- "Nathan Rajlich <nathan@tootallnate.net>"
18
+ "Daniel St. Jules <danielst.jules@gmail.com>",
19
+ "David da Silva Contín <dasilvacontin@gmail.com>",
20
+ "Ariel Mashraki <ariel@mashraki.co.il>",
21
+ "Pawel Kozlowski <pkozlowski.opensource@gmail.com>"
22
22
  ],
23
+ "license": "MIT",
23
24
  "repository": {
24
25
  "type": "git",
25
26
  "url": "git://github.com/mochajs/mocha.git"
@@ -44,7 +45,7 @@
44
45
  "dependencies": {
45
46
  "commander": "2.3.0",
46
47
  "debug": "2.0.0",
47
- "diff": "1.0.8",
48
+ "diff": "1.4.0",
48
49
  "escape-string-regexp": "1.0.2",
49
50
  "glob": "3.2.3",
50
51
  "growl": "1.8.1",