mocha 1.8.1 → 1.11.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,6 +1,5 @@
1
1
  ;(function(){
2
2
 
3
-
4
3
  // CommonJS require()
5
4
 
6
5
  function require(p){
@@ -32,11 +31,11 @@ require.register = function (path, fn){
32
31
  require.relative = function (parent) {
33
32
  return function(p){
34
33
  if ('.' != p.charAt(0)) return require(p);
35
-
34
+
36
35
  var path = parent.split('/')
37
36
  , segs = p.split('/');
38
37
  path.pop();
39
-
38
+
40
39
  for (var i = 0; i < segs.length; i++) {
41
40
  var seg = segs[i];
42
41
  if ('..' == seg) path.pop();
@@ -52,9 +51,9 @@ require.register("browser/debug.js", function(module, exports, require){
52
51
 
53
52
  module.exports = function(type){
54
53
  return function(){
55
-
56
54
  }
57
55
  };
56
+
58
57
  }); // module: browser/debug.js
59
58
 
60
59
  require.register("browser/diff.js", function(module, exports, require){
@@ -805,7 +804,6 @@ Hook.prototype.error = function(err){
805
804
  this._error = err;
806
805
  };
807
806
 
808
-
809
807
  }); // module: hook.js
810
808
 
811
809
  require.register("interfaces/bdd.js", function(module, exports, require){
@@ -819,7 +817,7 @@ var Suite = require('../suite')
819
817
 
820
818
  /**
821
819
  * BDD-style interface:
822
- *
820
+ *
823
821
  * describe('Array', function(){
824
822
  * describe('#indexOf()', function(){
825
823
  * it('should return -1 when not present', function(){
@@ -831,7 +829,7 @@ var Suite = require('../suite')
831
829
  * });
832
830
  * });
833
831
  * });
834
- *
832
+ *
835
833
  */
836
834
 
837
835
  module.exports = function(suite){
@@ -876,7 +874,7 @@ module.exports = function(suite){
876
874
  * and callback `fn` containing nested suites
877
875
  * and/or tests.
878
876
  */
879
-
877
+
880
878
  context.describe = context.context = function(title, fn){
881
879
  var suite = Suite.create(suites[0], title);
882
880
  suites.unshift(suite);
@@ -956,19 +954,19 @@ var Suite = require('../suite')
956
954
 
957
955
  /**
958
956
  * TDD-style interface:
959
- *
957
+ *
960
958
  * exports.Array = {
961
959
  * '#indexOf()': {
962
960
  * 'should return -1 when the value is not present': function(){
963
- *
961
+ *
964
962
  * },
965
963
  *
966
964
  * 'should return the correct index when the value is present': function(){
967
- *
965
+ *
968
966
  * }
969
967
  * }
970
968
  * };
971
- *
969
+ *
972
970
  */
973
971
 
974
972
  module.exports = function(suite){
@@ -1006,6 +1004,7 @@ module.exports = function(suite){
1006
1004
  }
1007
1005
  }
1008
1006
  };
1007
+
1009
1008
  }); // module: interfaces/exports.js
1010
1009
 
1011
1010
  require.register("interfaces/index.js", function(module, exports, require){
@@ -1028,33 +1027,33 @@ var Suite = require('../suite')
1028
1027
 
1029
1028
  /**
1030
1029
  * QUnit-style interface:
1031
- *
1030
+ *
1032
1031
  * suite('Array');
1033
- *
1032
+ *
1034
1033
  * test('#length', function(){
1035
1034
  * var arr = [1,2,3];
1036
1035
  * ok(arr.length == 3);
1037
1036
  * });
1038
- *
1037
+ *
1039
1038
  * test('#indexOf()', function(){
1040
1039
  * var arr = [1,2,3];
1041
1040
  * ok(arr.indexOf(1) == 0);
1042
1041
  * ok(arr.indexOf(2) == 1);
1043
1042
  * ok(arr.indexOf(3) == 2);
1044
1043
  * });
1045
- *
1044
+ *
1046
1045
  * suite('String');
1047
- *
1046
+ *
1048
1047
  * test('#length', function(){
1049
1048
  * ok('foo'.length == 3);
1050
1049
  * });
1051
- *
1050
+ *
1052
1051
  */
1053
1052
 
1054
1053
  module.exports = function(suite){
1055
1054
  var suites = [suite];
1056
1055
 
1057
- suite.on('pre-require', function(context){
1056
+ suite.on('pre-require', function(context, file, mocha){
1058
1057
 
1059
1058
  /**
1060
1059
  * Execute before running tests.
@@ -1091,11 +1090,21 @@ module.exports = function(suite){
1091
1090
  /**
1092
1091
  * Describe a "suite" with the given `title`.
1093
1092
  */
1094
-
1093
+
1095
1094
  context.suite = function(title){
1096
1095
  if (suites.length > 1) suites.shift();
1097
1096
  var suite = Suite.create(suites[0], title);
1098
1097
  suites.unshift(suite);
1098
+ return suite;
1099
+ };
1100
+
1101
+ /**
1102
+ * Exclusive test-case.
1103
+ */
1104
+
1105
+ context.suite.only = function(title, fn){
1106
+ var suite = context.suite(title, fn);
1107
+ mocha.grep(suite.fullTitle());
1099
1108
  };
1100
1109
 
1101
1110
  /**
@@ -1105,7 +1114,26 @@ module.exports = function(suite){
1105
1114
  */
1106
1115
 
1107
1116
  context.test = function(title, fn){
1108
- suites[0].addTest(new Test(title, fn));
1117
+ var test = new Test(title, fn);
1118
+ suites[0].addTest(test);
1119
+ return test;
1120
+ };
1121
+
1122
+ /**
1123
+ * Exclusive test-case.
1124
+ */
1125
+
1126
+ context.test.only = function(title, fn){
1127
+ var test = context.test(title, fn);
1128
+ mocha.grep(test.fullTitle());
1129
+ };
1130
+
1131
+ /**
1132
+ * Pending test case.
1133
+ */
1134
+
1135
+ context.test.skip = function(title){
1136
+ context.test(title);
1109
1137
  };
1110
1138
  });
1111
1139
  };
@@ -1129,7 +1157,7 @@ var Suite = require('../suite')
1129
1157
  * suiteSetup(function(){
1130
1158
  *
1131
1159
  * });
1132
- *
1160
+ *
1133
1161
  * test('should return -1 when not present', function(){
1134
1162
  *
1135
1163
  * });
@@ -1549,7 +1577,7 @@ Mocha.prototype.run = function(fn){
1549
1577
  var options = this.options;
1550
1578
  var runner = new exports.Runner(suite);
1551
1579
  var reporter = new this._reporter(runner);
1552
- runner.ignoreLeaks = options.ignoreLeaks;
1580
+ runner.ignoreLeaks = false !== options.ignoreLeaks;
1553
1581
  runner.asyncOnly = options.asyncOnly;
1554
1582
  if (options.grep) runner.grep(options.grep, options.invert);
1555
1583
  if (options.globals) runner.globals(options.globals);
@@ -1710,7 +1738,7 @@ exports.colors = {
1710
1738
  /**
1711
1739
  * Default symbol map.
1712
1740
  */
1713
-
1741
+
1714
1742
  exports.symbols = {
1715
1743
  ok: '✓',
1716
1744
  err: '✖',
@@ -1816,10 +1844,7 @@ exports.list = function(failures){
1816
1844
 
1817
1845
  // actual / expected diff
1818
1846
  if ('string' == typeof actual && 'string' == typeof expected) {
1819
- var len = Math.max(actual.length, expected.length);
1820
-
1821
- if (len < 20) msg = errorDiff(err, 'Chars', escape);
1822
- else msg = errorDiff(err, 'Words', escape);
1847
+ msg = errorDiff(err, 'Words', escape);
1823
1848
 
1824
1849
  // linenos
1825
1850
  var lines = msg.split('\n');
@@ -2334,8 +2359,6 @@ function HTML(runner, root) {
2334
2359
  });
2335
2360
 
2336
2361
  runner.on('test end', function(test){
2337
- window.scrollTo(0, document.body.scrollHeight);
2338
-
2339
2362
  // TODO: add to stats
2340
2363
  var percent = stats.tests / this.total * 100 | 0;
2341
2364
  if (progress) progress.update(percent).draw(ctx);
@@ -3080,7 +3103,7 @@ exports = module.exports = Min;
3080
3103
 
3081
3104
  function Min(runner) {
3082
3105
  Base.call(this, runner);
3083
-
3106
+
3084
3107
  runner.on('start', function(){
3085
3108
  // clear screen
3086
3109
  process.stdout.write('\u001b[2J');
@@ -3100,10 +3123,10 @@ F.prototype = Base.prototype;
3100
3123
  Min.prototype = new F;
3101
3124
  Min.prototype.constructor = Min;
3102
3125
 
3126
+
3103
3127
  }); // module: reporters/min.js
3104
3128
 
3105
3129
  require.register("reporters/nyan.js", function(module, exports, require){
3106
-
3107
3130
  /**
3108
3131
  * Module dependencies.
3109
3132
  */
@@ -3249,44 +3272,39 @@ NyanCat.prototype.drawRainbow = function(){
3249
3272
  NyanCat.prototype.drawNyanCat = function(status) {
3250
3273
  var self = this;
3251
3274
  var startWidth = this.scoreboardWidth + this.trajectories[0].length;
3252
-
3253
- [0, 1, 2, 3].forEach(function(index) {
3254
- write('\u001b[' + startWidth + 'C');
3255
-
3256
- switch (index) {
3257
- case 0:
3258
- write('_,------,');
3259
- write('\n');
3260
- break;
3261
- case 1:
3262
- var padding = self.tick ? ' ' : ' ';
3263
- write('_|' + padding + '/\\_/\\ ');
3264
- write('\n');
3265
- break;
3266
- case 2:
3267
- var padding = self.tick ? '_' : '__';
3268
- var tail = self.tick ? '~' : '^';
3269
- var face;
3270
- switch (status) {
3271
- case 'pass':
3272
- face = '( ^ .^)';
3273
- break;
3274
- case 'fail':
3275
- face = '( o .o)';
3276
- break;
3277
- default:
3278
- face = '( - .-)';
3279
- }
3280
- write(tail + '|' + padding + face + ' ');
3281
- write('\n');
3282
- break;
3283
- case 3:
3284
- var padding = self.tick ? ' ' : ' ';
3285
- write(padding + '"" "" ');
3286
- write('\n');
3287
- break;
3288
- }
3289
- });
3275
+ var color = '\u001b[' + startWidth + 'C';
3276
+ var padding = '';
3277
+
3278
+ write(color);
3279
+ write('_,------,');
3280
+ write('\n');
3281
+
3282
+ write(color);
3283
+ padding = self.tick ? ' ' : ' ';
3284
+ write('_|' + padding + '/\\_/\\ ');
3285
+ write('\n');
3286
+
3287
+ write(color);
3288
+ padding = self.tick ? '_' : '__';
3289
+ var tail = self.tick ? '~' : '^';
3290
+ var face;
3291
+ switch (status) {
3292
+ case 'pass':
3293
+ face = '( ^ .^)';
3294
+ break;
3295
+ case 'fail':
3296
+ face = '( o .o)';
3297
+ break;
3298
+ default:
3299
+ face = '( - .-)';
3300
+ }
3301
+ write(tail + '|' + padding + face + ' ');
3302
+ write('\n');
3303
+
3304
+ write(color);
3305
+ padding = self.tick ? ' ' : ' ';
3306
+ write(padding + '"" "" ');
3307
+ write('\n');
3290
3308
 
3291
3309
  this.cursorUp(this.numberOfLines);
3292
3310
  };
@@ -3746,7 +3764,7 @@ function XUnit(runner) {
3746
3764
  runner.on('pass', function(test){
3747
3765
  tests.push(test);
3748
3766
  });
3749
-
3767
+
3750
3768
  runner.on('fail', function(test){
3751
3769
  tests.push(test);
3752
3770
  });
@@ -3763,7 +3781,7 @@ function XUnit(runner) {
3763
3781
  }, false));
3764
3782
 
3765
3783
  tests.forEach(test);
3766
- console.log('</testsuite>');
3784
+ console.log('</testsuite>');
3767
3785
  });
3768
3786
  }
3769
3787
 
@@ -4065,8 +4083,7 @@ var EventEmitter = require('browser/events').EventEmitter
4065
4083
  , Test = require('./test')
4066
4084
  , utils = require('./utils')
4067
4085
  , filter = utils.filter
4068
- , keys = utils.keys
4069
- , noop = function(){};
4086
+ , keys = utils.keys;
4070
4087
 
4071
4088
  /**
4072
4089
  * Non-enumerable globals.
@@ -4118,6 +4135,15 @@ function Runner(suite) {
4118
4135
  this.globals(this.globalProps().concat(['errno']));
4119
4136
  }
4120
4137
 
4138
+ /**
4139
+ * Wrapper for setImmediate, process.nextTick, or browser polyfill.
4140
+ *
4141
+ * @param {Function} fn
4142
+ * @api private
4143
+ */
4144
+
4145
+ Runner.immediately = global.setImmediate || process.nextTick;
4146
+
4121
4147
  /**
4122
4148
  * Inherit from `EventEmitter.prototype`.
4123
4149
  */
@@ -4246,7 +4272,7 @@ Runner.prototype.fail = function(test, err){
4246
4272
  if ('string' == typeof err) {
4247
4273
  err = new Error('the string "' + err + '" was thrown, throw an Error :)');
4248
4274
  }
4249
-
4275
+
4250
4276
  this.emit('fail', test, err);
4251
4277
  };
4252
4278
 
@@ -4303,7 +4329,7 @@ Runner.prototype.hook = function(name, fn){
4303
4329
  });
4304
4330
  }
4305
4331
 
4306
- process.nextTick(function(){
4332
+ Runner.immediately(function(){
4307
4333
  next(0);
4308
4334
  });
4309
4335
  };
@@ -4546,14 +4572,16 @@ Runner.prototype.run = function(fn){
4546
4572
  var self = this
4547
4573
  , fn = fn || function(){};
4548
4574
 
4575
+ function uncaught(err){
4576
+ self.uncaught(err);
4577
+ }
4578
+
4549
4579
  debug('start');
4550
4580
 
4551
4581
  // callback
4552
4582
  this.on('end', function(){
4553
4583
  debug('end');
4554
- process.removeListener('uncaughtException', function(err){
4555
- self.uncaught(err);
4556
- });
4584
+ process.removeListener('uncaughtException', uncaught);
4557
4585
  fn(self.failures);
4558
4586
  });
4559
4587
 
@@ -4565,9 +4593,7 @@ Runner.prototype.run = function(fn){
4565
4593
  });
4566
4594
 
4567
4595
  // uncaught exception
4568
- process.on('uncaughtException', function(err){
4569
- self.uncaught(err);
4570
- });
4596
+ process.on('uncaughtException', uncaught);
4571
4597
 
4572
4598
  return this;
4573
4599
  };
@@ -4583,6 +4609,8 @@ Runner.prototype.run = function(fn){
4583
4609
 
4584
4610
  function filterLeaks(ok, globals) {
4585
4611
  return filter(globals, function(key){
4612
+ // Firefox and Chrome exposes iframes as index inside the window object
4613
+ if (/^d+/.test(key)) return false;
4586
4614
  var matched = filter(ok, function(ok){
4587
4615
  if (~ok.indexOf('*')) return 0 == key.indexOf(ok.split('*')[0]);
4588
4616
  // Opera and IE expose global variables for HTML element IDs (issue #243)
@@ -5005,7 +5033,7 @@ exports.indexOf = function(arr, obj, start){
5005
5033
 
5006
5034
  /**
5007
5035
  * Array#reduce (<=IE8)
5008
- *
5036
+ *
5009
5037
  * @param {Array} array
5010
5038
  * @param {Function} fn
5011
5039
  * @param {Object} initial value
@@ -5224,6 +5252,17 @@ exports.highlightTags = function(name) {
5224
5252
  };
5225
5253
 
5226
5254
  }); // module: utils.js
5255
+
5256
+ /**
5257
+ * Save timer references to avoid Sinon interfering (see GH-237).
5258
+ */
5259
+
5260
+ var Date = window.Date;
5261
+ var setTimeout = window.setTimeout;
5262
+ var setInterval = window.setInterval;
5263
+ var clearTimeout = window.clearTimeout;
5264
+ var clearInterval = window.clearInterval;
5265
+
5227
5266
  /**
5228
5267
  * Node shims.
5229
5268
  *
@@ -5233,39 +5272,11 @@ exports.highlightTags = function(name) {
5233
5272
  * the browser.
5234
5273
  */
5235
5274
 
5236
- process = {};
5275
+ var process = {};
5237
5276
  process.exit = function(status){};
5238
5277
  process.stdout = {};
5239
5278
  global = window;
5240
5279
 
5241
- /**
5242
- * next tick implementation.
5243
- */
5244
-
5245
- process.nextTick = (function(){
5246
- // postMessage behaves badly on IE8
5247
- if (window.ActiveXObject || !window.postMessage) {
5248
- return function(fn){ fn() };
5249
- }
5250
-
5251
- // based on setZeroTimeout by David Baron
5252
- // - http://dbaron.org/log/20100309-faster-timeouts
5253
- var timeouts = []
5254
- , name = 'mocha-zero-timeout'
5255
-
5256
- window.addEventListener('message', function(e){
5257
- if (e.source == window && e.data == name) {
5258
- if (e.stopPropagation) e.stopPropagation();
5259
- if (timeouts.length) timeouts.shift()();
5260
- }
5261
- }, true);
5262
-
5263
- return function(fn){
5264
- timeouts.push(fn);
5265
- window.postMessage(name, '*');
5266
- }
5267
- })();
5268
-
5269
5280
  /**
5270
5281
  * Remove uncaughtException listener.
5271
5282
  */
@@ -5288,53 +5299,75 @@ process.on = function(e, fn){
5288
5299
  }
5289
5300
  };
5290
5301
 
5291
- // boot
5292
- ;(function(){
5302
+ /**
5303
+ * Expose mocha.
5304
+ */
5293
5305
 
5294
- /**
5295
- * Expose mocha.
5296
- */
5306
+ var Mocha = window.Mocha = require('mocha'),
5307
+ mocha = window.mocha = new Mocha({ reporter: 'html' });
5297
5308
 
5298
- var Mocha = window.Mocha = require('mocha'),
5299
- mocha = window.mocha = new Mocha({ reporter: 'html' });
5309
+ var immediateQueue = []
5310
+ , immediateTimeout;
5300
5311
 
5301
- /**
5302
- * Override ui to ensure that the ui functions are initialized.
5303
- * Normally this would happen in Mocha.prototype.loadFiles.
5304
- */
5312
+ function timeslice() {
5313
+ var immediateStart = new Date().getTime();
5314
+ while (immediateQueue.length && (new Date().getTime() - immediateStart) < 100) {
5315
+ immediateQueue.shift()();
5316
+ }
5317
+ if (immediateQueue.length) {
5318
+ immediateTimeout = setTimeout(timeslice, 0);
5319
+ } else {
5320
+ immediateTimeout = null;
5321
+ }
5322
+ }
5305
5323
 
5306
- mocha.ui = function(ui){
5307
- Mocha.prototype.ui.call(this, ui);
5308
- this.suite.emit('pre-require', window, null, this);
5309
- return this;
5310
- };
5324
+ /**
5325
+ * High-performance override of Runner.immediately.
5326
+ */
5311
5327
 
5312
- /**
5313
- * Setup mocha with the given setting options.
5314
- */
5328
+ Mocha.Runner.immediately = function(callback) {
5329
+ immediateQueue.push(callback);
5330
+ if (!immediateTimeout) {
5331
+ immediateTimeout = setTimeout(timeslice, 0);
5332
+ }
5333
+ };
5315
5334
 
5316
- mocha.setup = function(opts){
5317
- if ('string' == typeof opts) opts = { ui: opts };
5318
- for (var opt in opts) this[opt](opts[opt]);
5319
- return this;
5320
- };
5335
+ /**
5336
+ * Override ui to ensure that the ui functions are initialized.
5337
+ * Normally this would happen in Mocha.prototype.loadFiles.
5338
+ */
5321
5339
 
5322
- /**
5323
- * Run mocha, returning the Runner.
5324
- */
5340
+ mocha.ui = function(ui){
5341
+ Mocha.prototype.ui.call(this, ui);
5342
+ this.suite.emit('pre-require', window, null, this);
5343
+ return this;
5344
+ };
5325
5345
 
5326
- mocha.run = function(fn){
5327
- var options = mocha.options;
5328
- mocha.globals('location');
5346
+ /**
5347
+ * Setup mocha with the given setting options.
5348
+ */
5329
5349
 
5330
- var query = Mocha.utils.parseQuery(window.location.search || '');
5331
- if (query.grep) mocha.grep(query.grep);
5332
- if (query.invert) mocha.invert();
5350
+ mocha.setup = function(opts){
5351
+ if ('string' == typeof opts) opts = { ui: opts };
5352
+ for (var opt in opts) this[opt](opts[opt]);
5353
+ return this;
5354
+ };
5333
5355
 
5334
- return Mocha.prototype.run.call(mocha, function(){
5335
- Mocha.utils.highlightTags('code');
5336
- if (fn) fn();
5337
- });
5338
- };
5339
- })();
5356
+ /**
5357
+ * Run mocha, returning the Runner.
5358
+ */
5359
+
5360
+ mocha.run = function(fn){
5361
+ var options = mocha.options;
5362
+ mocha.globals('location');
5363
+
5364
+ var query = Mocha.utils.parseQuery(window.location.search || '');
5365
+ if (query.grep) mocha.grep(query.grep);
5366
+ if (query.invert) mocha.invert();
5367
+
5368
+ return Mocha.prototype.run.call(mocha, function(){
5369
+ Mocha.utils.highlightTags('code');
5370
+ if (fn) fn();
5371
+ });
5372
+ };
5340
5373
  })();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mocha",
3
- "version": "1.8.1",
3
+ "version": "1.11.0",
4
4
  "description": "simple, flexible, fun test framework",
5
5
  "keywords": [
6
6
  "mocha",
@@ -31,8 +31,9 @@
31
31
  "jade": "0.26.3",
32
32
  "diff": "1.0.2",
33
33
  "debug": "*",
34
- "mkdirp": "0.3.3",
35
- "ms": "0.3.0"
34
+ "mkdirp": "0.3.5",
35
+ "ms": "0.3.0",
36
+ "glob": "3.2.1"
36
37
  },
37
38
  "devDependencies": {
38
39
  "should": "*",
package/test.js CHANGED
@@ -1,14 +1,13 @@
1
1
 
2
- describe('somethinf', function(){
3
- it('should fail', function(){
4
- test()
5
- })
6
-
7
- it('should pass', function(){
2
+ describe('something', function(){
3
+ it('should work', function(){
8
4
 
9
5
  })
10
6
 
11
- it('should pass again', function(){
7
+ // it('be pending')
8
+ // it('be pending')
12
9
 
10
+ it('should fail', function(){
11
+ // tasdf
13
12
  })
14
13
  })