mocha 7.1.2 → 8.1.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/CHANGELOG.md +143 -2
- package/bin/mocha +24 -4
- package/browser-entry.js +37 -9
- package/lib/browser/growl.js +2 -1
- package/lib/browser/highlight-tags.js +39 -0
- package/lib/browser/parse-query.js +24 -0
- package/lib/browser/progress.js +4 -0
- package/lib/browser/template.html +7 -5
- package/lib/cli/cli.js +6 -3
- package/lib/cli/collect-files.js +17 -10
- package/lib/cli/config.js +6 -6
- package/lib/cli/init.js +1 -2
- package/lib/cli/lookup-files.js +145 -0
- 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 +211 -51
- 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 +21 -10
- package/lib/mocha.js +301 -126
- 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 +295 -0
- package/lib/nodejs/reporters/parallel-buffered.js +133 -0
- package/lib/nodejs/serializer.js +404 -0
- package/lib/nodejs/worker.js +154 -0
- package/lib/pending.js +4 -0
- package/lib/reporters/base.js +25 -12
- 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 +39 -47
- package/lib/runner.js +219 -118
- package/lib/suite.js +61 -27
- package/lib/test.js +48 -3
- package/lib/utils.js +33 -209
- package/mocha.js +25522 -17715
- package/mocha.js.map +1 -0
- package/package.json +87 -68
- package/lib/browser/tty.js +0 -13
package/lib/reporters/landing.js
CHANGED
|
@@ -56,11 +56,12 @@ function Landing(runner, options) {
|
|
|
56
56
|
|
|
57
57
|
var self = this;
|
|
58
58
|
var width = (Base.window.width * 0.75) | 0;
|
|
59
|
-
var total = runner.total;
|
|
60
59
|
var stream = process.stdout;
|
|
60
|
+
|
|
61
61
|
var plane = color('plane', '✈');
|
|
62
62
|
var crashed = -1;
|
|
63
63
|
var n = 0;
|
|
64
|
+
var total = 0;
|
|
64
65
|
|
|
65
66
|
function runway() {
|
|
66
67
|
var buf = Array(width).join('-');
|
|
@@ -74,8 +75,7 @@ function Landing(runner, options) {
|
|
|
74
75
|
|
|
75
76
|
runner.on(EVENT_TEST_END, function(test) {
|
|
76
77
|
// check if the plane crashed
|
|
77
|
-
var col = crashed === -1 ? ((width * ++n) / total) | 0 : crashed;
|
|
78
|
-
|
|
78
|
+
var col = crashed === -1 ? ((width * ++n) / ++total) | 0 : crashed;
|
|
79
79
|
// show the crash
|
|
80
80
|
if (test.state === STATE_FAILED) {
|
|
81
81
|
plane = color('plane crash', '✈');
|
|
@@ -98,6 +98,14 @@ function Landing(runner, options) {
|
|
|
98
98
|
process.stdout.write('\n');
|
|
99
99
|
self.epilogue();
|
|
100
100
|
});
|
|
101
|
+
|
|
102
|
+
// if cursor is hidden when we ctrl-C, then it will remain hidden unless...
|
|
103
|
+
process.once('SIGINT', function() {
|
|
104
|
+
cursor.show();
|
|
105
|
+
process.nextTick(function() {
|
|
106
|
+
process.kill(process.pid, 'SIGINT');
|
|
107
|
+
});
|
|
108
|
+
});
|
|
101
109
|
}
|
|
102
110
|
|
|
103
111
|
/**
|
package/lib/reporters/tap.js
CHANGED
|
@@ -50,9 +50,7 @@ function TAP(runner, options) {
|
|
|
50
50
|
this._producer = createProducer(tapVersion);
|
|
51
51
|
|
|
52
52
|
runner.once(EVENT_RUN_BEGIN, function() {
|
|
53
|
-
var ntests = runner.grepTotal(runner.suite);
|
|
54
53
|
self._producer.writeVersion();
|
|
55
|
-
self._producer.writePlan(ntests);
|
|
56
54
|
});
|
|
57
55
|
|
|
58
56
|
runner.on(EVENT_TEST_END, function() {
|
|
@@ -204,6 +202,7 @@ TAPProducer.prototype.writeEpilogue = function(stats) {
|
|
|
204
202
|
println('# pass ' + stats.passes);
|
|
205
203
|
// :TBD: Why are we not showing pending results?
|
|
206
204
|
println('# fail ' + stats.failures);
|
|
205
|
+
this.writePlan(stats.passes + stats.failures + stats.pending);
|
|
207
206
|
};
|
|
208
207
|
|
|
209
208
|
/**
|
package/lib/reporters/xunit.js
CHANGED
|
@@ -9,7 +9,6 @@
|
|
|
9
9
|
var Base = require('./base');
|
|
10
10
|
var utils = require('../utils');
|
|
11
11
|
var fs = require('fs');
|
|
12
|
-
var mkdirp = require('mkdirp');
|
|
13
12
|
var path = require('path');
|
|
14
13
|
var errors = require('../errors');
|
|
15
14
|
var createUnsupportedError = errors.createUnsupportedError;
|
|
@@ -62,7 +61,9 @@ function XUnit(runner, options) {
|
|
|
62
61
|
throw createUnsupportedError('file output not supported in browser');
|
|
63
62
|
}
|
|
64
63
|
|
|
65
|
-
|
|
64
|
+
fs.mkdirSync(path.dirname(options.reporterOptions.output), {
|
|
65
|
+
recursive: true
|
|
66
|
+
});
|
|
66
67
|
self.fileStream = fs.createWriteStream(options.reporterOptions.output);
|
|
67
68
|
}
|
|
68
69
|
|
package/lib/runnable.js
CHANGED
|
@@ -5,11 +5,13 @@ 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).
|
|
14
|
+
* @private
|
|
13
15
|
*/
|
|
14
16
|
var Date = global.Date;
|
|
15
17
|
var setTimeout = global.setTimeout;
|
|
@@ -35,11 +37,8 @@ function Runnable(title, fn) {
|
|
|
35
37
|
this.sync = !this.async;
|
|
36
38
|
this._timeout = 2000;
|
|
37
39
|
this._slow = 75;
|
|
38
|
-
this._enableTimeouts = true;
|
|
39
|
-
this.timedOut = false;
|
|
40
40
|
this._retries = -1;
|
|
41
|
-
this.
|
|
42
|
-
this.pending = false;
|
|
41
|
+
this.reset();
|
|
43
42
|
}
|
|
44
43
|
|
|
45
44
|
/**
|
|
@@ -47,6 +46,17 @@ function Runnable(title, fn) {
|
|
|
47
46
|
*/
|
|
48
47
|
utils.inherits(Runnable, EventEmitter);
|
|
49
48
|
|
|
49
|
+
/**
|
|
50
|
+
* Resets the state initially or for a next run.
|
|
51
|
+
*/
|
|
52
|
+
Runnable.prototype.reset = function() {
|
|
53
|
+
this.timedOut = false;
|
|
54
|
+
this._currentRetry = 0;
|
|
55
|
+
this.pending = false;
|
|
56
|
+
delete this.state;
|
|
57
|
+
delete this.err;
|
|
58
|
+
};
|
|
59
|
+
|
|
50
60
|
/**
|
|
51
61
|
* Get current timeout value in msecs.
|
|
52
62
|
*
|
|
@@ -83,10 +93,12 @@ Runnable.prototype.timeout = function(ms) {
|
|
|
83
93
|
|
|
84
94
|
// see #1652 for reasoning
|
|
85
95
|
if (ms === range[0] || ms === range[1]) {
|
|
86
|
-
this.
|
|
96
|
+
this._timeout = 0;
|
|
97
|
+
} else {
|
|
98
|
+
this._timeout = ms;
|
|
87
99
|
}
|
|
88
|
-
debug('timeout %d',
|
|
89
|
-
|
|
100
|
+
debug('timeout %d', this._timeout);
|
|
101
|
+
|
|
90
102
|
if (this.timer) {
|
|
91
103
|
this.resetTimeout();
|
|
92
104
|
}
|
|
@@ -112,22 +124,6 @@ Runnable.prototype.slow = function(ms) {
|
|
|
112
124
|
return this;
|
|
113
125
|
};
|
|
114
126
|
|
|
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
127
|
/**
|
|
132
128
|
* Halt and mark as pending.
|
|
133
129
|
*
|
|
@@ -229,14 +225,14 @@ Runnable.prototype.clearTimeout = function() {
|
|
|
229
225
|
*/
|
|
230
226
|
Runnable.prototype.resetTimeout = function() {
|
|
231
227
|
var self = this;
|
|
232
|
-
var ms = this.timeout()
|
|
228
|
+
var ms = this.timeout();
|
|
233
229
|
|
|
234
|
-
if (
|
|
230
|
+
if (ms === 0) {
|
|
235
231
|
return;
|
|
236
232
|
}
|
|
237
233
|
this.clearTimeout();
|
|
238
234
|
this.timer = setTimeout(function() {
|
|
239
|
-
if (
|
|
235
|
+
if (self.timeout() === 0) {
|
|
240
236
|
return;
|
|
241
237
|
}
|
|
242
238
|
self.callback(self._timeoutError(ms));
|
|
@@ -268,7 +264,9 @@ Runnable.prototype.run = function(fn) {
|
|
|
268
264
|
var start = new Date();
|
|
269
265
|
var ctx = this.ctx;
|
|
270
266
|
var finished;
|
|
271
|
-
var
|
|
267
|
+
var errorWasHandled = false;
|
|
268
|
+
|
|
269
|
+
if (this.isPending()) return fn();
|
|
272
270
|
|
|
273
271
|
// Sometimes the ctx exists, but it is not runnable
|
|
274
272
|
if (ctx && ctx.runnable) {
|
|
@@ -277,17 +275,11 @@ Runnable.prototype.run = function(fn) {
|
|
|
277
275
|
|
|
278
276
|
// called multiple times
|
|
279
277
|
function multiple(err) {
|
|
280
|
-
if (
|
|
278
|
+
if (errorWasHandled) {
|
|
281
279
|
return;
|
|
282
280
|
}
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
if (err && err.message) {
|
|
286
|
-
err.message += " (and Mocha's " + msg + ')';
|
|
287
|
-
self.emit('error', err);
|
|
288
|
-
} else {
|
|
289
|
-
self.emit('error', new Error(msg));
|
|
290
|
-
}
|
|
281
|
+
errorWasHandled = true;
|
|
282
|
+
self.emit('error', createMultipleDoneError(self, err));
|
|
291
283
|
}
|
|
292
284
|
|
|
293
285
|
// finished
|
|
@@ -304,7 +296,7 @@ Runnable.prototype.run = function(fn) {
|
|
|
304
296
|
self.clearTimeout();
|
|
305
297
|
self.duration = new Date() - start;
|
|
306
298
|
finished = true;
|
|
307
|
-
if (!err && self.duration > ms &&
|
|
299
|
+
if (!err && self.duration > ms && ms > 0) {
|
|
308
300
|
err = self._timeoutError(ms);
|
|
309
301
|
}
|
|
310
302
|
fn(err);
|
|
@@ -338,7 +330,7 @@ Runnable.prototype.run = function(fn) {
|
|
|
338
330
|
callFnAsync(this.fn);
|
|
339
331
|
} catch (err) {
|
|
340
332
|
// handles async runnables which actually run synchronously
|
|
341
|
-
|
|
333
|
+
errorWasHandled = true;
|
|
342
334
|
if (err instanceof Pending) {
|
|
343
335
|
return; // done() is already called in this.skip()
|
|
344
336
|
} else if (this.allowUncaught) {
|
|
@@ -351,13 +343,9 @@ Runnable.prototype.run = function(fn) {
|
|
|
351
343
|
|
|
352
344
|
// sync or promise-returning
|
|
353
345
|
try {
|
|
354
|
-
|
|
355
|
-
done();
|
|
356
|
-
} else {
|
|
357
|
-
callFn(this.fn);
|
|
358
|
-
}
|
|
346
|
+
callFn(this.fn);
|
|
359
347
|
} catch (err) {
|
|
360
|
-
|
|
348
|
+
errorWasHandled = true;
|
|
361
349
|
if (err instanceof Pending) {
|
|
362
350
|
return done();
|
|
363
351
|
} else if (this.allowUncaught) {
|
|
@@ -456,7 +444,11 @@ var constants = utils.defineConstants(
|
|
|
456
444
|
/**
|
|
457
445
|
* Value of `state` prop when a `Runnable` has passed
|
|
458
446
|
*/
|
|
459
|
-
STATE_PASSED: 'passed'
|
|
447
|
+
STATE_PASSED: 'passed',
|
|
448
|
+
/**
|
|
449
|
+
* Value of `state` prop when a `Runnable` has been skipped by user
|
|
450
|
+
*/
|
|
451
|
+
STATE_PENDING: 'pending'
|
|
460
452
|
}
|
|
461
453
|
);
|
|
462
454
|
|