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/bin/_mocha CHANGED
@@ -5,8 +5,10 @@
5
5
  */
6
6
 
7
7
  var program = require('commander')
8
+ , sprintf = require('util').format
8
9
  , path = require('path')
9
10
  , fs = require('fs')
11
+ , glob = require('glob')
10
12
  , resolve = path.resolve
11
13
  , exists = fs.existsSync || path.existsSync
12
14
  , Mocha = require('../')
@@ -72,7 +74,7 @@ program
72
74
  .option('--recursive', 'include sub directories')
73
75
  .option('--debug-brk', "enable node's debugger breaking on the first line")
74
76
  .option('--globals <names>', 'allow the given comma-delimited global [names]', list, [])
75
- .option('--ignore-leaks', 'ignore global variable leaks')
77
+ .option('--check-leaks', 'check for global variable leaks')
76
78
  .option('--interfaces', 'display available interfaces')
77
79
  .option('--reporters', 'display available reporters')
78
80
  .option('--compilers <ext>:<module>,...', 'use the given module(s) to compile files', list, [])
@@ -92,7 +94,8 @@ program
92
94
  var tmpl = fs.readFileSync(join(__dirname, '..', 'lib/template.html'));
93
95
  fs.writeFileSync(join(path, 'mocha.css'), css);
94
96
  fs.writeFileSync(join(path, 'mocha.js'), js);
95
- fs.writeFileSync(join(path, 'tests.html'), tmpl);
97
+ fs.writeFileSync(join(path, 'tests.js'), '');
98
+ fs.writeFileSync(join(path, 'index.html'), tmpl);
96
99
  process.exit(0);
97
100
  });
98
101
 
@@ -114,7 +117,7 @@ program.on('reporters', function(){
114
117
  console.log(' list - spec-style listing');
115
118
  console.log(' tap - test-anything-protocol');
116
119
  console.log(' landing - unicode landing strip');
117
- console.log(' xunit - xunit reportert');
120
+ console.log(' xunit - xunit reporter');
118
121
  console.log(' teamcity - teamcity ci support');
119
122
  console.log(' html-cov - HTML test coverage');
120
123
  console.log(' json-cov - JSON test coverage');
@@ -143,10 +146,8 @@ program.on('interfaces', function(){
143
146
  module.paths.push(cwd, join(cwd, 'node_modules'));
144
147
 
145
148
  program.on('require', function(mod){
146
- var abs = exists(mod)
147
- || exists(mod + '.js');
148
-
149
- if (abs) mod = join(cwd, mod);
149
+ var abs = exists(mod) || exists(mod + '.js');
150
+ if (abs) mod = resolve(mod);
150
151
  require(mod);
151
152
  });
152
153
 
@@ -223,9 +224,9 @@ if (program.grep) mocha.grep(new RegExp(program.grep));
223
224
 
224
225
  if (program.invert) mocha.invert();
225
226
 
226
- // --ignore-leaks
227
+ // --check-leaks
227
228
 
228
- if (program.ignoreLeaks) mocha.ignoreLeaks();
229
+ if (program.checkLeaks) mocha.checkLeaks();
229
230
 
230
231
  // --growl
231
232
 
@@ -284,14 +285,13 @@ if (program.watch) {
284
285
  process.exit();
285
286
  });
286
287
 
287
- var frames = [
288
- ' \u001b[96m◜ \u001b[90mwatching\u001b[0m'
289
- , ' \u001b[96m \u001b[90mwatching\u001b[0m'
290
- , ' \u001b[96m◝ \u001b[90mwatching\u001b[0m'
291
- , ' \u001b[96m◞ \u001b[90mwatching\u001b[0m'
292
- , ' \u001b[96m \u001b[90mwatching\u001b[0m'
293
- , ' \u001b[96m◟ \u001b[90mwatching\u001b[0m'
294
- ];
288
+ var spinner = 'win32' == process.platform
289
+ ? ['|','/','-','\\']
290
+ : ['◜','◠','◝','◞','◡','◟'];
291
+
292
+ var frames = spinner.map(function(c) {
293
+ return sprintf(' \u001b[96m%s \u001b[90mwatching\u001b[0m', c);
294
+ });
295
295
 
296
296
  var watchFiles = utils.files(cwd);
297
297
 
@@ -386,7 +386,14 @@ function stop() {
386
386
  function lookupFiles(path, recursive) {
387
387
  var files = [];
388
388
 
389
- if (!exists(path)) path += '.js';
389
+ if (!exists(path)) {
390
+ if (exists(path + '.js')) {
391
+ path += '.js'
392
+ } else {
393
+ return glob.sync(path);
394
+ }
395
+ }
396
+
390
397
  var stat = fs.statSync(path);
391
398
  if (stat.isFile()) return path;
392
399
 
@@ -415,6 +422,6 @@ function play(arr, interval) {
415
422
 
416
423
  play.timer = setInterval(function(){
417
424
  var str = arr[i++ % len];
418
- process.stdout.write('\r' + str);
425
+ process.stdout.write('\u001b[0G' + str);
419
426
  }, interval);
420
427
  }
package/bin/mocha CHANGED
@@ -8,8 +8,10 @@
8
8
  var spawn = require('child_process').spawn
9
9
  , args = [ __dirname + '/_mocha' ];
10
10
 
11
- process.argv.slice(2).forEach(function (arg) {
12
- switch (arg) {
11
+ process.argv.slice(2).forEach(function(arg){
12
+ var flag = arg.split('=')[0];
13
+
14
+ switch (flag) {
13
15
  case '-d':
14
16
  args.unshift('--debug');
15
17
  break;
@@ -26,6 +28,8 @@ process.argv.slice(2).forEach(function (arg) {
26
28
  case '--harmony':
27
29
  case '--harmony-proxies':
28
30
  case '--harmony-collections':
31
+ case '--harmony-generators':
32
+ case '--prof':
29
33
  args.unshift(arg);
30
34
  break;
31
35
  default:
package/component.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mocha",
3
- "version": "1.8.1",
3
+ "version": "1.11.0",
4
4
  "repo": "visionmedia/mocha",
5
5
  "description": "simple, flexible, fun test framework",
6
6
  "keywords": [
@@ -1,6 +1,5 @@
1
1
 
2
2
  module.exports = function(type){
3
3
  return function(){
4
-
5
4
  }
6
- };
5
+ };
@@ -4,5 +4,10 @@ exports.isatty = function(){
4
4
  };
5
5
 
6
6
  exports.getWindowSize = function(){
7
- return [window.innerHeight, window.innerWidth];
8
- };
7
+ if ('innerHeight' in global) {
8
+ return [global.innerHeight, global.innerWidth];
9
+ } else {
10
+ // In a Web Worker, the DOM Window is not available.
11
+ return [640, 480];
12
+ }
13
+ };
package/lib/hook.js CHANGED
@@ -47,4 +47,3 @@ Hook.prototype.error = function(err){
47
47
 
48
48
  this._error = err;
49
49
  };
50
-
@@ -8,7 +8,7 @@ var Suite = require('../suite')
8
8
 
9
9
  /**
10
10
  * BDD-style interface:
11
- *
11
+ *
12
12
  * describe('Array', function(){
13
13
  * describe('#indexOf()', function(){
14
14
  * it('should return -1 when not present', function(){
@@ -20,7 +20,7 @@ var Suite = require('../suite')
20
20
  * });
21
21
  * });
22
22
  * });
23
- *
23
+ *
24
24
  */
25
25
 
26
26
  module.exports = function(suite){
@@ -65,7 +65,7 @@ module.exports = function(suite){
65
65
  * and callback `fn` containing nested suites
66
66
  * and/or tests.
67
67
  */
68
-
68
+
69
69
  context.describe = context.context = function(title, fn){
70
70
  var suite = Suite.create(suites[0], title);
71
71
  suites.unshift(suite);
@@ -8,19 +8,19 @@ var Suite = require('../suite')
8
8
 
9
9
  /**
10
10
  * TDD-style interface:
11
- *
11
+ *
12
12
  * exports.Array = {
13
13
  * '#indexOf()': {
14
14
  * 'should return -1 when the value is not present': function(){
15
- *
15
+ *
16
16
  * },
17
17
  *
18
18
  * 'should return the correct index when the value is present': function(){
19
- *
19
+ *
20
20
  * }
21
21
  * }
22
22
  * };
23
- *
23
+ *
24
24
  */
25
25
 
26
26
  module.exports = function(suite){
@@ -57,4 +57,4 @@ module.exports = function(suite){
57
57
  }
58
58
  }
59
59
  }
60
- };
60
+ };
@@ -8,33 +8,33 @@ var Suite = require('../suite')
8
8
 
9
9
  /**
10
10
  * QUnit-style interface:
11
- *
11
+ *
12
12
  * suite('Array');
13
- *
13
+ *
14
14
  * test('#length', function(){
15
15
  * var arr = [1,2,3];
16
16
  * ok(arr.length == 3);
17
17
  * });
18
- *
18
+ *
19
19
  * test('#indexOf()', function(){
20
20
  * var arr = [1,2,3];
21
21
  * ok(arr.indexOf(1) == 0);
22
22
  * ok(arr.indexOf(2) == 1);
23
23
  * ok(arr.indexOf(3) == 2);
24
24
  * });
25
- *
25
+ *
26
26
  * suite('String');
27
- *
27
+ *
28
28
  * test('#length', function(){
29
29
  * ok('foo'.length == 3);
30
30
  * });
31
- *
31
+ *
32
32
  */
33
33
 
34
34
  module.exports = function(suite){
35
35
  var suites = [suite];
36
36
 
37
- suite.on('pre-require', function(context){
37
+ suite.on('pre-require', function(context, file, mocha){
38
38
 
39
39
  /**
40
40
  * Execute before running tests.
@@ -71,11 +71,21 @@ module.exports = function(suite){
71
71
  /**
72
72
  * Describe a "suite" with the given `title`.
73
73
  */
74
-
74
+
75
75
  context.suite = function(title){
76
76
  if (suites.length > 1) suites.shift();
77
77
  var suite = Suite.create(suites[0], title);
78
78
  suites.unshift(suite);
79
+ return suite;
80
+ };
81
+
82
+ /**
83
+ * Exclusive test-case.
84
+ */
85
+
86
+ context.suite.only = function(title, fn){
87
+ var suite = context.suite(title, fn);
88
+ mocha.grep(suite.fullTitle());
79
89
  };
80
90
 
81
91
  /**
@@ -85,7 +95,26 @@ module.exports = function(suite){
85
95
  */
86
96
 
87
97
  context.test = function(title, fn){
88
- suites[0].addTest(new Test(title, fn));
98
+ var test = new Test(title, fn);
99
+ suites[0].addTest(test);
100
+ return test;
101
+ };
102
+
103
+ /**
104
+ * Exclusive test-case.
105
+ */
106
+
107
+ context.test.only = function(title, fn){
108
+ var test = context.test(title, fn);
109
+ mocha.grep(test.fullTitle());
110
+ };
111
+
112
+ /**
113
+ * Pending test case.
114
+ */
115
+
116
+ context.test.skip = function(title){
117
+ context.test(title);
89
118
  };
90
119
  });
91
120
  };
@@ -14,7 +14,7 @@ var Suite = require('../suite')
14
14
  * suiteSetup(function(){
15
15
  *
16
16
  * });
17
- *
17
+ *
18
18
  * test('should return -1 when not present', function(){
19
19
  *
20
20
  * });
@@ -82,6 +82,17 @@ module.exports = function(suite){
82
82
  return suite;
83
83
  };
84
84
 
85
+ /**
86
+ * Pending suite.
87
+ */
88
+ context.suite.skip = function(title, fn) {
89
+ var suite = Suite.create(suites[0], title);
90
+ suite.pending = true;
91
+ suites.unshift(suite);
92
+ fn.call(suite);
93
+ suites.shift();
94
+ };
95
+
85
96
  /**
86
97
  * Exclusive test-case.
87
98
  */
@@ -98,8 +109,10 @@ module.exports = function(suite){
98
109
  */
99
110
 
100
111
  context.test = function(title, fn){
112
+ var suite = suites[0];
113
+ if (suite.pending) var fn = null;
101
114
  var test = new Test(title, fn);
102
- suites[0].addTest(test);
115
+ suite.addTest(test);
103
116
  return test;
104
117
  };
105
118
 
package/lib/mocha.js CHANGED
@@ -307,7 +307,7 @@ Mocha.prototype.run = function(fn){
307
307
  var options = this.options;
308
308
  var runner = new exports.Runner(suite);
309
309
  var reporter = new this._reporter(runner);
310
- runner.ignoreLeaks = options.ignoreLeaks;
310
+ runner.ignoreLeaks = false !== options.ignoreLeaks;
311
311
  runner.asyncOnly = options.asyncOnly;
312
312
  if (options.grep) runner.grep(options.grep, options.invert);
313
313
  if (options.globals) runner.globals(options.globals);
@@ -64,7 +64,7 @@ exports.colors = {
64
64
  /**
65
65
  * Default symbol map.
66
66
  */
67
-
67
+
68
68
  exports.symbols = {
69
69
  ok: '✓',
70
70
  err: '✖',
@@ -161,6 +161,11 @@ exports.list = function(failures){
161
161
  , expected = err.expected
162
162
  , escape = true;
163
163
 
164
+ // uncaught
165
+ if (err.uncaught) {
166
+ msg = 'Uncaught ' + msg;
167
+ }
168
+
164
169
  // explicitly show diff
165
170
  if (err.showDiff) {
166
171
  escape = false;
@@ -170,10 +175,7 @@ exports.list = function(failures){
170
175
 
171
176
  // actual / expected diff
172
177
  if ('string' == typeof actual && 'string' == typeof expected) {
173
- var len = Math.max(actual.length, expected.length);
174
-
175
- if (len < 20) msg = errorDiff(err, 'Chars', escape);
176
- else msg = errorDiff(err, 'Words', escape);
178
+ msg = errorDiff(err, 'Words', escape);
177
179
 
178
180
  // linenos
179
181
  var lines = msg.split('\n');
@@ -282,48 +284,38 @@ function Base(runner) {
282
284
  */
283
285
 
284
286
  Base.prototype.epilogue = function(){
285
- var stats = this.stats
286
- , fmt
287
- , tests;
287
+ var stats = this.stats;
288
+ var tests;
289
+ var fmt;
288
290
 
289
291
  console.log();
290
292
 
291
- function pluralize(n) {
292
- return 1 == n ? 'test' : 'tests';
293
- }
294
-
295
- // failure
296
- if (stats.failures) {
297
- fmt = color('bright fail', ' ' + exports.symbols.err)
298
- + color('fail', ' %d of %d %s failed')
299
- + color('light', ':')
300
-
301
- console.error(fmt,
302
- stats.failures,
303
- this.runner.total,
304
- pluralize(this.runner.total));
305
-
306
- Base.list(this.failures);
307
- console.error();
308
- return;
309
- }
310
-
311
- // pass
293
+ // passes
312
294
  fmt = color('bright pass', ' ')
313
- + color('green', ' %d %s complete')
295
+ + color('green', ' %d passing')
314
296
  + color('light', ' (%s)');
315
297
 
316
298
  console.log(fmt,
317
- stats.tests || 0,
318
- pluralize(stats.tests),
299
+ stats.passes || 0,
319
300
  ms(stats.duration));
320
301
 
321
302
  // pending
322
303
  if (stats.pending) {
323
304
  fmt = color('pending', ' ')
324
- + color('pending', ' %d %s pending');
305
+ + color('pending', ' %d pending');
325
306
 
326
- console.log(fmt, stats.pending, pluralize(stats.pending));
307
+ console.log(fmt, stats.pending);
308
+ }
309
+
310
+ // failures
311
+ if (stats.failures) {
312
+ fmt = color('fail', ' %d failing');
313
+
314
+ console.error(fmt,
315
+ stats.failures);
316
+
317
+ Base.list(this.failures);
318
+ console.error();
327
319
  }
328
320
 
329
321
  console.log();
@@ -120,8 +120,6 @@ function HTML(runner, root) {
120
120
  });
121
121
 
122
122
  runner.on('test end', function(test){
123
- window.scrollTo(0, document.body.scrollHeight);
124
-
125
123
  // TODO: add to stats
126
124
  var percent = stats.tests / this.total * 100 | 0;
127
125
  if (progress) progress.update(percent).draw(ctx);
@@ -20,7 +20,7 @@ exports = module.exports = Min;
20
20
 
21
21
  function Min(runner) {
22
22
  Base.call(this, runner);
23
-
23
+
24
24
  runner.on('start', function(){
25
25
  // clear screen
26
26
  process.stdout.write('\u001b[2J');
@@ -35,4 +35,4 @@ function Min(runner) {
35
35
  * Inherit from `Base.prototype`.
36
36
  */
37
37
 
38
- Min.prototype.__proto__ = Base.prototype;
38
+ Min.prototype.__proto__ = Base.prototype;
@@ -1,4 +1,3 @@
1
-
2
1
  /**
3
2
  * Module dependencies.
4
3
  */
@@ -144,44 +143,39 @@ NyanCat.prototype.drawRainbow = function(){
144
143
  NyanCat.prototype.drawNyanCat = function(status) {
145
144
  var self = this;
146
145
  var startWidth = this.scoreboardWidth + this.trajectories[0].length;
147
-
148
- [0, 1, 2, 3].forEach(function(index) {
149
- write('\u001b[' + startWidth + 'C');
150
-
151
- switch (index) {
152
- case 0:
153
- write('_,------,');
154
- write('\n');
155
- break;
156
- case 1:
157
- var padding = self.tick ? ' ' : ' ';
158
- write('_|' + padding + '/\\_/\\ ');
159
- write('\n');
160
- break;
161
- case 2:
162
- var padding = self.tick ? '_' : '__';
163
- var tail = self.tick ? '~' : '^';
164
- var face;
165
- switch (status) {
166
- case 'pass':
167
- face = '( ^ .^)';
168
- break;
169
- case 'fail':
170
- face = '( o .o)';
171
- break;
172
- default:
173
- face = '( - .-)';
174
- }
175
- write(tail + '|' + padding + face + ' ');
176
- write('\n');
177
- break;
178
- case 3:
179
- var padding = self.tick ? ' ' : ' ';
180
- write(padding + '"" "" ');
181
- write('\n');
182
- break;
183
- }
184
- });
146
+ var color = '\u001b[' + startWidth + 'C';
147
+ var padding = '';
148
+
149
+ write(color);
150
+ write('_,------,');
151
+ write('\n');
152
+
153
+ write(color);
154
+ padding = self.tick ? ' ' : ' ';
155
+ write('_|' + padding + '/\\_/\\ ');
156
+ write('\n');
157
+
158
+ write(color);
159
+ padding = self.tick ? '_' : '__';
160
+ var tail = self.tick ? '~' : '^';
161
+ var face;
162
+ switch (status) {
163
+ case 'pass':
164
+ face = '( ^ .^)';
165
+ break;
166
+ case 'fail':
167
+ face = '( o .o)';
168
+ break;
169
+ default:
170
+ face = '( - .-)';
171
+ }
172
+ write(tail + '|' + padding + face + ' ');
173
+ write('\n');
174
+
175
+ write(color);
176
+ padding = self.tick ? ' ' : ' ';
177
+ write(padding + '"" "" ');
178
+ write('\n');
185
179
 
186
180
  this.cursorUp(this.numberOfLines);
187
181
  };
@@ -34,12 +34,12 @@ html
34
34
  tbody
35
35
  for line, number in file.source
36
36
  if line.coverage > 0
37
- tr.hit
37
+ tr.hit
38
38
  td.line= number
39
39
  td.hits= line.coverage
40
40
  td.source= line.source
41
41
  else if 0 === line.coverage
42
- tr.miss
42
+ tr.miss
43
43
  td.line= number
44
44
  td.hits 0
45
45
  td.source= line.source
@@ -47,4 +47,4 @@ html
47
47
  tr
48
48
  td.line= number
49
49
  td.hits
50
- td.source= line.source || ' '
50
+ td.source= line.source || ' '
@@ -39,7 +39,7 @@ function XUnit(runner) {
39
39
  runner.on('pass', function(test){
40
40
  tests.push(test);
41
41
  });
42
-
42
+
43
43
  runner.on('fail', function(test){
44
44
  tests.push(test);
45
45
  });
@@ -56,7 +56,7 @@ function XUnit(runner) {
56
56
  }, false));
57
57
 
58
58
  tests.forEach(test);
59
- console.log('</testsuite>');
59
+ console.log('</testsuite>');
60
60
  });
61
61
  }
62
62
 
package/lib/runnable.js CHANGED
@@ -131,16 +131,14 @@ Runnable.prototype.inspect = function(){
131
131
  */
132
132
 
133
133
  Runnable.prototype.resetTimeout = function(){
134
- var self = this
135
- , ms = this.timeout();
134
+ var self = this;
135
+ var ms = this.timeout() || 1e9;
136
136
 
137
137
  this.clearTimeout();
138
- if (ms) {
139
- this.timer = setTimeout(function(){
140
- self.callback(new Error('timeout of ' + ms + 'ms exceeded'));
141
- self.timedOut = true;
142
- }, ms);
143
- }
138
+ this.timer = setTimeout(function(){
139
+ self.callback(new Error('timeout of ' + ms + 'ms exceeded'));
140
+ self.timedOut = true;
141
+ }, ms);
144
142
  };
145
143
 
146
144
  /**