mocha 3.0.2 → 3.2.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.
Files changed (53) hide show
  1. package/CHANGELOG.md +103 -0
  2. package/LICENSE +1 -1
  3. package/README.md +2 -2
  4. package/bin/_mocha +170 -104
  5. package/bin/mocha +22 -13
  6. package/bin/options.js +7 -5
  7. package/browser-entry.js +43 -22
  8. package/lib/browser/.eslintrc.yaml +4 -0
  9. package/lib/browser/debug.js +6 -3
  10. package/lib/browser/events.js +11 -9
  11. package/lib/browser/progress.js +9 -7
  12. package/lib/browser/tty.js +4 -2
  13. package/lib/context.js +11 -9
  14. package/lib/hook.js +4 -2
  15. package/lib/interfaces/bdd.js +11 -9
  16. package/lib/interfaces/common.js +16 -14
  17. package/lib/interfaces/exports.js +4 -2
  18. package/lib/interfaces/index.js +2 -0
  19. package/lib/interfaces/qunit.js +12 -8
  20. package/lib/interfaces/tdd.js +9 -7
  21. package/lib/mocha.js +36 -34
  22. package/lib/ms.js +12 -10
  23. package/lib/pending.js +2 -1
  24. package/lib/reporters/base.js +52 -50
  25. package/lib/reporters/doc.js +8 -6
  26. package/lib/reporters/dot.js +9 -7
  27. package/lib/reporters/html.js +32 -30
  28. package/lib/reporters/index.js +2 -0
  29. package/lib/reporters/json-stream.js +8 -6
  30. package/lib/reporters/json.js +11 -9
  31. package/lib/reporters/landing.js +8 -6
  32. package/lib/reporters/list.js +13 -11
  33. package/lib/reporters/markdown.js +12 -10
  34. package/lib/reporters/min.js +4 -2
  35. package/lib/reporters/nyan.js +22 -20
  36. package/lib/reporters/progress.js +7 -5
  37. package/lib/reporters/spec.js +17 -15
  38. package/lib/reporters/tap.js +10 -8
  39. package/lib/reporters/xunit.js +14 -12
  40. package/lib/runnable.js +43 -32
  41. package/lib/runner.js +78 -63
  42. package/lib/suite.js +24 -22
  43. package/lib/test.js +4 -2
  44. package/lib/utils.js +115 -90
  45. package/mocha.js +1185 -800
  46. package/package.json +9 -2
  47. package/lib/interfaces/bdd.js.orig +0 -118
  48. package/lib/mocha.js.orig +0 -532
  49. package/lib/runnable.js.orig +0 -378
  50. package/lib/runner.js.orig +0 -934
  51. package/lib/suite.js.orig +0 -418
  52. package/lib/test.js.orig +0 -52
  53. package/lib/utils.js.orig +0 -758
package/lib/runnable.js CHANGED
@@ -1,3 +1,5 @@
1
+ 'use strict';
2
+
1
3
  /**
2
4
  * Module dependencies.
3
5
  */
@@ -43,7 +45,7 @@ module.exports = Runnable;
43
45
  * @param {string} title
44
46
  * @param {Function} fn
45
47
  */
46
- function Runnable(title, fn) {
48
+ function Runnable (title, fn) {
47
49
  this.title = title;
48
50
  this.fn = fn;
49
51
  this.body = (fn || '').toString();
@@ -73,7 +75,7 @@ Runnable.prototype = create(EventEmitter.prototype, {
73
75
  * @param {number|string} ms
74
76
  * @return {Runnable|number} ms or Runnable instance.
75
77
  */
76
- Runnable.prototype.timeout = function(ms) {
78
+ Runnable.prototype.timeout = function (ms) {
77
79
  if (!arguments.length) {
78
80
  return this._timeout;
79
81
  }
@@ -99,7 +101,7 @@ Runnable.prototype.timeout = function(ms) {
99
101
  * @param {number|string} ms
100
102
  * @return {Runnable|number} ms or Runnable instance.
101
103
  */
102
- Runnable.prototype.slow = function(ms) {
104
+ Runnable.prototype.slow = function (ms) {
103
105
  if (typeof ms === 'undefined') {
104
106
  return this._slow;
105
107
  }
@@ -118,7 +120,7 @@ Runnable.prototype.slow = function(ms) {
118
120
  * @param {boolean} enabled
119
121
  * @return {Runnable|boolean} enabled or Runnable instance.
120
122
  */
121
- Runnable.prototype.enableTimeouts = function(enabled) {
123
+ Runnable.prototype.enableTimeouts = function (enabled) {
122
124
  if (!arguments.length) {
123
125
  return this._enableTimeouts;
124
126
  }
@@ -132,8 +134,8 @@ Runnable.prototype.enableTimeouts = function(enabled) {
132
134
  *
133
135
  * @api public
134
136
  */
135
- Runnable.prototype.skip = function() {
136
- throw new Pending();
137
+ Runnable.prototype.skip = function () {
138
+ throw new Pending('sync skip');
137
139
  };
138
140
 
139
141
  /**
@@ -141,7 +143,7 @@ Runnable.prototype.skip = function() {
141
143
  *
142
144
  * @api private
143
145
  */
144
- Runnable.prototype.isPending = function() {
146
+ Runnable.prototype.isPending = function () {
145
147
  return this.pending || (this.parent && this.parent.isPending());
146
148
  };
147
149
 
@@ -150,7 +152,7 @@ Runnable.prototype.isPending = function() {
150
152
  *
151
153
  * @api private
152
154
  */
153
- Runnable.prototype.retries = function(n) {
155
+ Runnable.prototype.retries = function (n) {
154
156
  if (!arguments.length) {
155
157
  return this._retries;
156
158
  }
@@ -162,7 +164,7 @@ Runnable.prototype.retries = function(n) {
162
164
  *
163
165
  * @api private
164
166
  */
165
- Runnable.prototype.currentRetry = function(n) {
167
+ Runnable.prototype.currentRetry = function (n) {
166
168
  if (!arguments.length) {
167
169
  return this._currentRetry;
168
170
  }
@@ -176,7 +178,7 @@ Runnable.prototype.currentRetry = function(n) {
176
178
  * @api public
177
179
  * @return {string}
178
180
  */
179
- Runnable.prototype.fullTitle = function() {
181
+ Runnable.prototype.fullTitle = function () {
180
182
  return this.parent.fullTitle() + ' ' + this.title;
181
183
  };
182
184
 
@@ -185,7 +187,7 @@ Runnable.prototype.fullTitle = function() {
185
187
  *
186
188
  * @api private
187
189
  */
188
- Runnable.prototype.clearTimeout = function() {
190
+ Runnable.prototype.clearTimeout = function () {
189
191
  clearTimeout(this.timer);
190
192
  };
191
193
 
@@ -195,8 +197,8 @@ Runnable.prototype.clearTimeout = function() {
195
197
  * @api private
196
198
  * @return {string}
197
199
  */
198
- Runnable.prototype.inspect = function() {
199
- return JSON.stringify(this, function(key, val) {
200
+ Runnable.prototype.inspect = function () {
201
+ return JSON.stringify(this, function (key, val) {
200
202
  if (key[0] === '_') {
201
203
  return;
202
204
  }
@@ -215,7 +217,7 @@ Runnable.prototype.inspect = function() {
215
217
  *
216
218
  * @api private
217
219
  */
218
- Runnable.prototype.resetTimeout = function() {
220
+ Runnable.prototype.resetTimeout = function () {
219
221
  var self = this;
220
222
  var ms = this.timeout() || 1e9;
221
223
 
@@ -223,11 +225,12 @@ Runnable.prototype.resetTimeout = function() {
223
225
  return;
224
226
  }
225
227
  this.clearTimeout();
226
- this.timer = setTimeout(function() {
228
+ this.timer = setTimeout(function () {
227
229
  if (!self._enableTimeouts) {
228
230
  return;
229
231
  }
230
- self.callback(new Error('timeout of ' + ms + 'ms exceeded. Ensure the done() callback is being called in this test.'));
232
+ self.callback(new Error('Timeout of ' + ms +
233
+ 'ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.'));
231
234
  self.timedOut = true;
232
235
  }, ms);
233
236
  };
@@ -238,7 +241,7 @@ Runnable.prototype.resetTimeout = function() {
238
241
  * @api private
239
242
  * @param {string[]} globals
240
243
  */
241
- Runnable.prototype.globals = function(globals) {
244
+ Runnable.prototype.globals = function (globals) {
242
245
  if (!arguments.length) {
243
246
  return this._allowedGlobals;
244
247
  }
@@ -251,7 +254,7 @@ Runnable.prototype.globals = function(globals) {
251
254
  * @param {Function} fn
252
255
  * @api private
253
256
  */
254
- Runnable.prototype.run = function(fn) {
257
+ Runnable.prototype.run = function (fn) {
255
258
  var self = this;
256
259
  var start = new Date();
257
260
  var ctx = this.ctx;
@@ -264,7 +267,7 @@ Runnable.prototype.run = function(fn) {
264
267
  }
265
268
 
266
269
  // called multiple times
267
- function multiple(err) {
270
+ function multiple (err) {
268
271
  if (emitted) {
269
272
  return;
270
273
  }
@@ -273,7 +276,7 @@ Runnable.prototype.run = function(fn) {
273
276
  }
274
277
 
275
278
  // finished
276
- function done(err) {
279
+ function done (err) {
277
280
  var ms = self.timeout();
278
281
  if (self.timedOut) {
279
282
  return;
@@ -286,7 +289,8 @@ Runnable.prototype.run = function(fn) {
286
289
  self.duration = new Date() - start;
287
290
  finished = true;
288
291
  if (!err && self.duration > ms && self._enableTimeouts) {
289
- err = new Error('timeout of ' + ms + 'ms exceeded. Ensure the done() callback is being called in this test.');
292
+ err = new Error('Timeout of ' + ms +
293
+ 'ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.');
290
294
  }
291
295
  fn(err);
292
296
  }
@@ -298,16 +302,22 @@ Runnable.prototype.run = function(fn) {
298
302
  if (this.async) {
299
303
  this.resetTimeout();
300
304
 
305
+ // allows skip() to be used in an explicit async context
306
+ this.skip = function asyncSkip () {
307
+ done(new Pending('async skip call'));
308
+ // halt execution. the Runnable will be marked pending
309
+ // by the previous call, and the uncaught handler will ignore
310
+ // the failure.
311
+ throw new Pending('async skip; aborting execution');
312
+ };
313
+
301
314
  if (this.allowUncaught) {
302
315
  return callFnAsync(this.fn);
303
316
  }
304
317
  try {
305
- // allows skip() to be used in an explicit async context
306
- this.skip = function() {
307
- done(new Pending());
308
- };
309
318
  callFnAsync(this.fn);
310
319
  } catch (err) {
320
+ emitted = true;
311
321
  done(utils.getError(err));
312
322
  }
313
323
  return;
@@ -327,21 +337,22 @@ Runnable.prototype.run = function(fn) {
327
337
  callFn(this.fn);
328
338
  }
329
339
  } catch (err) {
340
+ emitted = true;
330
341
  done(utils.getError(err));
331
342
  }
332
343
 
333
- function callFn(fn) {
344
+ function callFn (fn) {
334
345
  var result = fn.call(ctx);
335
346
  if (result && typeof result.then === 'function') {
336
347
  self.resetTimeout();
337
348
  result
338
- .then(function() {
349
+ .then(function () {
339
350
  done();
340
351
  // Return null so libraries like bluebird do not warn about
341
352
  // subsequently constructed Promises.
342
353
  return null;
343
354
  },
344
- function(reason) {
355
+ function (reason) {
345
356
  done(reason || new Error('Promise rejected with no or falsy reason'));
346
357
  });
347
358
  } else {
@@ -353,15 +364,15 @@ Runnable.prototype.run = function(fn) {
353
364
  }
354
365
  }
355
366
 
356
- function callFnAsync(fn) {
357
- var result = fn.call(ctx, function(err) {
367
+ function callFnAsync (fn) {
368
+ var result = fn.call(ctx, function (err) {
358
369
  if (err instanceof Error || toString.call(err) === '[object Error]') {
359
370
  return done(err);
360
371
  }
361
372
  if (err) {
362
373
  if (Object.prototype.toString.call(err) === '[object Object]') {
363
- return done(new Error('done() invoked with non-Error: '
364
- + JSON.stringify(err)));
374
+ return done(new Error('done() invoked with non-Error: ' +
375
+ JSON.stringify(err)));
365
376
  }
366
377
  return done(new Error('done() invoked with non-Error: ' + err));
367
378
  }