mocha 2.2.5 → 2.3.3

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.
Files changed (50) hide show
  1. package/HISTORY.md +1034 -0
  2. package/bin/.eslintrc +3 -0
  3. package/bin/_mocha +12 -15
  4. package/bin/mocha +3 -10
  5. package/bin/options.js +6 -5
  6. package/lib/browser/debug.js +3 -3
  7. package/lib/browser/events.js +42 -26
  8. package/lib/browser/progress.js +37 -45
  9. package/lib/browser/tty.js +4 -5
  10. package/lib/context.js +26 -32
  11. package/lib/hook.js +5 -7
  12. package/lib/interfaces/bdd.js +21 -26
  13. package/lib/interfaces/common.js +33 -15
  14. package/lib/interfaces/exports.js +7 -7
  15. package/lib/interfaces/qunit.js +16 -17
  16. package/lib/interfaces/tdd.js +24 -28
  17. package/lib/mocha.js +140 -99
  18. package/lib/ms.js +43 -24
  19. package/lib/pending.js +2 -3
  20. package/lib/reporters/base.js +159 -138
  21. package/lib/reporters/doc.js +13 -13
  22. package/lib/reporters/dot.js +23 -19
  23. package/lib/reporters/html-cov.js +25 -19
  24. package/lib/reporters/html.js +130 -91
  25. package/lib/reporters/index.js +19 -17
  26. package/lib/reporters/json-cov.js +39 -41
  27. package/lib/reporters/json-stream.js +14 -17
  28. package/lib/reporters/json.js +16 -19
  29. package/lib/reporters/landing.js +20 -24
  30. package/lib/reporters/list.js +14 -16
  31. package/lib/reporters/markdown.js +17 -20
  32. package/lib/reporters/min.js +4 -5
  33. package/lib/reporters/nyan.js +49 -48
  34. package/lib/reporters/progress.js +20 -23
  35. package/lib/reporters/spec.js +23 -22
  36. package/lib/reporters/tap.js +15 -19
  37. package/lib/reporters/xunit.js +83 -63
  38. package/lib/runnable.js +134 -94
  39. package/lib/runner.js +291 -167
  40. package/lib/suite.js +105 -95
  41. package/lib/template.html +1 -1
  42. package/lib/test.js +3 -4
  43. package/lib/utils.js +227 -199
  44. package/mocha.css +35 -0
  45. package/mocha.js +8324 -2471
  46. package/package.json +250 -10
  47. package/lib/browser/escape-string-regexp.js +0 -11
  48. package/lib/browser/fs.js +0 -0
  49. package/lib/browser/glob.js +0 -0
  50. package/lib/browser/path.js +0 -0
package/bin/.eslintrc ADDED
@@ -0,0 +1,3 @@
1
+ ---
2
+ rules:
3
+ no-process-exit: 0
package/bin/_mocha CHANGED
@@ -58,7 +58,7 @@ var images = {
58
58
  program
59
59
  .version(JSON.parse(fs.readFileSync(__dirname + '/../package.json', 'utf8')).version)
60
60
  .usage('[debug] [options] [files]')
61
- .option('-A, --async-only', "force all tests to take a callback (async)")
61
+ .option('-A, --async-only', "force all tests to take a callback (async) or return a promise")
62
62
  .option('-c, --colors', 'force enabling of colors')
63
63
  .option('-C, --no-colors', 'force disabling of colors')
64
64
  .option('-G, --growl', 'enable growl notification support')
@@ -81,15 +81,8 @@ program
81
81
  .option('--compilers <ext>:<module>,...', 'use the given module(s) to compile files', list, [])
82
82
  .option('--debug-brk', "enable node's debugger breaking on the first line")
83
83
  .option('--globals <names>', 'allow the given comma-delimited global [names]', list, [])
84
- .option('--harmony', 'enable all harmony features (except typeof)')
85
84
  .option('--es_staging', 'enable all staged features')
86
- .option('--harmony-collections', 'enable harmony collections (sets, maps, and weak maps)')
87
- .option('--harmony-generators', 'enable harmony generators')
88
- .option('--harmony-proxies', 'enable harmony proxies')
89
- .option('--harmony_shipping', 'enable all shipped harmony fetaures (iojs)')
90
- .option('--harmony_arrow_functions', 'enable "harmony arrow functions" (iojs)')
91
- .option('--harmony_proxies', 'enable "harmony proxies" (iojs)')
92
- .option('--harmony_classes', 'enable "harmony classes" (iojs)')
85
+ .option('--harmony<_classes,_generators,...>', 'all node --harmony* flags are available')
93
86
  .option('--inline-diffs', 'display actual/expected differences inline within each string')
94
87
  .option('--interfaces', 'display available interfaces')
95
88
  .option('--no-deprecation', 'silence deprecation warnings')
@@ -194,10 +187,13 @@ var reporterOptions = {};
194
187
  if (program.reporterOptions !== undefined) {
195
188
  program.reporterOptions.split(",").forEach(function(opt) {
196
189
  var L = opt.split("=");
197
- if (L.length != 2) {
190
+ if (L.length > 2 || L.length === 0) {
198
191
  throw new Error("invalid reporter option '" + opt + "'");
192
+ } else if (L.length === 2) {
193
+ reporterOptions[L[0]] = L[1];
194
+ } else {
195
+ reporterOptions[L[0]] = true;
199
196
  }
200
- reporterOptions[L[0]] = L[1];
201
197
  });
202
198
  }
203
199
 
@@ -389,13 +385,14 @@ if (program.watch) {
389
385
  }
390
386
  });
391
387
 
392
- return;
393
- }
388
+ } else {
394
389
 
395
390
  // load
396
391
 
397
- mocha.files = files;
398
- runner = mocha.run(program.exit ? exit : exitLater);
392
+ mocha.files = files;
393
+ runner = mocha.run(program.exit ? exit : exitLater);
394
+
395
+ }
399
396
 
400
397
  function exitLater(code) {
401
398
  process.on('exit', function() { process.exit(code) })
package/bin/mocha CHANGED
@@ -34,15 +34,7 @@ process.argv.slice(2).forEach(function(arg){
34
34
  args.unshift('--expose-gc');
35
35
  break;
36
36
  case '--gc-global':
37
- case '--harmony':
38
37
  case '--es_staging':
39
- case '--harmony-proxies':
40
- case '--harmony-collections':
41
- case '--harmony-generators':
42
- case '--harmony_shipping':
43
- case '--harmony_arrow_functions':
44
- case '--harmony_proxies':
45
- case '--harmony_classes':
46
38
  case '--no-deprecation':
47
39
  case '--prof':
48
40
  case '--throw-deprecation':
@@ -51,7 +43,9 @@ process.argv.slice(2).forEach(function(arg){
51
43
  args.unshift(arg);
52
44
  break;
53
45
  default:
54
- if (0 == arg.indexOf('--trace')) args.unshift(arg);
46
+ if (0 == arg.indexOf('--harmony')) args.unshift(arg);
47
+ else if (0 == arg.indexOf('--trace')) args.unshift(arg);
48
+ else if (0 == arg.indexOf('--max-old-space-size')) args.unshift(arg);
55
49
  else args.push(arg);
56
50
  break;
57
51
  }
@@ -72,5 +66,4 @@ proc.on('exit', function (code, signal) {
72
66
  process.on('SIGINT', function () {
73
67
  proc.kill('SIGINT'); // calls runner.abort()
74
68
  proc.kill('SIGTERM'); // if that didn't work, we're probably in an infinite loop, so make it die.
75
- process.kill(process.pid, 'SIGINT');
76
69
  });
package/bin/options.js CHANGED
@@ -21,11 +21,12 @@ function getOptions() {
21
21
 
22
22
  try {
23
23
  var opts = fs.readFileSync(optsPath, 'utf8')
24
- .trim()
25
- .split(/\s+/)
26
- .filter(function(value) {
27
- return value ? true : false;
28
- });
24
+ .replace(/\\\s/g, '%20')
25
+ .split(/\s/)
26
+ .filter(Boolean)
27
+ .map(function(value) {
28
+ return value.replace(/%20/g, ' ');
29
+ });
29
30
 
30
31
  process.argv = process.argv
31
32
  .slice(0, 2)
@@ -1,4 +1,4 @@
1
- module.exports = function(type){
2
- return function(){
3
- }
1
+ /* eslint-disable no-unused-vars */
2
+ module.exports = function(type) {
3
+ return function() {};
4
4
  };
@@ -5,11 +5,19 @@
5
5
  exports.EventEmitter = EventEmitter;
6
6
 
7
7
  /**
8
- * Check if `obj` is an array.
8
+ * Object#hasOwnProperty reference.
9
9
  */
10
+ var objToString = Object.prototype.toString;
10
11
 
11
- function isArray(obj) {
12
- return '[object Array]' == {}.toString.call(obj);
12
+ /**
13
+ * Check if a value is an array.
14
+ *
15
+ * @api private
16
+ * @param {*} val The value to test.
17
+ * @return {boolean} true if the value is a boolean, otherwise false.
18
+ */
19
+ function isArray(val) {
20
+ return objToString.call(val) === '[object Array]';
13
21
  }
14
22
 
15
23
  /**
@@ -17,16 +25,17 @@ function isArray(obj) {
17
25
  *
18
26
  * @api public
19
27
  */
20
-
21
- function EventEmitter(){};
28
+ function EventEmitter() {}
22
29
 
23
30
  /**
24
- * Adds a listener.
31
+ * Add a listener.
25
32
  *
26
33
  * @api public
34
+ * @param {string} name Event name.
35
+ * @param {Function} fn Event handler.
36
+ * @return {EventEmitter} Emitter instance.
27
37
  */
28
-
29
- EventEmitter.prototype.on = function (name, fn) {
38
+ EventEmitter.prototype.on = function(name, fn) {
30
39
  if (!this.$events) {
31
40
  this.$events = {};
32
41
  }
@@ -48,15 +57,17 @@ EventEmitter.prototype.addListener = EventEmitter.prototype.on;
48
57
  * Adds a volatile listener.
49
58
  *
50
59
  * @api public
60
+ * @param {string} name Event name.
61
+ * @param {Function} fn Event handler.
62
+ * @return {EventEmitter} Emitter instance.
51
63
  */
52
-
53
- EventEmitter.prototype.once = function (name, fn) {
64
+ EventEmitter.prototype.once = function(name, fn) {
54
65
  var self = this;
55
66
 
56
- function on () {
67
+ function on() {
57
68
  self.removeListener(name, on);
58
69
  fn.apply(this, arguments);
59
- };
70
+ }
60
71
 
61
72
  on.listener = fn;
62
73
  this.on(name, on);
@@ -65,12 +76,14 @@ EventEmitter.prototype.once = function (name, fn) {
65
76
  };
66
77
 
67
78
  /**
68
- * Removes a listener.
79
+ * Remove a listener.
69
80
  *
70
81
  * @api public
82
+ * @param {string} name Event name.
83
+ * @param {Function} fn Event handler.
84
+ * @return {EventEmitter} Emitter instance.
71
85
  */
72
-
73
- EventEmitter.prototype.removeListener = function (name, fn) {
86
+ EventEmitter.prototype.removeListener = function(name, fn) {
74
87
  if (this.$events && this.$events[name]) {
75
88
  var list = this.$events[name];
76
89
 
@@ -102,12 +115,13 @@ EventEmitter.prototype.removeListener = function (name, fn) {
102
115
  };
103
116
 
104
117
  /**
105
- * Removes all listeners for an event.
118
+ * Remove all listeners for an event.
106
119
  *
107
120
  * @api public
121
+ * @param {string} name Event name.
122
+ * @return {EventEmitter} Emitter instance.
108
123
  */
109
-
110
- EventEmitter.prototype.removeAllListeners = function (name) {
124
+ EventEmitter.prototype.removeAllListeners = function(name) {
111
125
  if (name === undefined) {
112
126
  this.$events = {};
113
127
  return this;
@@ -121,12 +135,13 @@ EventEmitter.prototype.removeAllListeners = function (name) {
121
135
  };
122
136
 
123
137
  /**
124
- * Gets all listeners for a certain event.
138
+ * Get all listeners for a given event.
125
139
  *
126
140
  * @api public
141
+ * @param {string} name Event name.
142
+ * @return {EventEmitter} Emitter instance.
127
143
  */
128
-
129
- EventEmitter.prototype.listeners = function (name) {
144
+ EventEmitter.prototype.listeners = function(name) {
130
145
  if (!this.$events) {
131
146
  this.$events = {};
132
147
  }
@@ -143,12 +158,13 @@ EventEmitter.prototype.listeners = function (name) {
143
158
  };
144
159
 
145
160
  /**
146
- * Emits an event.
161
+ * Emit an event.
147
162
  *
148
163
  * @api public
164
+ * @param {string} name Event name.
165
+ * @return {boolean} true if at least one handler was invoked, else false.
149
166
  */
150
-
151
- EventEmitter.prototype.emit = function (name) {
167
+ EventEmitter.prototype.emit = function(name) {
152
168
  if (!this.$events) {
153
169
  return false;
154
170
  }
@@ -159,9 +175,9 @@ EventEmitter.prototype.emit = function (name) {
159
175
  return false;
160
176
  }
161
177
 
162
- var args = [].slice.call(arguments, 1);
178
+ var args = Array.prototype.slice.call(arguments, 1);
163
179
 
164
- if ('function' == typeof handler) {
180
+ if (typeof handler === 'function') {
165
181
  handler.apply(this, args);
166
182
  } else if (isArray(handler)) {
167
183
  var listeners = handler.slice();
@@ -7,7 +7,6 @@ module.exports = Progress;
7
7
  /**
8
8
  * Initialize a new `Progress` indicator.
9
9
  */
10
-
11
10
  function Progress() {
12
11
  this.percent = 0;
13
12
  this.size(0);
@@ -16,52 +15,48 @@ function Progress() {
16
15
  }
17
16
 
18
17
  /**
19
- * Set progress size to `n`.
18
+ * Set progress size to `size`.
20
19
  *
21
- * @param {Number} n
22
- * @return {Progress} for chaining
23
20
  * @api public
21
+ * @param {number} size
22
+ * @return {Progress} Progress instance.
24
23
  */
25
-
26
- Progress.prototype.size = function(n){
27
- this._size = n;
24
+ Progress.prototype.size = function(size) {
25
+ this._size = size;
28
26
  return this;
29
27
  };
30
28
 
31
29
  /**
32
- * Set text to `str`.
30
+ * Set text to `text`.
33
31
  *
34
- * @param {String} str
35
- * @return {Progress} for chaining
36
32
  * @api public
33
+ * @param {string} text
34
+ * @return {Progress} Progress instance.
37
35
  */
38
-
39
- Progress.prototype.text = function(str){
40
- this._text = str;
36
+ Progress.prototype.text = function(text) {
37
+ this._text = text;
41
38
  return this;
42
39
  };
43
40
 
44
41
  /**
45
- * Set font size to `n`.
42
+ * Set font size to `size`.
46
43
  *
47
- * @param {Number} n
48
- * @return {Progress} for chaining
49
44
  * @api public
45
+ * @param {number} size
46
+ * @return {Progress} Progress instance.
50
47
  */
51
-
52
- Progress.prototype.fontSize = function(n){
53
- this._fontSize = n;
48
+ Progress.prototype.fontSize = function(size) {
49
+ this._fontSize = size;
54
50
  return this;
55
51
  };
56
52
 
57
53
  /**
58
- * Set font `family`.
54
+ * Set font to `family`.
59
55
  *
60
- * @param {String} family
61
- * @return {Progress} for chaining
56
+ * @param {string} family
57
+ * @return {Progress} Progress instance.
62
58
  */
63
-
64
- Progress.prototype.font = function(family){
59
+ Progress.prototype.font = function(family) {
65
60
  this._font = family;
66
61
  return this;
67
62
  };
@@ -69,11 +64,10 @@ Progress.prototype.font = function(family){
69
64
  /**
70
65
  * Update percentage to `n`.
71
66
  *
72
- * @param {Number} n
73
- * @return {Progress} for chaining
67
+ * @param {number} n
68
+ * @return {Progress} Progress instance.
74
69
  */
75
-
76
- Progress.prototype.update = function(n){
70
+ Progress.prototype.update = function(n) {
77
71
  this.percent = n;
78
72
  return this;
79
73
  };
@@ -82,18 +76,17 @@ Progress.prototype.update = function(n){
82
76
  * Draw on `ctx`.
83
77
  *
84
78
  * @param {CanvasRenderingContext2d} ctx
85
- * @return {Progress} for chaining
79
+ * @return {Progress} Progress instance.
86
80
  */
87
-
88
- Progress.prototype.draw = function(ctx){
81
+ Progress.prototype.draw = function(ctx) {
89
82
  try {
90
- var percent = Math.min(this.percent, 100)
91
- , size = this._size
92
- , half = size / 2
93
- , x = half
94
- , y = half
95
- , rad = half - 1
96
- , fontSize = this._fontSize;
83
+ var percent = Math.min(this.percent, 100);
84
+ var size = this._size;
85
+ var half = size / 2;
86
+ var x = half;
87
+ var y = half;
88
+ var rad = half - 1;
89
+ var fontSize = this._fontSize;
97
90
 
98
91
  ctx.font = fontSize + 'px ' + this._font;
99
92
 
@@ -113,13 +106,12 @@ Progress.prototype.draw = function(ctx){
113
106
  ctx.stroke();
114
107
 
115
108
  // text
116
- var text = this._text || (percent | 0) + '%'
117
- , w = ctx.measureText(text).width;
109
+ var text = this._text || (percent | 0) + '%';
110
+ var w = ctx.measureText(text).width;
118
111
 
119
- ctx.fillText(
120
- text
121
- , x - w / 2 + 1
122
- , y + fontSize / 2 - 1);
123
- } catch (ex) {} //don't fail if we can't render progress
112
+ ctx.fillText(text, x - w / 2 + 1, y + fontSize / 2 - 1);
113
+ } catch (err) {
114
+ // don't fail if we can't render progress
115
+ }
124
116
  return this;
125
117
  };
@@ -1,12 +1,11 @@
1
- exports.isatty = function(){
1
+ exports.isatty = function isatty() {
2
2
  return true;
3
3
  };
4
4
 
5
- exports.getWindowSize = function(){
5
+ exports.getWindowSize = function getWindowSize() {
6
6
  if ('innerHeight' in global) {
7
7
  return [global.innerHeight, global.innerWidth];
8
- } else {
9
- // In a Web Worker, the DOM Window is not available.
10
- return [640, 480];
11
8
  }
9
+ // In a Web Worker, the DOM Window is not available.
10
+ return [640, 480];
12
11
  };
package/lib/context.js CHANGED
@@ -9,19 +9,19 @@ module.exports = Context;
9
9
  *
10
10
  * @api private
11
11
  */
12
-
13
- function Context(){}
12
+ function Context() {}
14
13
 
15
14
  /**
16
15
  * Set or get the context `Runnable` to `runnable`.
17
16
  *
17
+ * @api private
18
18
  * @param {Runnable} runnable
19
19
  * @return {Context}
20
- * @api private
21
20
  */
22
-
23
- Context.prototype.runnable = function(runnable){
24
- if (0 == arguments.length) return this._runnable;
21
+ Context.prototype.runnable = function(runnable) {
22
+ if (!arguments.length) {
23
+ return this._runnable;
24
+ }
25
25
  this.test = this._runnable = runnable;
26
26
  return this;
27
27
  };
@@ -29,13 +29,14 @@ Context.prototype.runnable = function(runnable){
29
29
  /**
30
30
  * Set test timeout `ms`.
31
31
  *
32
- * @param {Number} ms
33
- * @return {Context} self
34
32
  * @api private
33
+ * @param {number} ms
34
+ * @return {Context} self
35
35
  */
36
-
37
- Context.prototype.timeout = function(ms){
38
- if (arguments.length === 0) return this.runnable().timeout();
36
+ Context.prototype.timeout = function(ms) {
37
+ if (!arguments.length) {
38
+ return this.runnable().timeout();
39
+ }
39
40
  this.runnable().timeout(ms);
40
41
  return this;
41
42
  };
@@ -43,26 +44,23 @@ Context.prototype.timeout = function(ms){
43
44
  /**
44
45
  * Set test timeout `enabled`.
45
46
  *
46
- * @param {Boolean} enabled
47
- * @return {Context} self
48
47
  * @api private
48
+ * @param {boolean} enabled
49
+ * @return {Context} self
49
50
  */
50
-
51
- Context.prototype.enableTimeouts = function (enabled) {
51
+ Context.prototype.enableTimeouts = function(enabled) {
52
52
  this.runnable().enableTimeouts(enabled);
53
53
  return this;
54
54
  };
55
55
 
56
-
57
56
  /**
58
57
  * Set test slowness threshold `ms`.
59
58
  *
60
- * @param {Number} ms
61
- * @return {Context} self
62
59
  * @api private
60
+ * @param {number} ms
61
+ * @return {Context} self
63
62
  */
64
-
65
- Context.prototype.slow = function(ms){
63
+ Context.prototype.slow = function(ms) {
66
64
  this.runnable().slow(ms);
67
65
  return this;
68
66
  };
@@ -70,26 +68,22 @@ Context.prototype.slow = function(ms){
70
68
  /**
71
69
  * Mark a test as skipped.
72
70
  *
73
- * @return {Context} self
74
71
  * @api private
72
+ * @return {Context} self
75
73
  */
76
-
77
- Context.prototype.skip = function(){
78
- this.runnable().skip();
79
- return this;
74
+ Context.prototype.skip = function() {
75
+ this.runnable().skip();
76
+ return this;
80
77
  };
81
78
 
82
79
  /**
83
80
  * Inspect the context void of `._runnable`.
84
81
  *
85
- * @return {String}
86
82
  * @api private
83
+ * @return {string}
87
84
  */
88
-
89
- Context.prototype.inspect = function(){
90
- return JSON.stringify(this, function(key, val){
91
- if ('_runnable' == key) return;
92
- if ('test' == key) return;
93
- return val;
85
+ Context.prototype.inspect = function() {
86
+ return JSON.stringify(this, function(key, val) {
87
+ return key === 'runnable' || key === 'test' ? undefined : val;
94
88
  }, 2);
95
89
  };
package/lib/hook.js CHANGED
@@ -3,6 +3,7 @@
3
3
  */
4
4
 
5
5
  var Runnable = require('./runnable');
6
+ var inherits = require('./utils').inherits;
6
7
 
7
8
  /**
8
9
  * Expose `Hook`.
@@ -17,7 +18,6 @@ module.exports = Hook;
17
18
  * @param {Function} fn
18
19
  * @api private
19
20
  */
20
-
21
21
  function Hook(title, fn) {
22
22
  Runnable.call(this, title, fn);
23
23
  this.type = 'hook';
@@ -26,8 +26,7 @@ function Hook(title, fn) {
26
26
  /**
27
27
  * Inherit from `Runnable.prototype`.
28
28
  */
29
-
30
- Hook.prototype.__proto__ = Runnable.prototype;
29
+ inherits(Hook, Runnable);
31
30
 
32
31
  /**
33
32
  * Get or set the test `err`.
@@ -36,10 +35,9 @@ Hook.prototype.__proto__ = Runnable.prototype;
36
35
  * @return {Error}
37
36
  * @api public
38
37
  */
39
-
40
- Hook.prototype.error = function(err){
41
- if (0 == arguments.length) {
42
- var err = this._error;
38
+ Hook.prototype.error = function(err) {
39
+ if (!arguments.length) {
40
+ err = this._error;
43
41
  this._error = null;
44
42
  return err;
45
43
  }