mocha 6.2.1 → 7.0.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 +74 -0
- package/README.md +26 -26
- package/bin/mocha +12 -43
- package/lib/cli/node-flags.js +5 -2
- package/lib/cli/one-and-dones.js +2 -2
- package/lib/cli/options.js +4 -34
- package/lib/cli/run-helpers.js +4 -3
- package/lib/cli/run-option-metadata.js +6 -5
- package/lib/cli/run.js +24 -11
- package/lib/cli/watch-run.js +116 -31
- package/lib/mocha.js +137 -102
- package/lib/mocharc.json +2 -1
- package/lib/reporters/base.js +33 -8
- package/lib/reporters/html.js +2 -2
- package/lib/reporters/xunit.js +3 -3
- package/lib/runnable.js +16 -17
- package/lib/runner.js +76 -45
- package/lib/utils.js +0 -74
- package/mocha.js +271 -254
- package/package.json +31 -6
- package/bin/options.js +0 -10
package/lib/mocha.js
CHANGED
|
@@ -69,28 +69,26 @@ exports.Test = require('./test');
|
|
|
69
69
|
* @param {boolean} [options.allowUncaught] - Propagate uncaught errors?
|
|
70
70
|
* @param {boolean} [options.asyncOnly] - Force `done` callback or promise?
|
|
71
71
|
* @param {boolean} [options.bail] - Bail after first test failure?
|
|
72
|
-
* @param {boolean} [options.checkLeaks] -
|
|
72
|
+
* @param {boolean} [options.checkLeaks] - Check for global variable leaks?
|
|
73
|
+
* @param {boolean} [options.color] - Color TTY output from reporter?
|
|
73
74
|
* @param {boolean} [options.delay] - Delay root suite execution?
|
|
74
|
-
* @param {boolean} [options.
|
|
75
|
+
* @param {boolean} [options.diff] - Show diff on failure?
|
|
75
76
|
* @param {string} [options.fgrep] - Test filter given string.
|
|
76
77
|
* @param {boolean} [options.forbidOnly] - Tests marked `only` fail the suite?
|
|
77
78
|
* @param {boolean} [options.forbidPending] - Pending tests fail the suite?
|
|
78
|
-
* @param {boolean} [options.
|
|
79
|
+
* @param {boolean} [options.fullTrace] - Full stacktrace upon failure?
|
|
79
80
|
* @param {string[]} [options.global] - Variables expected in global scope.
|
|
80
81
|
* @param {RegExp|string} [options.grep] - Test filter given regular expression.
|
|
81
82
|
* @param {boolean} [options.growl] - Enable desktop notifications?
|
|
82
|
-
* @param {boolean} [options.
|
|
83
|
-
* @param {boolean} [options.ignoreLeaks] - Ignore global leaks?
|
|
83
|
+
* @param {boolean} [options.inlineDiffs] - Display inline diffs?
|
|
84
84
|
* @param {boolean} [options.invert] - Invert test filter matches?
|
|
85
85
|
* @param {boolean} [options.noHighlighting] - Disable syntax highlighting?
|
|
86
|
-
* @param {string} [options.reporter] - Reporter name.
|
|
86
|
+
* @param {string|constructor} [options.reporter] - Reporter name or constructor.
|
|
87
87
|
* @param {Object} [options.reporterOption] - Reporter settings object.
|
|
88
88
|
* @param {number} [options.retries] - Number of times to retry failed tests.
|
|
89
89
|
* @param {number} [options.slow] - Slow threshold value.
|
|
90
90
|
* @param {number|string} [options.timeout] - Timeout threshold value.
|
|
91
91
|
* @param {string} [options.ui] - Interface name.
|
|
92
|
-
* @param {boolean} [options.color] - Color TTY output from reporter?
|
|
93
|
-
* @param {boolean} [options.useInlineDiffs] - Use inline diffs?
|
|
94
92
|
*/
|
|
95
93
|
function Mocha(options) {
|
|
96
94
|
options = utils.assign({}, mocharc, options || {});
|
|
@@ -99,35 +97,12 @@ function Mocha(options) {
|
|
|
99
97
|
// root suite
|
|
100
98
|
this.suite = new exports.Suite('', new exports.Context(), true);
|
|
101
99
|
|
|
102
|
-
if ('useColors' in options) {
|
|
103
|
-
utils.deprecate(
|
|
104
|
-
'useColors is DEPRECATED and will be removed from a future version of Mocha. Instead, use the "color" option'
|
|
105
|
-
);
|
|
106
|
-
options.color = 'color' in options ? options.color : options.useColors;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
// Globals are passed in as options.global, with options.globals for backward compatibility.
|
|
110
|
-
options.globals = options.global || options.globals || [];
|
|
111
|
-
delete options.global;
|
|
112
|
-
|
|
113
100
|
this.grep(options.grep)
|
|
114
101
|
.fgrep(options.fgrep)
|
|
115
102
|
.ui(options.ui)
|
|
116
|
-
.
|
|
117
|
-
.reporter(options.reporter, options.reporterOptions)
|
|
118
|
-
.useColors(options.color)
|
|
103
|
+
.reporter(options.reporter, options.reporterOption)
|
|
119
104
|
.slow(options.slow)
|
|
120
|
-
.
|
|
121
|
-
.globals(options.globals);
|
|
122
|
-
|
|
123
|
-
if ('enableTimeouts' in options) {
|
|
124
|
-
utils.deprecate(
|
|
125
|
-
'enableTimeouts is DEPRECATED and will be removed from a future version of Mocha. Instead, use "timeout: false" to disable timeouts.'
|
|
126
|
-
);
|
|
127
|
-
if (options.enableTimeouts === false) {
|
|
128
|
-
this.timeout(0);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
105
|
+
.global(options.global);
|
|
131
106
|
|
|
132
107
|
// this guard exists because Suite#timeout does not consider `undefined` to be valid input
|
|
133
108
|
if (typeof options.timeout !== 'undefined') {
|
|
@@ -138,19 +113,19 @@ function Mocha(options) {
|
|
|
138
113
|
this.retries(options.retries);
|
|
139
114
|
}
|
|
140
115
|
|
|
141
|
-
if ('diff' in options) {
|
|
142
|
-
this.hideDiff(!options.diff);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
116
|
[
|
|
146
117
|
'allowUncaught',
|
|
147
118
|
'asyncOnly',
|
|
119
|
+
'bail',
|
|
148
120
|
'checkLeaks',
|
|
121
|
+
'color',
|
|
149
122
|
'delay',
|
|
123
|
+
'diff',
|
|
150
124
|
'forbidOnly',
|
|
151
125
|
'forbidPending',
|
|
152
126
|
'fullTrace',
|
|
153
127
|
'growl',
|
|
128
|
+
'inlineDiffs',
|
|
154
129
|
'invert'
|
|
155
130
|
].forEach(function(opt) {
|
|
156
131
|
if (options[opt]) {
|
|
@@ -163,16 +138,13 @@ function Mocha(options) {
|
|
|
163
138
|
* Enables or disables bailing on the first failure.
|
|
164
139
|
*
|
|
165
140
|
* @public
|
|
166
|
-
* @see
|
|
141
|
+
* @see [CLI option](../#-bail-b)
|
|
167
142
|
* @param {boolean} [bail=true] - Whether to bail on first error.
|
|
168
143
|
* @returns {Mocha} this
|
|
169
144
|
* @chainable
|
|
170
145
|
*/
|
|
171
146
|
Mocha.prototype.bail = function(bail) {
|
|
172
|
-
|
|
173
|
-
bail = true;
|
|
174
|
-
}
|
|
175
|
-
this.suite.bail(bail);
|
|
147
|
+
this.suite.bail(bail !== false);
|
|
176
148
|
return this;
|
|
177
149
|
};
|
|
178
150
|
|
|
@@ -184,7 +156,7 @@ Mocha.prototype.bail = function(bail) {
|
|
|
184
156
|
* Useful for generic setup code that must be included within test suite.
|
|
185
157
|
*
|
|
186
158
|
* @public
|
|
187
|
-
* @see
|
|
159
|
+
* @see [CLI option](../#-file-filedirectoryglob)
|
|
188
160
|
* @param {string} file - Pathname of file to be loaded.
|
|
189
161
|
* @returns {Mocha} this
|
|
190
162
|
* @chainable
|
|
@@ -198,8 +170,8 @@ Mocha.prototype.addFile = function(file) {
|
|
|
198
170
|
* Sets reporter to `reporter`, defaults to "spec".
|
|
199
171
|
*
|
|
200
172
|
* @public
|
|
201
|
-
* @see
|
|
202
|
-
* @see
|
|
173
|
+
* @see [CLI option](../#-reporter-name-r-name)
|
|
174
|
+
* @see [Reporters](../#reporters)
|
|
203
175
|
* @param {String|Function} reporter - Reporter name or constructor.
|
|
204
176
|
* @param {Object} [reporterOptions] - Options used to configure the reporter.
|
|
205
177
|
* @returns {Mocha} this
|
|
@@ -257,6 +229,8 @@ Mocha.prototype.reporter = function(reporter, reporterOptions) {
|
|
|
257
229
|
}
|
|
258
230
|
this._reporter = _reporter;
|
|
259
231
|
}
|
|
232
|
+
this.options.reporterOption = reporterOptions;
|
|
233
|
+
// alias option name is used in public reporters xunit/tap/progress
|
|
260
234
|
this.options.reporterOptions = reporterOptions;
|
|
261
235
|
return this;
|
|
262
236
|
};
|
|
@@ -265,8 +239,8 @@ Mocha.prototype.reporter = function(reporter, reporterOptions) {
|
|
|
265
239
|
* Sets test UI `name`, defaults to "bdd".
|
|
266
240
|
*
|
|
267
241
|
* @public
|
|
268
|
-
* @see
|
|
269
|
-
* @see
|
|
242
|
+
* @see [CLI option](../#-ui-name-u-name)
|
|
243
|
+
* @see [Interface DSLs](../#interfaces)
|
|
270
244
|
* @param {string|Function} [ui=bdd] - Interface name or class.
|
|
271
245
|
* @returns {Mocha} this
|
|
272
246
|
* @chainable
|
|
@@ -359,8 +333,6 @@ Mocha.unloadFile = function(file) {
|
|
|
359
333
|
* <strong>Intended for consumers — not used internally</strong>
|
|
360
334
|
*
|
|
361
335
|
* @public
|
|
362
|
-
* @see {@link Mocha.unloadFile}
|
|
363
|
-
* @see {@link Mocha#loadFiles}
|
|
364
336
|
* @see {@link Mocha#run}
|
|
365
337
|
* @returns {Mocha} this
|
|
366
338
|
* @chainable
|
|
@@ -404,7 +376,7 @@ Mocha.prototype.fgrep = function(str) {
|
|
|
404
376
|
* <strong>Previous filter value will be overwritten on each call!</strong>
|
|
405
377
|
*
|
|
406
378
|
* @public
|
|
407
|
-
* @see
|
|
379
|
+
* @see [CLI option](../#-grep-regexp-g-regexp)
|
|
408
380
|
* @see {@link Mocha#fgrep}
|
|
409
381
|
* @see {@link Mocha#invert}
|
|
410
382
|
* @param {RegExp|String} re - Regular expression used to select tests.
|
|
@@ -455,32 +427,32 @@ Mocha.prototype.invert = function() {
|
|
|
455
427
|
/**
|
|
456
428
|
* Enables or disables ignoring global leaks.
|
|
457
429
|
*
|
|
430
|
+
* @deprecated since v7.0.0
|
|
458
431
|
* @public
|
|
459
432
|
* @see {@link Mocha#checkLeaks}
|
|
460
|
-
* @param {boolean} ignoreLeaks - Whether to ignore global leaks.
|
|
433
|
+
* @param {boolean} [ignoreLeaks=false] - Whether to ignore global leaks.
|
|
461
434
|
* @return {Mocha} this
|
|
462
435
|
* @chainable
|
|
463
|
-
* @example
|
|
464
|
-
*
|
|
465
|
-
* // Ignore global leaks
|
|
466
|
-
* mocha.ignoreLeaks(true);
|
|
467
436
|
*/
|
|
468
437
|
Mocha.prototype.ignoreLeaks = function(ignoreLeaks) {
|
|
469
|
-
|
|
438
|
+
utils.deprecate(
|
|
439
|
+
'"ignoreLeaks()" is DEPRECATED, please use "checkLeaks()" instead.'
|
|
440
|
+
);
|
|
441
|
+
this.options.checkLeaks = !ignoreLeaks;
|
|
470
442
|
return this;
|
|
471
443
|
};
|
|
472
444
|
|
|
473
445
|
/**
|
|
474
|
-
* Enables checking for global variables leaked while running tests.
|
|
446
|
+
* Enables or disables checking for global variables leaked while running tests.
|
|
475
447
|
*
|
|
476
448
|
* @public
|
|
477
|
-
* @see
|
|
478
|
-
* @
|
|
449
|
+
* @see [CLI option](../#-check-leaks)
|
|
450
|
+
* @param {boolean} [checkLeaks=true] - Whether to check for global variable leaks.
|
|
479
451
|
* @return {Mocha} this
|
|
480
452
|
* @chainable
|
|
481
453
|
*/
|
|
482
|
-
Mocha.prototype.checkLeaks = function() {
|
|
483
|
-
this.options.
|
|
454
|
+
Mocha.prototype.checkLeaks = function(checkLeaks) {
|
|
455
|
+
this.options.checkLeaks = checkLeaks !== false;
|
|
484
456
|
return this;
|
|
485
457
|
};
|
|
486
458
|
|
|
@@ -488,11 +460,13 @@ Mocha.prototype.checkLeaks = function() {
|
|
|
488
460
|
* Displays full stack trace upon test failure.
|
|
489
461
|
*
|
|
490
462
|
* @public
|
|
463
|
+
* @see [CLI option](../#-full-trace)
|
|
464
|
+
* @param {boolean} [fullTrace=true] - Whether to print full stacktrace upon failure.
|
|
491
465
|
* @return {Mocha} this
|
|
492
466
|
* @chainable
|
|
493
467
|
*/
|
|
494
|
-
Mocha.prototype.fullTrace = function() {
|
|
495
|
-
this.options.
|
|
468
|
+
Mocha.prototype.fullTrace = function(fullTrace) {
|
|
469
|
+
this.options.fullTrace = fullTrace !== false;
|
|
496
470
|
return this;
|
|
497
471
|
};
|
|
498
472
|
|
|
@@ -500,8 +474,7 @@ Mocha.prototype.fullTrace = function() {
|
|
|
500
474
|
* Enables desktop notification support if prerequisite software installed.
|
|
501
475
|
*
|
|
502
476
|
* @public
|
|
503
|
-
* @see
|
|
504
|
-
* @see {@link Mocha#_growl}
|
|
477
|
+
* @see [CLI option](../#-growl-g)
|
|
505
478
|
* @return {Mocha} this
|
|
506
479
|
* @chainable
|
|
507
480
|
*/
|
|
@@ -544,65 +517,121 @@ Mocha.prototype._growl = growl.notify;
|
|
|
544
517
|
* Specifies whitelist of variable names to be expected in global scope.
|
|
545
518
|
*
|
|
546
519
|
* @public
|
|
547
|
-
* @see
|
|
520
|
+
* @see [CLI option](../#-global-variable-name)
|
|
548
521
|
* @see {@link Mocha#checkLeaks}
|
|
549
|
-
* @param {String[]|String}
|
|
522
|
+
* @param {String[]|String} global - Accepted global variable name(s).
|
|
550
523
|
* @return {Mocha} this
|
|
551
524
|
* @chainable
|
|
552
525
|
* @example
|
|
553
526
|
*
|
|
554
527
|
* // Specify variables to be expected in global scope
|
|
555
|
-
* mocha.
|
|
528
|
+
* mocha.global(['jQuery', 'MyLib']);
|
|
556
529
|
*/
|
|
557
|
-
Mocha.prototype.
|
|
558
|
-
this.options.
|
|
559
|
-
.concat(
|
|
530
|
+
Mocha.prototype.global = function(global) {
|
|
531
|
+
this.options.global = (this.options.global || [])
|
|
532
|
+
.concat(global)
|
|
560
533
|
.filter(Boolean)
|
|
561
534
|
.filter(function(elt, idx, arr) {
|
|
562
535
|
return arr.indexOf(elt) === idx;
|
|
563
536
|
});
|
|
564
537
|
return this;
|
|
565
538
|
};
|
|
539
|
+
// for backwards compability, 'globals' is an alias of 'global'
|
|
540
|
+
Mocha.prototype.globals = Mocha.prototype.global;
|
|
566
541
|
|
|
567
542
|
/**
|
|
568
543
|
* Enables or disables TTY color output by screen-oriented reporters.
|
|
569
544
|
*
|
|
545
|
+
* @deprecated since v7.0.0
|
|
570
546
|
* @public
|
|
547
|
+
* @see {@link Mocha#color}
|
|
571
548
|
* @param {boolean} colors - Whether to enable color output.
|
|
572
549
|
* @return {Mocha} this
|
|
573
550
|
* @chainable
|
|
574
551
|
*/
|
|
575
552
|
Mocha.prototype.useColors = function(colors) {
|
|
553
|
+
utils.deprecate('"useColors()" is DEPRECATED, please use "color()" instead.');
|
|
576
554
|
if (colors !== undefined) {
|
|
577
|
-
this.options.
|
|
555
|
+
this.options.color = colors;
|
|
578
556
|
}
|
|
579
557
|
return this;
|
|
580
558
|
};
|
|
581
559
|
|
|
560
|
+
/**
|
|
561
|
+
* Enables or disables TTY color output by screen-oriented reporters.
|
|
562
|
+
*
|
|
563
|
+
* @public
|
|
564
|
+
* @see [CLI option](../#-color-c-colors)
|
|
565
|
+
* @param {boolean} [color=true] - Whether to enable color output.
|
|
566
|
+
* @return {Mocha} this
|
|
567
|
+
* @chainable
|
|
568
|
+
*/
|
|
569
|
+
Mocha.prototype.color = function(color) {
|
|
570
|
+
this.options.color = color !== false;
|
|
571
|
+
return this;
|
|
572
|
+
};
|
|
573
|
+
|
|
582
574
|
/**
|
|
583
575
|
* Determines if reporter should use inline diffs (rather than +/-)
|
|
584
576
|
* in test failure output.
|
|
585
577
|
*
|
|
578
|
+
* @deprecated since v7.0.0
|
|
586
579
|
* @public
|
|
587
|
-
* @
|
|
580
|
+
* @see {@link Mocha#inlineDiffs}
|
|
581
|
+
* @param {boolean} [inlineDiffs=false] - Whether to use inline diffs.
|
|
588
582
|
* @return {Mocha} this
|
|
589
583
|
* @chainable
|
|
590
584
|
*/
|
|
591
585
|
Mocha.prototype.useInlineDiffs = function(inlineDiffs) {
|
|
592
|
-
|
|
586
|
+
utils.deprecate(
|
|
587
|
+
'"useInlineDiffs()" is DEPRECATED, please use "inlineDiffs()" instead.'
|
|
588
|
+
);
|
|
589
|
+
this.options.inlineDiffs = inlineDiffs !== undefined && inlineDiffs;
|
|
590
|
+
return this;
|
|
591
|
+
};
|
|
592
|
+
|
|
593
|
+
/**
|
|
594
|
+
* Enables or disables reporter to use inline diffs (rather than +/-)
|
|
595
|
+
* in test failure output.
|
|
596
|
+
*
|
|
597
|
+
* @public
|
|
598
|
+
* @see [CLI option](../#-inline-diffs)
|
|
599
|
+
* @param {boolean} [inlineDiffs=true] - Whether to use inline diffs.
|
|
600
|
+
* @return {Mocha} this
|
|
601
|
+
* @chainable
|
|
602
|
+
*/
|
|
603
|
+
Mocha.prototype.inlineDiffs = function(inlineDiffs) {
|
|
604
|
+
this.options.inlineDiffs = inlineDiffs !== false;
|
|
593
605
|
return this;
|
|
594
606
|
};
|
|
595
607
|
|
|
596
608
|
/**
|
|
597
609
|
* Determines if reporter should include diffs in test failure output.
|
|
598
610
|
*
|
|
611
|
+
* @deprecated since v7.0.0
|
|
599
612
|
* @public
|
|
600
|
-
* @
|
|
613
|
+
* @see {@link Mocha#diff}
|
|
614
|
+
* @param {boolean} [hideDiff=false] - Whether to hide diffs.
|
|
601
615
|
* @return {Mocha} this
|
|
602
616
|
* @chainable
|
|
603
617
|
*/
|
|
604
618
|
Mocha.prototype.hideDiff = function(hideDiff) {
|
|
605
|
-
|
|
619
|
+
utils.deprecate('"hideDiff()" is DEPRECATED, please use "diff()" instead.');
|
|
620
|
+
this.options.diff = !(hideDiff === true);
|
|
621
|
+
return this;
|
|
622
|
+
};
|
|
623
|
+
|
|
624
|
+
/**
|
|
625
|
+
* Enables or disables reporter to include diff in test failure output.
|
|
626
|
+
*
|
|
627
|
+
* @public
|
|
628
|
+
* @see [CLI option](../#-diff)
|
|
629
|
+
* @param {boolean} [diff=true] - Whether to show diff on failure.
|
|
630
|
+
* @return {Mocha} this
|
|
631
|
+
* @chainable
|
|
632
|
+
*/
|
|
633
|
+
Mocha.prototype.diff = function(diff) {
|
|
634
|
+
this.options.diff = diff !== false;
|
|
606
635
|
return this;
|
|
607
636
|
};
|
|
608
637
|
|
|
@@ -615,9 +644,8 @@ Mocha.prototype.hideDiff = function(hideDiff) {
|
|
|
615
644
|
* If the value is `0`, timeouts will be disabled.
|
|
616
645
|
*
|
|
617
646
|
* @public
|
|
618
|
-
* @see
|
|
619
|
-
* @see
|
|
620
|
-
* @see {@link https://mochajs.org/#timeouts|Timeouts}
|
|
647
|
+
* @see [CLI option](../#-timeout-ms-t-ms)
|
|
648
|
+
* @see [Timeouts](../#timeouts)
|
|
621
649
|
* @see {@link Mocha#enableTimeouts}
|
|
622
650
|
* @param {number|string} msecs - Timeout threshold value.
|
|
623
651
|
* @return {Mocha} this
|
|
@@ -640,7 +668,8 @@ Mocha.prototype.timeout = function(msecs) {
|
|
|
640
668
|
* Sets the number of times to retry failed tests.
|
|
641
669
|
*
|
|
642
670
|
* @public
|
|
643
|
-
* @see
|
|
671
|
+
* @see [CLI option](../#-retries-n)
|
|
672
|
+
* @see [Retry Tests](../#retry-tests)
|
|
644
673
|
* @param {number} retry - Number of times to retry failed tests.
|
|
645
674
|
* @return {Mocha} this
|
|
646
675
|
* @chainable
|
|
@@ -658,7 +687,7 @@ Mocha.prototype.retries = function(n) {
|
|
|
658
687
|
* Sets slowness threshold value.
|
|
659
688
|
*
|
|
660
689
|
* @public
|
|
661
|
-
* @see
|
|
690
|
+
* @see [CLI option](../#-slow-ms-s-ms)
|
|
662
691
|
* @param {number} msecs - Slowness threshold value.
|
|
663
692
|
* @return {Mocha} this
|
|
664
693
|
* @chainable
|
|
@@ -680,8 +709,7 @@ Mocha.prototype.slow = function(msecs) {
|
|
|
680
709
|
* Enables or disables timeouts.
|
|
681
710
|
*
|
|
682
711
|
* @public
|
|
683
|
-
* @see
|
|
684
|
-
* @see {@link https://mochajs.org/#--no-timeouts|CLI option}
|
|
712
|
+
* @see [CLI option](../#-timeout-ms-t-ms)
|
|
685
713
|
* @param {boolean} enableTimeouts - Whether to enable timeouts.
|
|
686
714
|
* @return {Mocha} this
|
|
687
715
|
* @chainable
|
|
@@ -697,11 +725,13 @@ Mocha.prototype.enableTimeouts = function(enableTimeouts) {
|
|
|
697
725
|
* Forces all tests to either accept a `done` callback or return a promise.
|
|
698
726
|
*
|
|
699
727
|
* @public
|
|
728
|
+
* @see [CLI option](../#-async-only-a)
|
|
729
|
+
* @param {boolean} [asyncOnly=true] - Wether to force `done` callback or promise.
|
|
700
730
|
* @return {Mocha} this
|
|
701
731
|
* @chainable
|
|
702
732
|
*/
|
|
703
|
-
Mocha.prototype.asyncOnly = function() {
|
|
704
|
-
this.options.asyncOnly =
|
|
733
|
+
Mocha.prototype.asyncOnly = function(asyncOnly) {
|
|
734
|
+
this.options.asyncOnly = asyncOnly !== false;
|
|
705
735
|
return this;
|
|
706
736
|
};
|
|
707
737
|
|
|
@@ -718,14 +748,16 @@ Mocha.prototype.noHighlighting = function() {
|
|
|
718
748
|
};
|
|
719
749
|
|
|
720
750
|
/**
|
|
721
|
-
* Enables uncaught errors to propagate
|
|
751
|
+
* Enables or disables uncaught errors to propagate.
|
|
722
752
|
*
|
|
723
753
|
* @public
|
|
754
|
+
* @see [CLI option](../#-allow-uncaught)
|
|
755
|
+
* @param {boolean} [allowUncaught=true] - Whether to propagate uncaught errors.
|
|
724
756
|
* @return {Mocha} this
|
|
725
757
|
* @chainable
|
|
726
758
|
*/
|
|
727
|
-
Mocha.prototype.allowUncaught = function() {
|
|
728
|
-
this.options.allowUncaught =
|
|
759
|
+
Mocha.prototype.allowUncaught = function(allowUncaught) {
|
|
760
|
+
this.options.allowUncaught = allowUncaught !== false;
|
|
729
761
|
return this;
|
|
730
762
|
};
|
|
731
763
|
|
|
@@ -737,7 +769,7 @@ Mocha.prototype.allowUncaught = function() {
|
|
|
737
769
|
* Used to perform asynch operations before any suites are run.
|
|
738
770
|
*
|
|
739
771
|
* @public
|
|
740
|
-
* @see
|
|
772
|
+
* @see [delayed root suite](../#delayed-root-suite)
|
|
741
773
|
* @returns {Mocha} this
|
|
742
774
|
* @chainable
|
|
743
775
|
*/
|
|
@@ -750,11 +782,13 @@ Mocha.prototype.delay = function delay() {
|
|
|
750
782
|
* Causes tests marked `only` to fail the suite.
|
|
751
783
|
*
|
|
752
784
|
* @public
|
|
785
|
+
* @see [CLI option](../#-forbid-only)
|
|
786
|
+
* @param {boolean} [forbidOnly=true] - Whether tests marked `only` fail the suite.
|
|
753
787
|
* @returns {Mocha} this
|
|
754
788
|
* @chainable
|
|
755
789
|
*/
|
|
756
|
-
Mocha.prototype.forbidOnly = function() {
|
|
757
|
-
this.options.forbidOnly =
|
|
790
|
+
Mocha.prototype.forbidOnly = function(forbidOnly) {
|
|
791
|
+
this.options.forbidOnly = forbidOnly !== false;
|
|
758
792
|
return this;
|
|
759
793
|
};
|
|
760
794
|
|
|
@@ -762,11 +796,13 @@ Mocha.prototype.forbidOnly = function() {
|
|
|
762
796
|
* Causes pending tests and tests marked `skip` to fail the suite.
|
|
763
797
|
*
|
|
764
798
|
* @public
|
|
799
|
+
* @see [CLI option](../#-forbid-pending)
|
|
800
|
+
* @param {boolean} [forbidPending=true] - Whether pending tests fail the suite.
|
|
765
801
|
* @returns {Mocha} this
|
|
766
802
|
* @chainable
|
|
767
803
|
*/
|
|
768
|
-
Mocha.prototype.forbidPending = function() {
|
|
769
|
-
this.options.forbidPending =
|
|
804
|
+
Mocha.prototype.forbidPending = function(forbidPending) {
|
|
805
|
+
this.options.forbidPending = forbidPending !== false;
|
|
770
806
|
return this;
|
|
771
807
|
};
|
|
772
808
|
|
|
@@ -800,7 +836,6 @@ Object.defineProperty(Mocha.prototype, 'version', {
|
|
|
800
836
|
* the cache first!
|
|
801
837
|
*
|
|
802
838
|
* @public
|
|
803
|
-
* @see {@link Mocha#loadFiles}
|
|
804
839
|
* @see {@link Mocha#unloadFiles}
|
|
805
840
|
* @see {@link Runner#run}
|
|
806
841
|
* @param {DoneCB} [fn] - Callback invoked when test execution completed.
|
|
@@ -816,8 +851,8 @@ Mocha.prototype.run = function(fn) {
|
|
|
816
851
|
var runner = new exports.Runner(suite, options.delay);
|
|
817
852
|
createStatsCollector(runner);
|
|
818
853
|
var reporter = new this._reporter(runner, options);
|
|
819
|
-
runner.
|
|
820
|
-
runner.fullStackTrace = options.
|
|
854
|
+
runner.checkLeaks = options.checkLeaks === true;
|
|
855
|
+
runner.fullStackTrace = options.fullTrace;
|
|
821
856
|
runner.asyncOnly = options.asyncOnly;
|
|
822
857
|
runner.allowUncaught = options.allowUncaught;
|
|
823
858
|
runner.forbidOnly = options.forbidOnly;
|
|
@@ -825,17 +860,17 @@ Mocha.prototype.run = function(fn) {
|
|
|
825
860
|
if (options.grep) {
|
|
826
861
|
runner.grep(options.grep, options.invert);
|
|
827
862
|
}
|
|
828
|
-
if (options.
|
|
829
|
-
runner.globals(options.
|
|
863
|
+
if (options.global) {
|
|
864
|
+
runner.globals(options.global);
|
|
830
865
|
}
|
|
831
866
|
if (options.growl) {
|
|
832
867
|
this._growl(runner);
|
|
833
868
|
}
|
|
834
|
-
if (options.
|
|
835
|
-
exports.reporters.Base.useColors = options.
|
|
869
|
+
if (options.color !== undefined) {
|
|
870
|
+
exports.reporters.Base.useColors = options.color;
|
|
836
871
|
}
|
|
837
|
-
exports.reporters.Base.inlineDiffs = options.
|
|
838
|
-
exports.reporters.Base.hideDiff = options.
|
|
872
|
+
exports.reporters.Base.inlineDiffs = options.inlineDiffs;
|
|
873
|
+
exports.reporters.Base.hideDiff = !options.diff;
|
|
839
874
|
|
|
840
875
|
function done(failures) {
|
|
841
876
|
fn = fn || utils.noop;
|
package/lib/mocharc.json
CHANGED
package/lib/reporters/base.js
CHANGED
|
@@ -154,14 +154,14 @@ exports.cursor = {
|
|
|
154
154
|
}
|
|
155
155
|
};
|
|
156
156
|
|
|
157
|
-
|
|
157
|
+
var showDiff = (exports.showDiff = function(err) {
|
|
158
158
|
return (
|
|
159
159
|
err &&
|
|
160
160
|
err.showDiff !== false &&
|
|
161
161
|
sameType(err.actual, err.expected) &&
|
|
162
162
|
err.expected !== undefined
|
|
163
163
|
);
|
|
164
|
-
}
|
|
164
|
+
});
|
|
165
165
|
|
|
166
166
|
function stringifyDiffObjs(err) {
|
|
167
167
|
if (!utils.isString(err.actual) || !utils.isString(err.expected)) {
|
|
@@ -182,9 +182,19 @@ function stringifyDiffObjs(err) {
|
|
|
182
182
|
* @return {string} Diff
|
|
183
183
|
*/
|
|
184
184
|
var generateDiff = (exports.generateDiff = function(actual, expected) {
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
185
|
+
try {
|
|
186
|
+
return exports.inlineDiffs
|
|
187
|
+
? inlineDiff(actual, expected)
|
|
188
|
+
: unifiedDiff(actual, expected);
|
|
189
|
+
} catch (err) {
|
|
190
|
+
var msg =
|
|
191
|
+
'\n ' +
|
|
192
|
+
color('diff added', '+ expected') +
|
|
193
|
+
' ' +
|
|
194
|
+
color('diff removed', '- actual: failed to generate Mocha diff') +
|
|
195
|
+
'\n';
|
|
196
|
+
return msg;
|
|
197
|
+
}
|
|
188
198
|
});
|
|
189
199
|
|
|
190
200
|
/**
|
|
@@ -197,6 +207,7 @@ var generateDiff = (exports.generateDiff = function(actual, expected) {
|
|
|
197
207
|
* Error property
|
|
198
208
|
*/
|
|
199
209
|
exports.list = function(failures) {
|
|
210
|
+
var multipleErr, multipleTest;
|
|
200
211
|
Base.consoleLog();
|
|
201
212
|
failures.forEach(function(test, i) {
|
|
202
213
|
// format
|
|
@@ -207,7 +218,16 @@ exports.list = function(failures) {
|
|
|
207
218
|
|
|
208
219
|
// msg
|
|
209
220
|
var msg;
|
|
210
|
-
var err
|
|
221
|
+
var err;
|
|
222
|
+
if (test.err && test.err.multiple) {
|
|
223
|
+
if (multipleTest !== test) {
|
|
224
|
+
multipleTest = test;
|
|
225
|
+
multipleErr = [test.err].concat(test.err.multiple);
|
|
226
|
+
}
|
|
227
|
+
err = multipleErr.shift();
|
|
228
|
+
} else {
|
|
229
|
+
err = test.err;
|
|
230
|
+
}
|
|
211
231
|
var message;
|
|
212
232
|
if (err.message && typeof err.message.toString === 'function') {
|
|
213
233
|
message = err.message + '';
|
|
@@ -298,7 +318,12 @@ function Base(runner, options) {
|
|
|
298
318
|
if (showDiff(err)) {
|
|
299
319
|
stringifyDiffObjs(err);
|
|
300
320
|
}
|
|
301
|
-
|
|
321
|
+
// more than one error per test
|
|
322
|
+
if (test.err && err instanceof Error) {
|
|
323
|
+
test.err.multiple = (test.err.multiple || []).concat(err);
|
|
324
|
+
} else {
|
|
325
|
+
test.err = err;
|
|
326
|
+
}
|
|
302
327
|
failures.push(test);
|
|
303
328
|
});
|
|
304
329
|
}
|
|
@@ -307,7 +332,7 @@ function Base(runner, options) {
|
|
|
307
332
|
* Outputs common epilogue used by many of the bundled reporters.
|
|
308
333
|
*
|
|
309
334
|
* @public
|
|
310
|
-
* @memberof Mocha.reporters
|
|
335
|
+
* @memberof Mocha.reporters
|
|
311
336
|
*/
|
|
312
337
|
Base.prototype.epilogue = function() {
|
|
313
338
|
var stats = this.stats;
|
package/lib/reporters/html.js
CHANGED
|
@@ -357,8 +357,8 @@ function hideSuitesWithout(classname) {
|
|
|
357
357
|
*/
|
|
358
358
|
function unhide() {
|
|
359
359
|
var els = document.getElementsByClassName('suite hidden');
|
|
360
|
-
|
|
361
|
-
els[
|
|
360
|
+
while (els.length > 0) {
|
|
361
|
+
els[0].className = els[0].className.replace('suite hidden', 'suite');
|
|
362
362
|
}
|
|
363
363
|
}
|
|
364
364
|
|
package/lib/reporters/xunit.js
CHANGED
|
@@ -163,9 +163,9 @@ XUnit.prototype.test = function(test) {
|
|
|
163
163
|
if (test.state === STATE_FAILED) {
|
|
164
164
|
var err = test.err;
|
|
165
165
|
var diff =
|
|
166
|
-
Base.hideDiff
|
|
167
|
-
? ''
|
|
168
|
-
: '
|
|
166
|
+
!Base.hideDiff && Base.showDiff(err)
|
|
167
|
+
? '\n' + Base.generateDiff(err.actual, err.expected)
|
|
168
|
+
: '';
|
|
169
169
|
this.write(
|
|
170
170
|
tag(
|
|
171
171
|
'testcase',
|