mocha 4.0.0 → 5.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 +1022 -971
- package/CHANGELOG.md.orig +1736 -0
- package/LICENSE +1 -1
- package/README.md +81 -85
- package/README.md.orig +132 -0
- package/bin/.eslintrc.yml +3 -0
- package/bin/_mocha +169 -153
- package/bin/mocha +12 -10
- package/bin/options.js +8 -6
- package/lib/browser/{.eslintrc.yaml → .eslintrc.yml} +0 -0
- package/lib/context.js +9 -15
- package/lib/interfaces/bdd.js +1 -1
- package/lib/mocha.js +23 -0
- package/lib/ms.js +4 -44
- package/lib/reporters/base.js +24 -40
- package/lib/reporters/base.js.orig +498 -0
- package/lib/reporters/progress.js +7 -5
- package/lib/runnable.js +14 -8
- package/lib/runner.js +4 -5
- package/lib/suite.js +5 -5
- package/lib/utils.js +1 -1
- package/mocha.js +7280 -7389
- package/package.json +16 -15
package/lib/mocha.js
CHANGED
|
@@ -389,6 +389,20 @@ Mocha.prototype.useInlineDiffs = function (inlineDiffs) {
|
|
|
389
389
|
return this;
|
|
390
390
|
};
|
|
391
391
|
|
|
392
|
+
/**
|
|
393
|
+
* Do not show diffs at all.
|
|
394
|
+
*
|
|
395
|
+
* @param {Boolean} hideDiff
|
|
396
|
+
* @return {Mocha}
|
|
397
|
+
* @api public
|
|
398
|
+
* @param {boolean} hideDiff
|
|
399
|
+
* @return {Mocha}
|
|
400
|
+
*/
|
|
401
|
+
Mocha.prototype.hideDiff = function (hideDiff) {
|
|
402
|
+
this.options.hideDiff = hideDiff !== undefined && hideDiff;
|
|
403
|
+
return this;
|
|
404
|
+
};
|
|
405
|
+
|
|
392
406
|
/**
|
|
393
407
|
* Set the timeout in milliseconds.
|
|
394
408
|
*
|
|
@@ -505,6 +519,14 @@ Mocha.prototype.forbidPending = function () {
|
|
|
505
519
|
/**
|
|
506
520
|
* Run tests and invoke `fn()` when complete.
|
|
507
521
|
*
|
|
522
|
+
* Note that `loadFiles` relies on Node's `require` to execute
|
|
523
|
+
* the test interface functions and will be subject to the
|
|
524
|
+
* cache - if the files are already in the `require` cache,
|
|
525
|
+
* they will effectively be skipped. Therefore, to run tests
|
|
526
|
+
* multiple times or to run tests in files that are already
|
|
527
|
+
* in the `require` cache, make sure to clear them from the
|
|
528
|
+
* cache first in whichever manner best suits your needs.
|
|
529
|
+
*
|
|
508
530
|
* @api public
|
|
509
531
|
* @param {Function} fn
|
|
510
532
|
* @return {Runner}
|
|
@@ -537,6 +559,7 @@ Mocha.prototype.run = function (fn) {
|
|
|
537
559
|
exports.reporters.Base.useColors = options.useColors;
|
|
538
560
|
}
|
|
539
561
|
exports.reporters.Base.inlineDiffs = options.useInlineDiffs;
|
|
562
|
+
exports.reporters.Base.hideDiff = options.hideDiff;
|
|
540
563
|
|
|
541
564
|
function done (failures) {
|
|
542
565
|
if (reporter.done) {
|
package/lib/ms.js
CHANGED
|
@@ -13,22 +13,15 @@ var y = d * 365.25;
|
|
|
13
13
|
/**
|
|
14
14
|
* Parse or format the given `val`.
|
|
15
15
|
*
|
|
16
|
-
* Options:
|
|
17
|
-
*
|
|
18
|
-
* - `long` verbose formatting [false]
|
|
19
|
-
*
|
|
20
16
|
* @api public
|
|
21
17
|
* @param {string|number} val
|
|
22
|
-
* @param {Object} options
|
|
23
18
|
* @return {string|number}
|
|
24
19
|
*/
|
|
25
|
-
module.exports = function (val
|
|
26
|
-
options = options || {};
|
|
20
|
+
module.exports = function (val) {
|
|
27
21
|
if (typeof val === 'string') {
|
|
28
22
|
return parse(val);
|
|
29
23
|
}
|
|
30
|
-
|
|
31
|
-
return options['long'] ? longFormat(val) : shortFormat(val);
|
|
24
|
+
return format(val);
|
|
32
25
|
};
|
|
33
26
|
|
|
34
27
|
/**
|
|
@@ -74,13 +67,13 @@ function parse (str) {
|
|
|
74
67
|
}
|
|
75
68
|
|
|
76
69
|
/**
|
|
77
|
-
*
|
|
70
|
+
* Format for `ms`.
|
|
78
71
|
*
|
|
79
72
|
* @api private
|
|
80
73
|
* @param {number} ms
|
|
81
74
|
* @return {string}
|
|
82
75
|
*/
|
|
83
|
-
function
|
|
76
|
+
function format (ms) {
|
|
84
77
|
if (ms >= d) {
|
|
85
78
|
return Math.round(ms / d) + 'd';
|
|
86
79
|
}
|
|
@@ -95,36 +88,3 @@ function shortFormat (ms) {
|
|
|
95
88
|
}
|
|
96
89
|
return ms + 'ms';
|
|
97
90
|
}
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Long format for `ms`.
|
|
101
|
-
*
|
|
102
|
-
* @api private
|
|
103
|
-
* @param {number} ms
|
|
104
|
-
* @return {string}
|
|
105
|
-
*/
|
|
106
|
-
function longFormat (ms) {
|
|
107
|
-
return plural(ms, d, 'day') ||
|
|
108
|
-
plural(ms, h, 'hour') ||
|
|
109
|
-
plural(ms, m, 'minute') ||
|
|
110
|
-
plural(ms, s, 'second') ||
|
|
111
|
-
ms + ' ms';
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* Pluralization helper.
|
|
116
|
-
*
|
|
117
|
-
* @api private
|
|
118
|
-
* @param {number} ms
|
|
119
|
-
* @param {number} n
|
|
120
|
-
* @param {string} name
|
|
121
|
-
*/
|
|
122
|
-
function plural (ms, n, name) {
|
|
123
|
-
if (ms < n) {
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
if (ms < n * 1.5) {
|
|
127
|
-
return Math.floor(ms / n) + ' ' + name;
|
|
128
|
-
}
|
|
129
|
-
return Math.ceil(ms / n) + ' ' + name + 's';
|
|
130
|
-
}
|
package/lib/reporters/base.js
CHANGED
|
@@ -155,6 +155,17 @@ exports.cursor = {
|
|
|
155
155
|
}
|
|
156
156
|
};
|
|
157
157
|
|
|
158
|
+
function showDiff (err) {
|
|
159
|
+
return err && err.showDiff !== false && sameType(err.actual, err.expected) && err.expected !== undefined;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function stringifyDiffObjs (err) {
|
|
163
|
+
if (!utils.isString(err.actual) || !utils.isString(err.expected)) {
|
|
164
|
+
err.actual = utils.stringify(err.actual);
|
|
165
|
+
err.expected = utils.stringify(err.expected);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
158
169
|
/**
|
|
159
170
|
* Output the given `failures` as a list.
|
|
160
171
|
*
|
|
@@ -183,9 +194,6 @@ exports.list = function (failures) {
|
|
|
183
194
|
}
|
|
184
195
|
var stack = err.stack || message;
|
|
185
196
|
var index = message ? stack.indexOf(message) : -1;
|
|
186
|
-
var actual = err.actual;
|
|
187
|
-
var expected = err.expected;
|
|
188
|
-
var escape = true;
|
|
189
197
|
|
|
190
198
|
if (index === -1) {
|
|
191
199
|
msg = message;
|
|
@@ -201,21 +209,16 @@ exports.list = function (failures) {
|
|
|
201
209
|
msg = 'Uncaught ' + msg;
|
|
202
210
|
}
|
|
203
211
|
// explicitly show diff
|
|
204
|
-
if (
|
|
205
|
-
|
|
206
|
-
if (!(utils.isString(actual) && utils.isString(expected))) {
|
|
207
|
-
err.actual = actual = utils.stringify(actual);
|
|
208
|
-
err.expected = expected = utils.stringify(expected);
|
|
209
|
-
}
|
|
210
|
-
|
|
212
|
+
if (!exports.hideDiff && showDiff(err)) {
|
|
213
|
+
stringifyDiffObjs(err);
|
|
211
214
|
fmt = color('error title', ' %s) %s:\n%s') + color('error stack', '\n%s\n');
|
|
212
215
|
var match = message.match(/^([^:]+): expected/);
|
|
213
216
|
msg = '\n ' + color('error message', match ? match[1] : msg);
|
|
214
217
|
|
|
215
218
|
if (exports.inlineDiffs) {
|
|
216
|
-
msg += inlineDiff(err
|
|
219
|
+
msg += inlineDiff(err);
|
|
217
220
|
} else {
|
|
218
|
-
msg += unifiedDiff(err
|
|
221
|
+
msg += unifiedDiff(err);
|
|
219
222
|
}
|
|
220
223
|
}
|
|
221
224
|
|
|
@@ -292,13 +295,16 @@ function Base (runner) {
|
|
|
292
295
|
runner.on('fail', function (test, err) {
|
|
293
296
|
stats.failures = stats.failures || 0;
|
|
294
297
|
stats.failures++;
|
|
298
|
+
if (showDiff(err)) {
|
|
299
|
+
stringifyDiffObjs(err);
|
|
300
|
+
}
|
|
295
301
|
test.err = err;
|
|
296
302
|
failures.push(test);
|
|
297
303
|
});
|
|
298
304
|
|
|
299
305
|
runner.on('end', function () {
|
|
300
306
|
stats.end = new Date();
|
|
301
|
-
stats.duration =
|
|
307
|
+
stats.duration = stats.end - stats.start;
|
|
302
308
|
});
|
|
303
309
|
|
|
304
310
|
runner.on('pending', function () {
|
|
@@ -366,11 +372,10 @@ function pad (str, len) {
|
|
|
366
372
|
*
|
|
367
373
|
* @api private
|
|
368
374
|
* @param {Error} err with actual/expected
|
|
369
|
-
* @param {boolean} escape
|
|
370
375
|
* @return {string} Diff
|
|
371
376
|
*/
|
|
372
|
-
function inlineDiff (err
|
|
373
|
-
var msg = errorDiff(err
|
|
377
|
+
function inlineDiff (err) {
|
|
378
|
+
var msg = errorDiff(err);
|
|
374
379
|
|
|
375
380
|
// linenos
|
|
376
381
|
var lines = msg.split('\n');
|
|
@@ -400,15 +405,11 @@ function inlineDiff (err, escape) {
|
|
|
400
405
|
*
|
|
401
406
|
* @api private
|
|
402
407
|
* @param {Error} err with actual/expected
|
|
403
|
-
* @param {boolean} escape
|
|
404
408
|
* @return {string} The diff.
|
|
405
409
|
*/
|
|
406
|
-
function unifiedDiff (err
|
|
410
|
+
function unifiedDiff (err) {
|
|
407
411
|
var indent = ' ';
|
|
408
412
|
function cleanUp (line) {
|
|
409
|
-
if (escape) {
|
|
410
|
-
line = escapeInvisibles(line);
|
|
411
|
-
}
|
|
412
413
|
if (line[0] === '+') {
|
|
413
414
|
return indent + colorLines('diff added', line);
|
|
414
415
|
}
|
|
@@ -440,14 +441,10 @@ function unifiedDiff (err, escape) {
|
|
|
440
441
|
*
|
|
441
442
|
* @api private
|
|
442
443
|
* @param {Error} err
|
|
443
|
-
* @param {string} type
|
|
444
|
-
* @param {boolean} escape
|
|
445
444
|
* @return {string}
|
|
446
445
|
*/
|
|
447
|
-
function errorDiff (err
|
|
448
|
-
|
|
449
|
-
var expected = escape ? escapeInvisibles(err.expected) : err.expected;
|
|
450
|
-
return diff['diff' + type](actual, expected).map(function (str) {
|
|
446
|
+
function errorDiff (err) {
|
|
447
|
+
return diff.diffWordsWithSpace(err.actual, err.expected).map(function (str) {
|
|
451
448
|
if (str.added) {
|
|
452
449
|
return colorLines('diff added', str.value);
|
|
453
450
|
}
|
|
@@ -458,19 +455,6 @@ function errorDiff (err, type, escape) {
|
|
|
458
455
|
}).join('');
|
|
459
456
|
}
|
|
460
457
|
|
|
461
|
-
/**
|
|
462
|
-
* Returns a string with all invisible characters in plain text
|
|
463
|
-
*
|
|
464
|
-
* @api private
|
|
465
|
-
* @param {string} line
|
|
466
|
-
* @return {string}
|
|
467
|
-
*/
|
|
468
|
-
function escapeInvisibles (line) {
|
|
469
|
-
return line.replace(/\t/g, '<tab>')
|
|
470
|
-
.replace(/\r/g, '<CR>')
|
|
471
|
-
.replace(/\n/g, '<LF>\n');
|
|
472
|
-
}
|
|
473
|
-
|
|
474
458
|
/**
|
|
475
459
|
* Color lines for `str`, using the color `name`.
|
|
476
460
|
*
|