mocha 5.1.1 → 5.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.
package/lib/runnable.js CHANGED
@@ -1,10 +1,4 @@
1
1
  'use strict';
2
- /**
3
- * @module Runnable
4
- */
5
- /**
6
- * Module dependencies.
7
- */
8
2
  var EventEmitter = require('events').EventEmitter;
9
3
  var Pending = require('./pending');
10
4
  var debug = require('debug')('mocha:runnable');
@@ -23,28 +17,19 @@ var clearTimeout = global.clearTimeout;
23
17
  var clearInterval = global.clearInterval;
24
18
  /* eslint-enable no-unused-vars, no-native-reassign */
25
19
 
26
- /**
27
- * Object#toString().
28
- */
29
-
30
20
  var toString = Object.prototype.toString;
31
21
 
32
- /**
33
- * Expose `Runnable`.
34
- */
35
-
36
22
  module.exports = Runnable;
37
23
 
38
24
  /**
39
25
  * Initialize a new `Runnable` with the given `title` and callback `fn`. Derived from [EventEmitter](https://nodejs.org/api/events.html#events_class_eventemitter)
40
26
  *
41
- * @memberof Mocha
42
- * @public
43
27
  * @class
28
+ * @extends EventEmitter
44
29
  * @param {String} title
45
30
  * @param {Function} fn
46
31
  */
47
- function Runnable (title, fn) {
32
+ function Runnable(title, fn) {
48
33
  this.title = title;
49
34
  this.fn = fn;
50
35
  this.body = (fn || '').toString();
@@ -71,7 +56,7 @@ utils.inherits(Runnable, EventEmitter);
71
56
  * @param {number|string} ms
72
57
  * @return {Runnable|number} ms or Runnable instance.
73
58
  */
74
- Runnable.prototype.timeout = function (ms) {
59
+ Runnable.prototype.timeout = function(ms) {
75
60
  if (!arguments.length) {
76
61
  return this._timeout;
77
62
  }
@@ -97,7 +82,7 @@ Runnable.prototype.timeout = function (ms) {
97
82
  * @param {number|string} ms
98
83
  * @return {Runnable|number} ms or Runnable instance.
99
84
  */
100
- Runnable.prototype.slow = function (ms) {
85
+ Runnable.prototype.slow = function(ms) {
101
86
  if (!arguments.length || typeof ms === 'undefined') {
102
87
  return this._slow;
103
88
  }
@@ -116,7 +101,7 @@ Runnable.prototype.slow = function (ms) {
116
101
  * @param {boolean} enabled
117
102
  * @return {Runnable|boolean} enabled or Runnable instance.
118
103
  */
119
- Runnable.prototype.enableTimeouts = function (enabled) {
104
+ Runnable.prototype.enableTimeouts = function(enabled) {
120
105
  if (!arguments.length) {
121
106
  return this._enableTimeouts;
122
107
  }
@@ -132,7 +117,7 @@ Runnable.prototype.enableTimeouts = function (enabled) {
132
117
  * @public
133
118
  * @api public
134
119
  */
135
- Runnable.prototype.skip = function () {
120
+ Runnable.prototype.skip = function() {
136
121
  throw new Pending('sync skip');
137
122
  };
138
123
 
@@ -141,7 +126,7 @@ Runnable.prototype.skip = function () {
141
126
  *
142
127
  * @api private
143
128
  */
144
- Runnable.prototype.isPending = function () {
129
+ Runnable.prototype.isPending = function() {
145
130
  return this.pending || (this.parent && this.parent.isPending());
146
131
  };
147
132
 
@@ -150,7 +135,7 @@ Runnable.prototype.isPending = function () {
150
135
  * @return {boolean}
151
136
  * @private
152
137
  */
153
- Runnable.prototype.isFailed = function () {
138
+ Runnable.prototype.isFailed = function() {
154
139
  return !this.isPending() && this.state === 'failed';
155
140
  };
156
141
 
@@ -159,7 +144,7 @@ Runnable.prototype.isFailed = function () {
159
144
  * @return {boolean}
160
145
  * @private
161
146
  */
162
- Runnable.prototype.isPassed = function () {
147
+ Runnable.prototype.isPassed = function() {
163
148
  return !this.isPending() && this.state === 'passed';
164
149
  };
165
150
 
@@ -168,7 +153,7 @@ Runnable.prototype.isPassed = function () {
168
153
  *
169
154
  * @api private
170
155
  */
171
- Runnable.prototype.retries = function (n) {
156
+ Runnable.prototype.retries = function(n) {
172
157
  if (!arguments.length) {
173
158
  return this._retries;
174
159
  }
@@ -180,7 +165,7 @@ Runnable.prototype.retries = function (n) {
180
165
  *
181
166
  * @api private
182
167
  */
183
- Runnable.prototype.currentRetry = function (n) {
168
+ Runnable.prototype.currentRetry = function(n) {
184
169
  if (!arguments.length) {
185
170
  return this._currentRetry;
186
171
  }
@@ -196,7 +181,7 @@ Runnable.prototype.currentRetry = function (n) {
196
181
  * @api public
197
182
  * @return {string}
198
183
  */
199
- Runnable.prototype.fullTitle = function () {
184
+ Runnable.prototype.fullTitle = function() {
200
185
  return this.titlePath().join(' ');
201
186
  };
202
187
 
@@ -208,7 +193,7 @@ Runnable.prototype.fullTitle = function () {
208
193
  * @api public
209
194
  * @return {string}
210
195
  */
211
- Runnable.prototype.titlePath = function () {
196
+ Runnable.prototype.titlePath = function() {
212
197
  return this.parent.titlePath().concat([this.title]);
213
198
  };
214
199
 
@@ -217,7 +202,7 @@ Runnable.prototype.titlePath = function () {
217
202
  *
218
203
  * @api private
219
204
  */
220
- Runnable.prototype.clearTimeout = function () {
205
+ Runnable.prototype.clearTimeout = function() {
221
206
  clearTimeout(this.timer);
222
207
  };
223
208
 
@@ -227,19 +212,23 @@ Runnable.prototype.clearTimeout = function () {
227
212
  * @api private
228
213
  * @return {string}
229
214
  */
230
- Runnable.prototype.inspect = function () {
231
- return JSON.stringify(this, function (key, val) {
232
- if (key[0] === '_') {
233
- return;
234
- }
235
- if (key === 'parent') {
236
- return '#<Suite>';
237
- }
238
- if (key === 'ctx') {
239
- return '#<Context>';
240
- }
241
- return val;
242
- }, 2);
215
+ Runnable.prototype.inspect = function() {
216
+ return JSON.stringify(
217
+ this,
218
+ function(key, val) {
219
+ if (key[0] === '_') {
220
+ return;
221
+ }
222
+ if (key === 'parent') {
223
+ return '#<Suite>';
224
+ }
225
+ if (key === 'ctx') {
226
+ return '#<Context>';
227
+ }
228
+ return val;
229
+ },
230
+ 2
231
+ );
243
232
  };
244
233
 
245
234
  /**
@@ -247,7 +236,7 @@ Runnable.prototype.inspect = function () {
247
236
  *
248
237
  * @api private
249
238
  */
250
- Runnable.prototype.resetTimeout = function () {
239
+ Runnable.prototype.resetTimeout = function() {
251
240
  var self = this;
252
241
  var ms = this.timeout() || 1e9;
253
242
 
@@ -255,7 +244,7 @@ Runnable.prototype.resetTimeout = function () {
255
244
  return;
256
245
  }
257
246
  this.clearTimeout();
258
- this.timer = setTimeout(function () {
247
+ this.timer = setTimeout(function() {
259
248
  if (!self._enableTimeouts) {
260
249
  return;
261
250
  }
@@ -270,7 +259,7 @@ Runnable.prototype.resetTimeout = function () {
270
259
  * @api private
271
260
  * @param {string[]} globals
272
261
  */
273
- Runnable.prototype.globals = function (globals) {
262
+ Runnable.prototype.globals = function(globals) {
274
263
  if (!arguments.length) {
275
264
  return this._allowedGlobals;
276
265
  }
@@ -283,7 +272,7 @@ Runnable.prototype.globals = function (globals) {
283
272
  * @param {Function} fn
284
273
  * @api private
285
274
  */
286
- Runnable.prototype.run = function (fn) {
275
+ Runnable.prototype.run = function(fn) {
287
276
  var self = this;
288
277
  var start = new Date();
289
278
  var ctx = this.ctx;
@@ -296,7 +285,7 @@ Runnable.prototype.run = function (fn) {
296
285
  }
297
286
 
298
287
  // called multiple times
299
- function multiple (err) {
288
+ function multiple(err) {
300
289
  if (emitted) {
301
290
  return;
302
291
  }
@@ -311,7 +300,7 @@ Runnable.prototype.run = function (fn) {
311
300
  }
312
301
 
313
302
  // finished
314
- function done (err) {
303
+ function done(err) {
315
304
  var ms = self.timeout();
316
305
  if (self.timedOut) {
317
306
  return;
@@ -338,7 +327,7 @@ Runnable.prototype.run = function (fn) {
338
327
  this.resetTimeout();
339
328
 
340
329
  // allows skip() to be used in an explicit async context
341
- this.skip = function asyncSkip () {
330
+ this.skip = function asyncSkip() {
342
331
  done(new Pending('async skip call'));
343
332
  // halt execution. the Runnable will be marked pending
344
333
  // by the previous call, and the uncaught handler will ignore
@@ -379,43 +368,53 @@ Runnable.prototype.run = function (fn) {
379
368
  done(utils.getError(err));
380
369
  }
381
370
 
382
- function callFn (fn) {
371
+ function callFn(fn) {
383
372
  var result = fn.call(ctx);
384
373
  if (result && typeof result.then === 'function') {
385
374
  self.resetTimeout();
386
- result
387
- .then(function () {
375
+ result.then(
376
+ function() {
388
377
  done();
389
378
  // Return null so libraries like bluebird do not warn about
390
379
  // subsequently constructed Promises.
391
380
  return null;
392
381
  },
393
- function (reason) {
382
+ function(reason) {
394
383
  done(reason || new Error('Promise rejected with no or falsy reason'));
395
- });
384
+ }
385
+ );
396
386
  } else {
397
387
  if (self.asyncOnly) {
398
- return done(new Error('--async-only option in use without declaring `done()` or returning a promise'));
388
+ return done(
389
+ new Error(
390
+ '--async-only option in use without declaring `done()` or returning a promise'
391
+ )
392
+ );
399
393
  }
400
394
 
401
395
  done();
402
396
  }
403
397
  }
404
398
 
405
- function callFnAsync (fn) {
406
- var result = fn.call(ctx, function (err) {
399
+ function callFnAsync(fn) {
400
+ var result = fn.call(ctx, function(err) {
407
401
  if (err instanceof Error || toString.call(err) === '[object Error]') {
408
402
  return done(err);
409
403
  }
410
404
  if (err) {
411
405
  if (Object.prototype.toString.call(err) === '[object Object]') {
412
- return done(new Error('done() invoked with non-Error: ' +
413
- JSON.stringify(err)));
406
+ return done(
407
+ new Error('done() invoked with non-Error: ' + JSON.stringify(err))
408
+ );
414
409
  }
415
410
  return done(new Error('done() invoked with non-Error: ' + err));
416
411
  }
417
412
  if (result && utils.isPromise(result)) {
418
- return done(new Error('Resolution method is overspecified. Specify a callback *or* return a Promise; not both.'));
413
+ return done(
414
+ new Error(
415
+ 'Resolution method is overspecified. Specify a callback *or* return a Promise; not both.'
416
+ )
417
+ );
419
418
  }
420
419
 
421
420
  done();
@@ -430,8 +429,11 @@ Runnable.prototype.run = function (fn) {
430
429
  * @returns {Error} a "timeout" error
431
430
  * @private
432
431
  */
433
- Runnable.prototype._timeoutError = function (ms) {
434
- var msg = 'Timeout of ' + ms + 'ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.';
432
+ Runnable.prototype._timeoutError = function(ms) {
433
+ var msg =
434
+ 'Timeout of ' +
435
+ ms +
436
+ 'ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.';
435
437
  if (this.file) {
436
438
  msg += ' (' + this.file + ')';
437
439
  }