mocha 7.1.1 → 8.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 +110 -2
- package/bin/mocha +24 -4
- package/browser-entry.js +11 -0
- package/lib/browser/growl.js +2 -1
- package/lib/cli/cli.js +6 -3
- package/lib/cli/collect-files.js +14 -8
- package/lib/cli/config.js +6 -6
- package/lib/cli/init.js +1 -2
- package/lib/cli/node-flags.js +2 -2
- package/lib/cli/options.js +14 -90
- package/lib/cli/run-helpers.js +133 -36
- package/lib/cli/run-option-metadata.js +4 -2
- package/lib/cli/run.js +71 -11
- package/lib/cli/watch-run.js +202 -50
- package/lib/context.js +0 -15
- package/lib/errors.js +202 -9
- package/lib/esm-utils.js +11 -6
- package/lib/hook.js +32 -0
- package/lib/interfaces/common.js +16 -10
- package/lib/mocha.js +289 -123
- package/lib/mocharc.json +0 -1
- package/lib/nodejs/buffered-worker-pool.js +174 -0
- package/lib/{growl.js → nodejs/growl.js} +3 -2
- package/lib/nodejs/parallel-buffered-runner.js +293 -0
- package/lib/nodejs/reporters/parallel-buffered.js +133 -0
- package/lib/nodejs/serializer.js +402 -0
- package/lib/nodejs/worker.js +154 -0
- package/lib/reporters/base.js +2 -2
- package/lib/reporters/doc.js +6 -0
- package/lib/reporters/json-stream.js +1 -0
- package/lib/reporters/json.js +1 -0
- package/lib/reporters/landing.js +11 -3
- package/lib/reporters/tap.js +1 -2
- package/lib/reporters/xunit.js +3 -2
- package/lib/runnable.js +38 -72
- package/lib/runner.js +185 -85
- package/lib/suite.js +60 -27
- package/lib/test.js +48 -3
- package/lib/utils.js +32 -40
- package/mocha.js +2418 -2199
- package/package.json +71 -56
package/lib/runnable.js
CHANGED
|
@@ -5,8 +5,9 @@ var Pending = require('./pending');
|
|
|
5
5
|
var debug = require('debug')('mocha:runnable');
|
|
6
6
|
var milliseconds = require('ms');
|
|
7
7
|
var utils = require('./utils');
|
|
8
|
-
var
|
|
9
|
-
|
|
8
|
+
var errors = require('./errors');
|
|
9
|
+
var createInvalidExceptionError = errors.createInvalidExceptionError;
|
|
10
|
+
var createMultipleDoneError = errors.createMultipleDoneError;
|
|
10
11
|
|
|
11
12
|
/**
|
|
12
13
|
* Save timer references to avoid Sinon interfering (see GH-237).
|
|
@@ -35,11 +36,8 @@ function Runnable(title, fn) {
|
|
|
35
36
|
this.sync = !this.async;
|
|
36
37
|
this._timeout = 2000;
|
|
37
38
|
this._slow = 75;
|
|
38
|
-
this._enableTimeouts = true;
|
|
39
|
-
this.timedOut = false;
|
|
40
39
|
this._retries = -1;
|
|
41
|
-
this.
|
|
42
|
-
this.pending = false;
|
|
40
|
+
this.reset();
|
|
43
41
|
}
|
|
44
42
|
|
|
45
43
|
/**
|
|
@@ -47,6 +45,17 @@ function Runnable(title, fn) {
|
|
|
47
45
|
*/
|
|
48
46
|
utils.inherits(Runnable, EventEmitter);
|
|
49
47
|
|
|
48
|
+
/**
|
|
49
|
+
* Resets the state initially or for a next run.
|
|
50
|
+
*/
|
|
51
|
+
Runnable.prototype.reset = function() {
|
|
52
|
+
this.timedOut = false;
|
|
53
|
+
this._currentRetry = 0;
|
|
54
|
+
this.pending = false;
|
|
55
|
+
delete this.state;
|
|
56
|
+
delete this.err;
|
|
57
|
+
};
|
|
58
|
+
|
|
50
59
|
/**
|
|
51
60
|
* Get current timeout value in msecs.
|
|
52
61
|
*
|
|
@@ -83,10 +92,12 @@ Runnable.prototype.timeout = function(ms) {
|
|
|
83
92
|
|
|
84
93
|
// see #1652 for reasoning
|
|
85
94
|
if (ms === range[0] || ms === range[1]) {
|
|
86
|
-
this.
|
|
95
|
+
this._timeout = 0;
|
|
96
|
+
} else {
|
|
97
|
+
this._timeout = ms;
|
|
87
98
|
}
|
|
88
|
-
debug('timeout %d',
|
|
89
|
-
|
|
99
|
+
debug('timeout %d', this._timeout);
|
|
100
|
+
|
|
90
101
|
if (this.timer) {
|
|
91
102
|
this.resetTimeout();
|
|
92
103
|
}
|
|
@@ -112,22 +123,6 @@ Runnable.prototype.slow = function(ms) {
|
|
|
112
123
|
return this;
|
|
113
124
|
};
|
|
114
125
|
|
|
115
|
-
/**
|
|
116
|
-
* Set and get whether timeout is `enabled`.
|
|
117
|
-
*
|
|
118
|
-
* @private
|
|
119
|
-
* @param {boolean} enabled
|
|
120
|
-
* @return {Runnable|boolean} enabled or Runnable instance.
|
|
121
|
-
*/
|
|
122
|
-
Runnable.prototype.enableTimeouts = function(enabled) {
|
|
123
|
-
if (!arguments.length) {
|
|
124
|
-
return this._enableTimeouts;
|
|
125
|
-
}
|
|
126
|
-
debug('enableTimeouts %s', enabled);
|
|
127
|
-
this._enableTimeouts = enabled;
|
|
128
|
-
return this;
|
|
129
|
-
};
|
|
130
|
-
|
|
131
126
|
/**
|
|
132
127
|
* Halt and mark as pending.
|
|
133
128
|
*
|
|
@@ -222,31 +217,6 @@ Runnable.prototype.clearTimeout = function() {
|
|
|
222
217
|
clearTimeout(this.timer);
|
|
223
218
|
};
|
|
224
219
|
|
|
225
|
-
/**
|
|
226
|
-
* Inspect the runnable void of private properties.
|
|
227
|
-
*
|
|
228
|
-
* @private
|
|
229
|
-
* @return {string}
|
|
230
|
-
*/
|
|
231
|
-
Runnable.prototype.inspect = function() {
|
|
232
|
-
return JSON.stringify(
|
|
233
|
-
this,
|
|
234
|
-
function(key, val) {
|
|
235
|
-
if (key[0] === '_') {
|
|
236
|
-
return;
|
|
237
|
-
}
|
|
238
|
-
if (key === 'parent') {
|
|
239
|
-
return '#<Suite>';
|
|
240
|
-
}
|
|
241
|
-
if (key === 'ctx') {
|
|
242
|
-
return '#<Context>';
|
|
243
|
-
}
|
|
244
|
-
return val;
|
|
245
|
-
},
|
|
246
|
-
2
|
|
247
|
-
);
|
|
248
|
-
};
|
|
249
|
-
|
|
250
220
|
/**
|
|
251
221
|
* Reset the timeout.
|
|
252
222
|
*
|
|
@@ -254,14 +224,14 @@ Runnable.prototype.inspect = function() {
|
|
|
254
224
|
*/
|
|
255
225
|
Runnable.prototype.resetTimeout = function() {
|
|
256
226
|
var self = this;
|
|
257
|
-
var ms = this.timeout()
|
|
227
|
+
var ms = this.timeout();
|
|
258
228
|
|
|
259
|
-
if (
|
|
229
|
+
if (ms === 0) {
|
|
260
230
|
return;
|
|
261
231
|
}
|
|
262
232
|
this.clearTimeout();
|
|
263
233
|
this.timer = setTimeout(function() {
|
|
264
|
-
if (
|
|
234
|
+
if (self.timeout() === 0) {
|
|
265
235
|
return;
|
|
266
236
|
}
|
|
267
237
|
self.callback(self._timeoutError(ms));
|
|
@@ -293,7 +263,9 @@ Runnable.prototype.run = function(fn) {
|
|
|
293
263
|
var start = new Date();
|
|
294
264
|
var ctx = this.ctx;
|
|
295
265
|
var finished;
|
|
296
|
-
var
|
|
266
|
+
var errorWasHandled = false;
|
|
267
|
+
|
|
268
|
+
if (this.isPending()) return fn();
|
|
297
269
|
|
|
298
270
|
// Sometimes the ctx exists, but it is not runnable
|
|
299
271
|
if (ctx && ctx.runnable) {
|
|
@@ -302,17 +274,11 @@ Runnable.prototype.run = function(fn) {
|
|
|
302
274
|
|
|
303
275
|
// called multiple times
|
|
304
276
|
function multiple(err) {
|
|
305
|
-
if (
|
|
277
|
+
if (errorWasHandled) {
|
|
306
278
|
return;
|
|
307
279
|
}
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
if (err && err.message) {
|
|
311
|
-
err.message += " (and Mocha's " + msg + ')';
|
|
312
|
-
self.emit('error', err);
|
|
313
|
-
} else {
|
|
314
|
-
self.emit('error', new Error(msg));
|
|
315
|
-
}
|
|
280
|
+
errorWasHandled = true;
|
|
281
|
+
self.emit('error', createMultipleDoneError(self, err));
|
|
316
282
|
}
|
|
317
283
|
|
|
318
284
|
// finished
|
|
@@ -329,7 +295,7 @@ Runnable.prototype.run = function(fn) {
|
|
|
329
295
|
self.clearTimeout();
|
|
330
296
|
self.duration = new Date() - start;
|
|
331
297
|
finished = true;
|
|
332
|
-
if (!err && self.duration > ms &&
|
|
298
|
+
if (!err && self.duration > ms && ms > 0) {
|
|
333
299
|
err = self._timeoutError(ms);
|
|
334
300
|
}
|
|
335
301
|
fn(err);
|
|
@@ -363,7 +329,7 @@ Runnable.prototype.run = function(fn) {
|
|
|
363
329
|
callFnAsync(this.fn);
|
|
364
330
|
} catch (err) {
|
|
365
331
|
// handles async runnables which actually run synchronously
|
|
366
|
-
|
|
332
|
+
errorWasHandled = true;
|
|
367
333
|
if (err instanceof Pending) {
|
|
368
334
|
return; // done() is already called in this.skip()
|
|
369
335
|
} else if (this.allowUncaught) {
|
|
@@ -376,13 +342,9 @@ Runnable.prototype.run = function(fn) {
|
|
|
376
342
|
|
|
377
343
|
// sync or promise-returning
|
|
378
344
|
try {
|
|
379
|
-
|
|
380
|
-
done();
|
|
381
|
-
} else {
|
|
382
|
-
callFn(this.fn);
|
|
383
|
-
}
|
|
345
|
+
callFn(this.fn);
|
|
384
346
|
} catch (err) {
|
|
385
|
-
|
|
347
|
+
errorWasHandled = true;
|
|
386
348
|
if (err instanceof Pending) {
|
|
387
349
|
return done();
|
|
388
350
|
} else if (this.allowUncaught) {
|
|
@@ -481,7 +443,11 @@ var constants = utils.defineConstants(
|
|
|
481
443
|
/**
|
|
482
444
|
* Value of `state` prop when a `Runnable` has passed
|
|
483
445
|
*/
|
|
484
|
-
STATE_PASSED: 'passed'
|
|
446
|
+
STATE_PASSED: 'passed',
|
|
447
|
+
/**
|
|
448
|
+
* Value of `state` prop when a `Runnable` has been skipped by user
|
|
449
|
+
*/
|
|
450
|
+
STATE_PENDING: 'pending'
|
|
485
451
|
}
|
|
486
452
|
);
|
|
487
453
|
|