mocha 5.1.0 → 6.0.0-1
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/CHANGELOG.md +653 -981
- package/README.md +2 -1
- package/{images → assets/growl}/error.png +0 -0
- package/{images → assets/growl}/ok.png +0 -0
- package/bin/_mocha +4 -595
- package/bin/mocha +84 -58
- package/bin/options.js +6 -39
- package/browser-entry.js +21 -17
- package/lib/browser/growl.js +164 -2
- package/lib/browser/progress.js +11 -11
- package/lib/{template.html → browser/template.html} +0 -0
- package/lib/browser/tty.js +2 -2
- package/lib/cli/cli.js +68 -0
- package/lib/cli/commands.js +13 -0
- package/lib/cli/config.js +79 -0
- package/lib/cli/index.js +9 -0
- package/lib/cli/init.js +37 -0
- package/lib/cli/node-flags.js +48 -0
- package/lib/cli/one-and-dones.js +70 -0
- package/lib/cli/options.js +299 -0
- package/lib/cli/run-helpers.js +328 -0
- package/lib/cli/run-option-metadata.js +72 -0
- package/lib/cli/run.js +293 -0
- package/lib/context.js +14 -14
- package/lib/errors.js +139 -0
- package/lib/growl.js +135 -0
- package/lib/hook.js +5 -16
- package/lib/interfaces/bdd.js +14 -13
- package/lib/interfaces/common.js +59 -16
- package/lib/interfaces/exports.js +4 -7
- package/lib/interfaces/qunit.js +8 -10
- package/lib/interfaces/tdd.js +10 -11
- package/lib/mocha.js +442 -255
- package/lib/mocharc.json +10 -0
- package/lib/pending.js +1 -5
- package/lib/reporters/base.js +92 -117
- package/lib/reporters/doc.js +18 -9
- package/lib/reporters/dot.js +13 -13
- package/lib/reporters/html.js +76 -47
- package/lib/reporters/json-stream.js +38 -23
- package/lib/reporters/json.js +26 -23
- package/lib/reporters/landing.js +9 -8
- package/lib/reporters/list.js +11 -10
- package/lib/reporters/markdown.js +13 -12
- package/lib/reporters/min.js +4 -3
- package/lib/reporters/nyan.js +36 -35
- package/lib/reporters/progress.js +8 -7
- package/lib/reporters/spec.js +14 -11
- package/lib/reporters/tap.js +243 -32
- package/lib/reporters/xunit.js +52 -33
- package/lib/runnable.js +103 -90
- package/lib/runner.js +156 -107
- package/lib/stats-collector.js +81 -0
- package/lib/suite.js +57 -51
- package/lib/test.js +13 -13
- package/lib/utils.js +192 -103
- package/mocha.js +3836 -2046
- package/package.json +122 -38
- package/bin/.eslintrc.yml +0 -3
- package/lib/browser/.eslintrc.yml +0 -4
- package/lib/ms.js +0 -94
- package/lib/reporters/base.js.orig +0 -498
- package/lib/reporters/json.js.orig +0 -128
package/lib/runnable.js
CHANGED
|
@@ -1,50 +1,29 @@
|
|
|
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');
|
|
11
|
-
var milliseconds = require('
|
|
5
|
+
var milliseconds = require('ms');
|
|
12
6
|
var utils = require('./utils');
|
|
13
7
|
|
|
14
8
|
/**
|
|
15
9
|
* Save timer references to avoid Sinon interfering (see GH-237).
|
|
16
10
|
*/
|
|
17
|
-
|
|
18
|
-
/* eslint-disable no-unused-vars, no-native-reassign */
|
|
19
11
|
var Date = global.Date;
|
|
20
12
|
var setTimeout = global.setTimeout;
|
|
21
|
-
var setInterval = global.setInterval;
|
|
22
13
|
var clearTimeout = global.clearTimeout;
|
|
23
|
-
var clearInterval = global.clearInterval;
|
|
24
|
-
/* eslint-enable no-unused-vars, no-native-reassign */
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Object#toString().
|
|
28
|
-
*/
|
|
29
|
-
|
|
30
14
|
var toString = Object.prototype.toString;
|
|
31
15
|
|
|
32
|
-
/**
|
|
33
|
-
* Expose `Runnable`.
|
|
34
|
-
*/
|
|
35
|
-
|
|
36
16
|
module.exports = Runnable;
|
|
37
17
|
|
|
38
18
|
/**
|
|
39
19
|
* Initialize a new `Runnable` with the given `title` and callback `fn`. Derived from [EventEmitter](https://nodejs.org/api/events.html#events_class_eventemitter)
|
|
40
20
|
*
|
|
41
|
-
* @memberof Mocha
|
|
42
|
-
* @public
|
|
43
21
|
* @class
|
|
22
|
+
* @extends EventEmitter
|
|
44
23
|
* @param {String} title
|
|
45
24
|
* @param {Function} fn
|
|
46
25
|
*/
|
|
47
|
-
function Runnable
|
|
26
|
+
function Runnable(title, fn) {
|
|
48
27
|
this.title = title;
|
|
49
28
|
this.fn = fn;
|
|
50
29
|
this.body = (fn || '').toString();
|
|
@@ -65,23 +44,43 @@ function Runnable (title, fn) {
|
|
|
65
44
|
utils.inherits(Runnable, EventEmitter);
|
|
66
45
|
|
|
67
46
|
/**
|
|
68
|
-
*
|
|
47
|
+
* Get current timeout value in msecs.
|
|
69
48
|
*
|
|
70
|
-
* @
|
|
71
|
-
* @
|
|
72
|
-
|
|
49
|
+
* @private
|
|
50
|
+
* @returns {number} current timeout threshold value
|
|
51
|
+
*/
|
|
52
|
+
/**
|
|
53
|
+
* @summary
|
|
54
|
+
* Set timeout threshold value (msecs).
|
|
55
|
+
*
|
|
56
|
+
* @description
|
|
57
|
+
* A string argument can use shorthand (e.g., "2s") and will be converted.
|
|
58
|
+
* The value will be clamped to range [<code>0</code>, <code>2^<sup>31</sup>-1</code>].
|
|
59
|
+
* If clamped value matches either range endpoint, timeouts will be disabled.
|
|
60
|
+
*
|
|
61
|
+
* @private
|
|
62
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setTimeout#Maximum_delay_value}
|
|
63
|
+
* @param {number|string} ms - Timeout threshold value.
|
|
64
|
+
* @returns {Runnable} this
|
|
65
|
+
* @chainable
|
|
73
66
|
*/
|
|
74
|
-
Runnable.prototype.timeout = function
|
|
67
|
+
Runnable.prototype.timeout = function(ms) {
|
|
75
68
|
if (!arguments.length) {
|
|
76
69
|
return this._timeout;
|
|
77
70
|
}
|
|
78
|
-
// see #1652 for reasoning
|
|
79
|
-
if (ms === 0 || ms > Math.pow(2, 31)) {
|
|
80
|
-
this._enableTimeouts = false;
|
|
81
|
-
}
|
|
82
71
|
if (typeof ms === 'string') {
|
|
83
72
|
ms = milliseconds(ms);
|
|
84
73
|
}
|
|
74
|
+
|
|
75
|
+
// Clamp to range
|
|
76
|
+
var INT_MAX = Math.pow(2, 31) - 1;
|
|
77
|
+
var range = [0, INT_MAX];
|
|
78
|
+
ms = utils.clamp(ms, range);
|
|
79
|
+
|
|
80
|
+
// see #1652 for reasoning
|
|
81
|
+
if (ms === range[0] || ms === range[1]) {
|
|
82
|
+
this._enableTimeouts = false;
|
|
83
|
+
}
|
|
85
84
|
debug('timeout %d', ms);
|
|
86
85
|
this._timeout = ms;
|
|
87
86
|
if (this.timer) {
|
|
@@ -93,11 +92,11 @@ Runnable.prototype.timeout = function (ms) {
|
|
|
93
92
|
/**
|
|
94
93
|
* Set or get slow `ms`.
|
|
95
94
|
*
|
|
96
|
-
* @
|
|
95
|
+
* @private
|
|
97
96
|
* @param {number|string} ms
|
|
98
97
|
* @return {Runnable|number} ms or Runnable instance.
|
|
99
98
|
*/
|
|
100
|
-
Runnable.prototype.slow = function
|
|
99
|
+
Runnable.prototype.slow = function(ms) {
|
|
101
100
|
if (!arguments.length || typeof ms === 'undefined') {
|
|
102
101
|
return this._slow;
|
|
103
102
|
}
|
|
@@ -112,11 +111,11 @@ Runnable.prototype.slow = function (ms) {
|
|
|
112
111
|
/**
|
|
113
112
|
* Set and get whether timeout is `enabled`.
|
|
114
113
|
*
|
|
115
|
-
* @
|
|
114
|
+
* @private
|
|
116
115
|
* @param {boolean} enabled
|
|
117
116
|
* @return {Runnable|boolean} enabled or Runnable instance.
|
|
118
117
|
*/
|
|
119
|
-
Runnable.prototype.enableTimeouts = function
|
|
118
|
+
Runnable.prototype.enableTimeouts = function(enabled) {
|
|
120
119
|
if (!arguments.length) {
|
|
121
120
|
return this._enableTimeouts;
|
|
122
121
|
}
|
|
@@ -130,18 +129,17 @@ Runnable.prototype.enableTimeouts = function (enabled) {
|
|
|
130
129
|
*
|
|
131
130
|
* @memberof Mocha.Runnable
|
|
132
131
|
* @public
|
|
133
|
-
* @api public
|
|
134
132
|
*/
|
|
135
|
-
Runnable.prototype.skip = function
|
|
133
|
+
Runnable.prototype.skip = function() {
|
|
136
134
|
throw new Pending('sync skip');
|
|
137
135
|
};
|
|
138
136
|
|
|
139
137
|
/**
|
|
140
138
|
* Check if this runnable or its parent suite is marked as pending.
|
|
141
139
|
*
|
|
142
|
-
* @
|
|
140
|
+
* @private
|
|
143
141
|
*/
|
|
144
|
-
Runnable.prototype.isPending = function
|
|
142
|
+
Runnable.prototype.isPending = function() {
|
|
145
143
|
return this.pending || (this.parent && this.parent.isPending());
|
|
146
144
|
};
|
|
147
145
|
|
|
@@ -150,7 +148,7 @@ Runnable.prototype.isPending = function () {
|
|
|
150
148
|
* @return {boolean}
|
|
151
149
|
* @private
|
|
152
150
|
*/
|
|
153
|
-
Runnable.prototype.isFailed = function
|
|
151
|
+
Runnable.prototype.isFailed = function() {
|
|
154
152
|
return !this.isPending() && this.state === 'failed';
|
|
155
153
|
};
|
|
156
154
|
|
|
@@ -159,16 +157,16 @@ Runnable.prototype.isFailed = function () {
|
|
|
159
157
|
* @return {boolean}
|
|
160
158
|
* @private
|
|
161
159
|
*/
|
|
162
|
-
Runnable.prototype.isPassed = function
|
|
160
|
+
Runnable.prototype.isPassed = function() {
|
|
163
161
|
return !this.isPending() && this.state === 'passed';
|
|
164
162
|
};
|
|
165
163
|
|
|
166
164
|
/**
|
|
167
165
|
* Set or get number of retries.
|
|
168
166
|
*
|
|
169
|
-
* @
|
|
167
|
+
* @private
|
|
170
168
|
*/
|
|
171
|
-
Runnable.prototype.retries = function
|
|
169
|
+
Runnable.prototype.retries = function(n) {
|
|
172
170
|
if (!arguments.length) {
|
|
173
171
|
return this._retries;
|
|
174
172
|
}
|
|
@@ -178,9 +176,9 @@ Runnable.prototype.retries = function (n) {
|
|
|
178
176
|
/**
|
|
179
177
|
* Set or get current retry
|
|
180
178
|
*
|
|
181
|
-
* @
|
|
179
|
+
* @private
|
|
182
180
|
*/
|
|
183
|
-
Runnable.prototype.currentRetry = function
|
|
181
|
+
Runnable.prototype.currentRetry = function(n) {
|
|
184
182
|
if (!arguments.length) {
|
|
185
183
|
return this._currentRetry;
|
|
186
184
|
}
|
|
@@ -193,10 +191,9 @@ Runnable.prototype.currentRetry = function (n) {
|
|
|
193
191
|
*
|
|
194
192
|
* @memberof Mocha.Runnable
|
|
195
193
|
* @public
|
|
196
|
-
* @api public
|
|
197
194
|
* @return {string}
|
|
198
195
|
*/
|
|
199
|
-
Runnable.prototype.fullTitle = function
|
|
196
|
+
Runnable.prototype.fullTitle = function() {
|
|
200
197
|
return this.titlePath().join(' ');
|
|
201
198
|
};
|
|
202
199
|
|
|
@@ -205,49 +202,52 @@ Runnable.prototype.fullTitle = function () {
|
|
|
205
202
|
*
|
|
206
203
|
* @memberof Mocha.Runnable
|
|
207
204
|
* @public
|
|
208
|
-
* @api public
|
|
209
205
|
* @return {string}
|
|
210
206
|
*/
|
|
211
|
-
Runnable.prototype.titlePath = function
|
|
207
|
+
Runnable.prototype.titlePath = function() {
|
|
212
208
|
return this.parent.titlePath().concat([this.title]);
|
|
213
209
|
};
|
|
214
210
|
|
|
215
211
|
/**
|
|
216
212
|
* Clear the timeout.
|
|
217
213
|
*
|
|
218
|
-
* @
|
|
214
|
+
* @private
|
|
219
215
|
*/
|
|
220
|
-
Runnable.prototype.clearTimeout = function
|
|
216
|
+
Runnable.prototype.clearTimeout = function() {
|
|
221
217
|
clearTimeout(this.timer);
|
|
222
218
|
};
|
|
223
219
|
|
|
224
220
|
/**
|
|
225
221
|
* Inspect the runnable void of private properties.
|
|
226
222
|
*
|
|
227
|
-
* @
|
|
223
|
+
* @private
|
|
228
224
|
* @return {string}
|
|
229
225
|
*/
|
|
230
|
-
Runnable.prototype.inspect = function
|
|
231
|
-
return JSON.stringify(
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
226
|
+
Runnable.prototype.inspect = function() {
|
|
227
|
+
return JSON.stringify(
|
|
228
|
+
this,
|
|
229
|
+
function(key, val) {
|
|
230
|
+
if (key[0] === '_') {
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
if (key === 'parent') {
|
|
234
|
+
return '#<Suite>';
|
|
235
|
+
}
|
|
236
|
+
if (key === 'ctx') {
|
|
237
|
+
return '#<Context>';
|
|
238
|
+
}
|
|
239
|
+
return val;
|
|
240
|
+
},
|
|
241
|
+
2
|
|
242
|
+
);
|
|
243
243
|
};
|
|
244
244
|
|
|
245
245
|
/**
|
|
246
246
|
* Reset the timeout.
|
|
247
247
|
*
|
|
248
|
-
* @
|
|
248
|
+
* @private
|
|
249
249
|
*/
|
|
250
|
-
Runnable.prototype.resetTimeout = function
|
|
250
|
+
Runnable.prototype.resetTimeout = function() {
|
|
251
251
|
var self = this;
|
|
252
252
|
var ms = this.timeout() || 1e9;
|
|
253
253
|
|
|
@@ -255,7 +255,7 @@ Runnable.prototype.resetTimeout = function () {
|
|
|
255
255
|
return;
|
|
256
256
|
}
|
|
257
257
|
this.clearTimeout();
|
|
258
|
-
this.timer = setTimeout(function
|
|
258
|
+
this.timer = setTimeout(function() {
|
|
259
259
|
if (!self._enableTimeouts) {
|
|
260
260
|
return;
|
|
261
261
|
}
|
|
@@ -267,10 +267,10 @@ Runnable.prototype.resetTimeout = function () {
|
|
|
267
267
|
/**
|
|
268
268
|
* Set or get a list of whitelisted globals for this test run.
|
|
269
269
|
*
|
|
270
|
-
* @
|
|
270
|
+
* @private
|
|
271
271
|
* @param {string[]} globals
|
|
272
272
|
*/
|
|
273
|
-
Runnable.prototype.globals = function
|
|
273
|
+
Runnable.prototype.globals = function(globals) {
|
|
274
274
|
if (!arguments.length) {
|
|
275
275
|
return this._allowedGlobals;
|
|
276
276
|
}
|
|
@@ -281,9 +281,9 @@ Runnable.prototype.globals = function (globals) {
|
|
|
281
281
|
* Run the test and invoke `fn(err)`.
|
|
282
282
|
*
|
|
283
283
|
* @param {Function} fn
|
|
284
|
-
* @
|
|
284
|
+
* @private
|
|
285
285
|
*/
|
|
286
|
-
Runnable.prototype.run = function
|
|
286
|
+
Runnable.prototype.run = function(fn) {
|
|
287
287
|
var self = this;
|
|
288
288
|
var start = new Date();
|
|
289
289
|
var ctx = this.ctx;
|
|
@@ -296,7 +296,7 @@ Runnable.prototype.run = function (fn) {
|
|
|
296
296
|
}
|
|
297
297
|
|
|
298
298
|
// called multiple times
|
|
299
|
-
function multiple
|
|
299
|
+
function multiple(err) {
|
|
300
300
|
if (emitted) {
|
|
301
301
|
return;
|
|
302
302
|
}
|
|
@@ -311,7 +311,7 @@ Runnable.prototype.run = function (fn) {
|
|
|
311
311
|
}
|
|
312
312
|
|
|
313
313
|
// finished
|
|
314
|
-
function done
|
|
314
|
+
function done(err) {
|
|
315
315
|
var ms = self.timeout();
|
|
316
316
|
if (self.timedOut) {
|
|
317
317
|
return;
|
|
@@ -338,7 +338,7 @@ Runnable.prototype.run = function (fn) {
|
|
|
338
338
|
this.resetTimeout();
|
|
339
339
|
|
|
340
340
|
// allows skip() to be used in an explicit async context
|
|
341
|
-
this.skip = function asyncSkip
|
|
341
|
+
this.skip = function asyncSkip() {
|
|
342
342
|
done(new Pending('async skip call'));
|
|
343
343
|
// halt execution. the Runnable will be marked pending
|
|
344
344
|
// by the previous call, and the uncaught handler will ignore
|
|
@@ -379,43 +379,53 @@ Runnable.prototype.run = function (fn) {
|
|
|
379
379
|
done(utils.getError(err));
|
|
380
380
|
}
|
|
381
381
|
|
|
382
|
-
function callFn
|
|
382
|
+
function callFn(fn) {
|
|
383
383
|
var result = fn.call(ctx);
|
|
384
384
|
if (result && typeof result.then === 'function') {
|
|
385
385
|
self.resetTimeout();
|
|
386
|
-
result
|
|
387
|
-
|
|
386
|
+
result.then(
|
|
387
|
+
function() {
|
|
388
388
|
done();
|
|
389
389
|
// Return null so libraries like bluebird do not warn about
|
|
390
390
|
// subsequently constructed Promises.
|
|
391
391
|
return null;
|
|
392
392
|
},
|
|
393
|
-
function
|
|
393
|
+
function(reason) {
|
|
394
394
|
done(reason || new Error('Promise rejected with no or falsy reason'));
|
|
395
|
-
}
|
|
395
|
+
}
|
|
396
|
+
);
|
|
396
397
|
} else {
|
|
397
398
|
if (self.asyncOnly) {
|
|
398
|
-
return done(
|
|
399
|
+
return done(
|
|
400
|
+
new Error(
|
|
401
|
+
'--async-only option in use without declaring `done()` or returning a promise'
|
|
402
|
+
)
|
|
403
|
+
);
|
|
399
404
|
}
|
|
400
405
|
|
|
401
406
|
done();
|
|
402
407
|
}
|
|
403
408
|
}
|
|
404
409
|
|
|
405
|
-
function callFnAsync
|
|
406
|
-
var result = fn.call(ctx, function
|
|
410
|
+
function callFnAsync(fn) {
|
|
411
|
+
var result = fn.call(ctx, function(err) {
|
|
407
412
|
if (err instanceof Error || toString.call(err) === '[object Error]') {
|
|
408
413
|
return done(err);
|
|
409
414
|
}
|
|
410
415
|
if (err) {
|
|
411
416
|
if (Object.prototype.toString.call(err) === '[object Object]') {
|
|
412
|
-
return done(
|
|
413
|
-
JSON.stringify(err))
|
|
417
|
+
return done(
|
|
418
|
+
new Error('done() invoked with non-Error: ' + JSON.stringify(err))
|
|
419
|
+
);
|
|
414
420
|
}
|
|
415
421
|
return done(new Error('done() invoked with non-Error: ' + err));
|
|
416
422
|
}
|
|
417
423
|
if (result && utils.isPromise(result)) {
|
|
418
|
-
return done(
|
|
424
|
+
return done(
|
|
425
|
+
new Error(
|
|
426
|
+
'Resolution method is overspecified. Specify a callback *or* return a Promise; not both.'
|
|
427
|
+
)
|
|
428
|
+
);
|
|
419
429
|
}
|
|
420
430
|
|
|
421
431
|
done();
|
|
@@ -430,8 +440,11 @@ Runnable.prototype.run = function (fn) {
|
|
|
430
440
|
* @returns {Error} a "timeout" error
|
|
431
441
|
* @private
|
|
432
442
|
*/
|
|
433
|
-
Runnable.prototype._timeoutError = function
|
|
434
|
-
var msg =
|
|
443
|
+
Runnable.prototype._timeoutError = function(ms) {
|
|
444
|
+
var msg =
|
|
445
|
+
'Timeout of ' +
|
|
446
|
+
ms +
|
|
447
|
+
'ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.';
|
|
435
448
|
if (this.file) {
|
|
436
449
|
msg += ' (' + this.file + ')';
|
|
437
450
|
}
|