mocha 6.2.3 → 7.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 +102 -1347
- package/LICENSE +1 -1
- package/README.md +6 -6
- package/bin/mocha +12 -41
- package/browser-entry.js +2 -2
- package/lib/cli/config.js +2 -1
- package/lib/cli/node-flags.js +1 -1
- package/lib/cli/one-and-dones.js +2 -2
- package/lib/cli/options.js +4 -35
- package/lib/cli/run-helpers.js +12 -10
- package/lib/cli/run-option-metadata.js +6 -5
- package/lib/cli/run.js +32 -14
- package/lib/cli/watch-run.js +116 -31
- package/lib/esm-utils.js +31 -0
- package/lib/mocha.js +194 -103
- package/lib/mocharc.json +3 -2
- package/lib/reporters/base.js +15 -5
- package/lib/reporters/xunit.js +3 -3
- package/lib/runnable.js +26 -18
- package/lib/runner.js +99 -87
- package/lib/test.js +13 -0
- package/lib/utils.js +22 -74
- package/mocha.js +483 -452
- package/package.json +25 -504
- package/bin/options.js +0 -10
package/lib/esm-utils.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
const url = require('url');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
|
|
4
|
+
const requireOrImport = async file => {
|
|
5
|
+
file = path.resolve(file);
|
|
6
|
+
|
|
7
|
+
if (path.extname(file) === '.mjs') {
|
|
8
|
+
return import(url.pathToFileURL(file));
|
|
9
|
+
}
|
|
10
|
+
// This is currently the only known way of figuring out whether a file is CJS or ESM.
|
|
11
|
+
// If Node.js or the community establish a better procedure for that, we can fix this code.
|
|
12
|
+
// Another option here would be to always use `import()`, as this also supports CJS, but I would be
|
|
13
|
+
// wary of using it for _all_ existing test files, till ESM is fully stable.
|
|
14
|
+
try {
|
|
15
|
+
return require(file);
|
|
16
|
+
} catch (err) {
|
|
17
|
+
if (err.code === 'ERR_REQUIRE_ESM') {
|
|
18
|
+
return import(url.pathToFileURL(file));
|
|
19
|
+
} else {
|
|
20
|
+
throw err;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
exports.loadFilesAsync = async (files, preLoadFunc, postLoadFunc) => {
|
|
26
|
+
for (const file of files) {
|
|
27
|
+
preLoadFunc(file);
|
|
28
|
+
const result = await requireOrImport(file);
|
|
29
|
+
postLoadFunc(file, result);
|
|
30
|
+
}
|
|
31
|
+
};
|
package/lib/mocha.js
CHANGED
|
@@ -14,6 +14,7 @@ var utils = require('./utils');
|
|
|
14
14
|
var mocharc = require('./mocharc.json');
|
|
15
15
|
var errors = require('./errors');
|
|
16
16
|
var Suite = require('./suite');
|
|
17
|
+
var esmUtils = utils.supportsEsModules() ? require('./esm-utils') : undefined;
|
|
17
18
|
var createStatsCollector = require('./stats-collector');
|
|
18
19
|
var createInvalidReporterError = errors.createInvalidReporterError;
|
|
19
20
|
var createInvalidInterfaceError = errors.createInvalidInterfaceError;
|
|
@@ -69,18 +70,18 @@ exports.Test = require('./test');
|
|
|
69
70
|
* @param {boolean} [options.allowUncaught] - Propagate uncaught errors?
|
|
70
71
|
* @param {boolean} [options.asyncOnly] - Force `done` callback or promise?
|
|
71
72
|
* @param {boolean} [options.bail] - Bail after first test failure?
|
|
72
|
-
* @param {boolean} [options.checkLeaks] -
|
|
73
|
+
* @param {boolean} [options.checkLeaks] - Check for global variable leaks?
|
|
74
|
+
* @param {boolean} [options.color] - Color TTY output from reporter?
|
|
73
75
|
* @param {boolean} [options.delay] - Delay root suite execution?
|
|
74
|
-
* @param {boolean} [options.
|
|
76
|
+
* @param {boolean} [options.diff] - Show diff on failure?
|
|
75
77
|
* @param {string} [options.fgrep] - Test filter given string.
|
|
76
78
|
* @param {boolean} [options.forbidOnly] - Tests marked `only` fail the suite?
|
|
77
79
|
* @param {boolean} [options.forbidPending] - Pending tests fail the suite?
|
|
78
|
-
* @param {boolean} [options.
|
|
80
|
+
* @param {boolean} [options.fullTrace] - Full stacktrace upon failure?
|
|
79
81
|
* @param {string[]} [options.global] - Variables expected in global scope.
|
|
80
82
|
* @param {RegExp|string} [options.grep] - Test filter given regular expression.
|
|
81
83
|
* @param {boolean} [options.growl] - Enable desktop notifications?
|
|
82
|
-
* @param {boolean} [options.
|
|
83
|
-
* @param {boolean} [options.ignoreLeaks] - Ignore global leaks?
|
|
84
|
+
* @param {boolean} [options.inlineDiffs] - Display inline diffs?
|
|
84
85
|
* @param {boolean} [options.invert] - Invert test filter matches?
|
|
85
86
|
* @param {boolean} [options.noHighlighting] - Disable syntax highlighting?
|
|
86
87
|
* @param {string|constructor} [options.reporter] - Reporter name or constructor.
|
|
@@ -89,8 +90,6 @@ exports.Test = require('./test');
|
|
|
89
90
|
* @param {number} [options.slow] - Slow threshold value.
|
|
90
91
|
* @param {number|string} [options.timeout] - Timeout threshold value.
|
|
91
92
|
* @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
93
|
*/
|
|
95
94
|
function Mocha(options) {
|
|
96
95
|
options = utils.assign({}, mocharc, options || {});
|
|
@@ -99,35 +98,15 @@ function Mocha(options) {
|
|
|
99
98
|
// root suite
|
|
100
99
|
this.suite = new exports.Suite('', new exports.Context(), true);
|
|
101
100
|
|
|
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
101
|
this.grep(options.grep)
|
|
114
102
|
.fgrep(options.fgrep)
|
|
115
103
|
.ui(options.ui)
|
|
116
|
-
.
|
|
117
|
-
|
|
118
|
-
|
|
104
|
+
.reporter(
|
|
105
|
+
options.reporter,
|
|
106
|
+
options.reporterOption || options.reporterOptions // reporterOptions was previously the only way to specify options to reporter
|
|
107
|
+
)
|
|
119
108
|
.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
|
-
}
|
|
109
|
+
.global(options.global);
|
|
131
110
|
|
|
132
111
|
// this guard exists because Suite#timeout does not consider `undefined` to be valid input
|
|
133
112
|
if (typeof options.timeout !== 'undefined') {
|
|
@@ -138,19 +117,19 @@ function Mocha(options) {
|
|
|
138
117
|
this.retries(options.retries);
|
|
139
118
|
}
|
|
140
119
|
|
|
141
|
-
if ('diff' in options) {
|
|
142
|
-
this.hideDiff(!options.diff);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
120
|
[
|
|
146
121
|
'allowUncaught',
|
|
147
122
|
'asyncOnly',
|
|
123
|
+
'bail',
|
|
148
124
|
'checkLeaks',
|
|
125
|
+
'color',
|
|
149
126
|
'delay',
|
|
127
|
+
'diff',
|
|
150
128
|
'forbidOnly',
|
|
151
129
|
'forbidPending',
|
|
152
130
|
'fullTrace',
|
|
153
131
|
'growl',
|
|
132
|
+
'inlineDiffs',
|
|
154
133
|
'invert'
|
|
155
134
|
].forEach(function(opt) {
|
|
156
135
|
if (options[opt]) {
|
|
@@ -163,16 +142,13 @@ function Mocha(options) {
|
|
|
163
142
|
* Enables or disables bailing on the first failure.
|
|
164
143
|
*
|
|
165
144
|
* @public
|
|
166
|
-
* @see
|
|
145
|
+
* @see [CLI option](../#-bail-b)
|
|
167
146
|
* @param {boolean} [bail=true] - Whether to bail on first error.
|
|
168
147
|
* @returns {Mocha} this
|
|
169
148
|
* @chainable
|
|
170
149
|
*/
|
|
171
150
|
Mocha.prototype.bail = function(bail) {
|
|
172
|
-
|
|
173
|
-
bail = true;
|
|
174
|
-
}
|
|
175
|
-
this.suite.bail(bail);
|
|
151
|
+
this.suite.bail(bail !== false);
|
|
176
152
|
return this;
|
|
177
153
|
};
|
|
178
154
|
|
|
@@ -184,7 +160,7 @@ Mocha.prototype.bail = function(bail) {
|
|
|
184
160
|
* Useful for generic setup code that must be included within test suite.
|
|
185
161
|
*
|
|
186
162
|
* @public
|
|
187
|
-
* @see
|
|
163
|
+
* @see [CLI option](../#-file-filedirectoryglob)
|
|
188
164
|
* @param {string} file - Pathname of file to be loaded.
|
|
189
165
|
* @returns {Mocha} this
|
|
190
166
|
* @chainable
|
|
@@ -198,8 +174,8 @@ Mocha.prototype.addFile = function(file) {
|
|
|
198
174
|
* Sets reporter to `reporter`, defaults to "spec".
|
|
199
175
|
*
|
|
200
176
|
* @public
|
|
201
|
-
* @see
|
|
202
|
-
* @see
|
|
177
|
+
* @see [CLI option](../#-reporter-name-r-name)
|
|
178
|
+
* @see [Reporters](../#reporters)
|
|
203
179
|
* @param {String|Function} reporter - Reporter name or constructor.
|
|
204
180
|
* @param {Object} [reporterOptions] - Options used to configure the reporter.
|
|
205
181
|
* @returns {Mocha} this
|
|
@@ -257,6 +233,8 @@ Mocha.prototype.reporter = function(reporter, reporterOptions) {
|
|
|
257
233
|
}
|
|
258
234
|
this._reporter = _reporter;
|
|
259
235
|
}
|
|
236
|
+
this.options.reporterOption = reporterOptions;
|
|
237
|
+
// alias option name is used in public reporters xunit/tap/progress
|
|
260
238
|
this.options.reporterOptions = reporterOptions;
|
|
261
239
|
return this;
|
|
262
240
|
};
|
|
@@ -265,8 +243,8 @@ Mocha.prototype.reporter = function(reporter, reporterOptions) {
|
|
|
265
243
|
* Sets test UI `name`, defaults to "bdd".
|
|
266
244
|
*
|
|
267
245
|
* @public
|
|
268
|
-
* @see
|
|
269
|
-
* @see
|
|
246
|
+
* @see [CLI option](../#-ui-name-u-name)
|
|
247
|
+
* @see [Interface DSLs](../#interfaces)
|
|
270
248
|
* @param {string|Function} [ui=bdd] - Interface name or class.
|
|
271
249
|
* @returns {Mocha} this
|
|
272
250
|
* @chainable
|
|
@@ -313,16 +291,18 @@ Mocha.prototype.ui = function(ui) {
|
|
|
313
291
|
};
|
|
314
292
|
|
|
315
293
|
/**
|
|
316
|
-
* Loads `files` prior to execution.
|
|
294
|
+
* Loads `files` prior to execution. Does not support ES Modules.
|
|
317
295
|
*
|
|
318
296
|
* @description
|
|
319
297
|
* The implementation relies on Node's `require` to execute
|
|
320
298
|
* the test interface functions and will be subject to its cache.
|
|
299
|
+
* Supports only CommonJS modules. To load ES modules, use Mocha#loadFilesAsync.
|
|
321
300
|
*
|
|
322
301
|
* @private
|
|
323
302
|
* @see {@link Mocha#addFile}
|
|
324
303
|
* @see {@link Mocha#run}
|
|
325
304
|
* @see {@link Mocha#unloadFiles}
|
|
305
|
+
* @see {@link Mocha#loadFilesAsync}
|
|
326
306
|
* @param {Function} [fn] - Callback invoked upon completion.
|
|
327
307
|
*/
|
|
328
308
|
Mocha.prototype.loadFiles = function(fn) {
|
|
@@ -337,6 +317,49 @@ Mocha.prototype.loadFiles = function(fn) {
|
|
|
337
317
|
fn && fn();
|
|
338
318
|
};
|
|
339
319
|
|
|
320
|
+
/**
|
|
321
|
+
* Loads `files` prior to execution. Supports Node ES Modules.
|
|
322
|
+
*
|
|
323
|
+
* @description
|
|
324
|
+
* The implementation relies on Node's `require` and `import` to execute
|
|
325
|
+
* the test interface functions and will be subject to its cache.
|
|
326
|
+
* Supports both CJS and ESM modules.
|
|
327
|
+
*
|
|
328
|
+
* @public
|
|
329
|
+
* @see {@link Mocha#addFile}
|
|
330
|
+
* @see {@link Mocha#run}
|
|
331
|
+
* @see {@link Mocha#unloadFiles}
|
|
332
|
+
* @returns {Promise}
|
|
333
|
+
* @example
|
|
334
|
+
*
|
|
335
|
+
* // loads ESM (and CJS) test files asynchronously, then runs root suite
|
|
336
|
+
* mocha.loadFilesAsync()
|
|
337
|
+
* .then(() => mocha.run(failures => process.exitCode = failures ? 1 : 0))
|
|
338
|
+
* .catch(() => process.exitCode = 1);
|
|
339
|
+
*/
|
|
340
|
+
Mocha.prototype.loadFilesAsync = function() {
|
|
341
|
+
var self = this;
|
|
342
|
+
var suite = this.suite;
|
|
343
|
+
this.loadAsync = true;
|
|
344
|
+
|
|
345
|
+
if (!esmUtils) {
|
|
346
|
+
return new Promise(function(resolve) {
|
|
347
|
+
self.loadFiles(resolve);
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
return esmUtils.loadFilesAsync(
|
|
352
|
+
this.files,
|
|
353
|
+
function(file) {
|
|
354
|
+
suite.emit(EVENT_FILE_PRE_REQUIRE, global, file, self);
|
|
355
|
+
},
|
|
356
|
+
function(file, resultModule) {
|
|
357
|
+
suite.emit(EVENT_FILE_REQUIRE, resultModule, file, self);
|
|
358
|
+
suite.emit(EVENT_FILE_POST_REQUIRE, global, file, self);
|
|
359
|
+
}
|
|
360
|
+
);
|
|
361
|
+
};
|
|
362
|
+
|
|
340
363
|
/**
|
|
341
364
|
* Removes a previously loaded file from Node's `require` cache.
|
|
342
365
|
*
|
|
@@ -353,14 +376,13 @@ Mocha.unloadFile = function(file) {
|
|
|
353
376
|
* Unloads `files` from Node's `require` cache.
|
|
354
377
|
*
|
|
355
378
|
* @description
|
|
356
|
-
* This allows files to be "freshly" reloaded, providing the ability
|
|
379
|
+
* This allows required files to be "freshly" reloaded, providing the ability
|
|
357
380
|
* to reuse a Mocha instance programmatically.
|
|
381
|
+
* Note: does not clear ESM module files from the cache
|
|
358
382
|
*
|
|
359
383
|
* <strong>Intended for consumers — not used internally</strong>
|
|
360
384
|
*
|
|
361
385
|
* @public
|
|
362
|
-
* @see {@link Mocha.unloadFile}
|
|
363
|
-
* @see {@link Mocha#loadFiles}
|
|
364
386
|
* @see {@link Mocha#run}
|
|
365
387
|
* @returns {Mocha} this
|
|
366
388
|
* @chainable
|
|
@@ -404,7 +426,7 @@ Mocha.prototype.fgrep = function(str) {
|
|
|
404
426
|
* <strong>Previous filter value will be overwritten on each call!</strong>
|
|
405
427
|
*
|
|
406
428
|
* @public
|
|
407
|
-
* @see
|
|
429
|
+
* @see [CLI option](../#-grep-regexp-g-regexp)
|
|
408
430
|
* @see {@link Mocha#fgrep}
|
|
409
431
|
* @see {@link Mocha#invert}
|
|
410
432
|
* @param {RegExp|String} re - Regular expression used to select tests.
|
|
@@ -455,32 +477,32 @@ Mocha.prototype.invert = function() {
|
|
|
455
477
|
/**
|
|
456
478
|
* Enables or disables ignoring global leaks.
|
|
457
479
|
*
|
|
480
|
+
* @deprecated since v7.0.0
|
|
458
481
|
* @public
|
|
459
482
|
* @see {@link Mocha#checkLeaks}
|
|
460
|
-
* @param {boolean} ignoreLeaks - Whether to ignore global leaks.
|
|
483
|
+
* @param {boolean} [ignoreLeaks=false] - Whether to ignore global leaks.
|
|
461
484
|
* @return {Mocha} this
|
|
462
485
|
* @chainable
|
|
463
|
-
* @example
|
|
464
|
-
*
|
|
465
|
-
* // Ignore global leaks
|
|
466
|
-
* mocha.ignoreLeaks(true);
|
|
467
486
|
*/
|
|
468
487
|
Mocha.prototype.ignoreLeaks = function(ignoreLeaks) {
|
|
469
|
-
|
|
488
|
+
utils.deprecate(
|
|
489
|
+
'"ignoreLeaks()" is DEPRECATED, please use "checkLeaks()" instead.'
|
|
490
|
+
);
|
|
491
|
+
this.options.checkLeaks = !ignoreLeaks;
|
|
470
492
|
return this;
|
|
471
493
|
};
|
|
472
494
|
|
|
473
495
|
/**
|
|
474
|
-
* Enables checking for global variables leaked while running tests.
|
|
496
|
+
* Enables or disables checking for global variables leaked while running tests.
|
|
475
497
|
*
|
|
476
498
|
* @public
|
|
477
|
-
* @see
|
|
478
|
-
* @
|
|
499
|
+
* @see [CLI option](../#-check-leaks)
|
|
500
|
+
* @param {boolean} [checkLeaks=true] - Whether to check for global variable leaks.
|
|
479
501
|
* @return {Mocha} this
|
|
480
502
|
* @chainable
|
|
481
503
|
*/
|
|
482
|
-
Mocha.prototype.checkLeaks = function() {
|
|
483
|
-
this.options.
|
|
504
|
+
Mocha.prototype.checkLeaks = function(checkLeaks) {
|
|
505
|
+
this.options.checkLeaks = checkLeaks !== false;
|
|
484
506
|
return this;
|
|
485
507
|
};
|
|
486
508
|
|
|
@@ -488,11 +510,13 @@ Mocha.prototype.checkLeaks = function() {
|
|
|
488
510
|
* Displays full stack trace upon test failure.
|
|
489
511
|
*
|
|
490
512
|
* @public
|
|
513
|
+
* @see [CLI option](../#-full-trace)
|
|
514
|
+
* @param {boolean} [fullTrace=true] - Whether to print full stacktrace upon failure.
|
|
491
515
|
* @return {Mocha} this
|
|
492
516
|
* @chainable
|
|
493
517
|
*/
|
|
494
|
-
Mocha.prototype.fullTrace = function() {
|
|
495
|
-
this.options.
|
|
518
|
+
Mocha.prototype.fullTrace = function(fullTrace) {
|
|
519
|
+
this.options.fullTrace = fullTrace !== false;
|
|
496
520
|
return this;
|
|
497
521
|
};
|
|
498
522
|
|
|
@@ -500,8 +524,7 @@ Mocha.prototype.fullTrace = function() {
|
|
|
500
524
|
* Enables desktop notification support if prerequisite software installed.
|
|
501
525
|
*
|
|
502
526
|
* @public
|
|
503
|
-
* @see
|
|
504
|
-
* @see {@link Mocha#_growl}
|
|
527
|
+
* @see [CLI option](../#-growl-g)
|
|
505
528
|
* @return {Mocha} this
|
|
506
529
|
* @chainable
|
|
507
530
|
*/
|
|
@@ -544,65 +567,121 @@ Mocha.prototype._growl = growl.notify;
|
|
|
544
567
|
* Specifies whitelist of variable names to be expected in global scope.
|
|
545
568
|
*
|
|
546
569
|
* @public
|
|
547
|
-
* @see
|
|
570
|
+
* @see [CLI option](../#-global-variable-name)
|
|
548
571
|
* @see {@link Mocha#checkLeaks}
|
|
549
|
-
* @param {String[]|String}
|
|
572
|
+
* @param {String[]|String} global - Accepted global variable name(s).
|
|
550
573
|
* @return {Mocha} this
|
|
551
574
|
* @chainable
|
|
552
575
|
* @example
|
|
553
576
|
*
|
|
554
577
|
* // Specify variables to be expected in global scope
|
|
555
|
-
* mocha.
|
|
578
|
+
* mocha.global(['jQuery', 'MyLib']);
|
|
556
579
|
*/
|
|
557
|
-
Mocha.prototype.
|
|
558
|
-
this.options.
|
|
559
|
-
.concat(
|
|
580
|
+
Mocha.prototype.global = function(global) {
|
|
581
|
+
this.options.global = (this.options.global || [])
|
|
582
|
+
.concat(global)
|
|
560
583
|
.filter(Boolean)
|
|
561
584
|
.filter(function(elt, idx, arr) {
|
|
562
585
|
return arr.indexOf(elt) === idx;
|
|
563
586
|
});
|
|
564
587
|
return this;
|
|
565
588
|
};
|
|
589
|
+
// for backwards compability, 'globals' is an alias of 'global'
|
|
590
|
+
Mocha.prototype.globals = Mocha.prototype.global;
|
|
566
591
|
|
|
567
592
|
/**
|
|
568
593
|
* Enables or disables TTY color output by screen-oriented reporters.
|
|
569
594
|
*
|
|
595
|
+
* @deprecated since v7.0.0
|
|
570
596
|
* @public
|
|
597
|
+
* @see {@link Mocha#color}
|
|
571
598
|
* @param {boolean} colors - Whether to enable color output.
|
|
572
599
|
* @return {Mocha} this
|
|
573
600
|
* @chainable
|
|
574
601
|
*/
|
|
575
602
|
Mocha.prototype.useColors = function(colors) {
|
|
603
|
+
utils.deprecate('"useColors()" is DEPRECATED, please use "color()" instead.');
|
|
576
604
|
if (colors !== undefined) {
|
|
577
|
-
this.options.
|
|
605
|
+
this.options.color = colors;
|
|
578
606
|
}
|
|
579
607
|
return this;
|
|
580
608
|
};
|
|
581
609
|
|
|
610
|
+
/**
|
|
611
|
+
* Enables or disables TTY color output by screen-oriented reporters.
|
|
612
|
+
*
|
|
613
|
+
* @public
|
|
614
|
+
* @see [CLI option](../#-color-c-colors)
|
|
615
|
+
* @param {boolean} [color=true] - Whether to enable color output.
|
|
616
|
+
* @return {Mocha} this
|
|
617
|
+
* @chainable
|
|
618
|
+
*/
|
|
619
|
+
Mocha.prototype.color = function(color) {
|
|
620
|
+
this.options.color = color !== false;
|
|
621
|
+
return this;
|
|
622
|
+
};
|
|
623
|
+
|
|
582
624
|
/**
|
|
583
625
|
* Determines if reporter should use inline diffs (rather than +/-)
|
|
584
626
|
* in test failure output.
|
|
585
627
|
*
|
|
628
|
+
* @deprecated since v7.0.0
|
|
586
629
|
* @public
|
|
587
|
-
* @
|
|
630
|
+
* @see {@link Mocha#inlineDiffs}
|
|
631
|
+
* @param {boolean} [inlineDiffs=false] - Whether to use inline diffs.
|
|
588
632
|
* @return {Mocha} this
|
|
589
633
|
* @chainable
|
|
590
634
|
*/
|
|
591
635
|
Mocha.prototype.useInlineDiffs = function(inlineDiffs) {
|
|
592
|
-
|
|
636
|
+
utils.deprecate(
|
|
637
|
+
'"useInlineDiffs()" is DEPRECATED, please use "inlineDiffs()" instead.'
|
|
638
|
+
);
|
|
639
|
+
this.options.inlineDiffs = inlineDiffs !== undefined && inlineDiffs;
|
|
640
|
+
return this;
|
|
641
|
+
};
|
|
642
|
+
|
|
643
|
+
/**
|
|
644
|
+
* Enables or disables reporter to use inline diffs (rather than +/-)
|
|
645
|
+
* in test failure output.
|
|
646
|
+
*
|
|
647
|
+
* @public
|
|
648
|
+
* @see [CLI option](../#-inline-diffs)
|
|
649
|
+
* @param {boolean} [inlineDiffs=true] - Whether to use inline diffs.
|
|
650
|
+
* @return {Mocha} this
|
|
651
|
+
* @chainable
|
|
652
|
+
*/
|
|
653
|
+
Mocha.prototype.inlineDiffs = function(inlineDiffs) {
|
|
654
|
+
this.options.inlineDiffs = inlineDiffs !== false;
|
|
593
655
|
return this;
|
|
594
656
|
};
|
|
595
657
|
|
|
596
658
|
/**
|
|
597
659
|
* Determines if reporter should include diffs in test failure output.
|
|
598
660
|
*
|
|
661
|
+
* @deprecated since v7.0.0
|
|
599
662
|
* @public
|
|
600
|
-
* @
|
|
663
|
+
* @see {@link Mocha#diff}
|
|
664
|
+
* @param {boolean} [hideDiff=false] - Whether to hide diffs.
|
|
601
665
|
* @return {Mocha} this
|
|
602
666
|
* @chainable
|
|
603
667
|
*/
|
|
604
668
|
Mocha.prototype.hideDiff = function(hideDiff) {
|
|
605
|
-
|
|
669
|
+
utils.deprecate('"hideDiff()" is DEPRECATED, please use "diff()" instead.');
|
|
670
|
+
this.options.diff = !(hideDiff === true);
|
|
671
|
+
return this;
|
|
672
|
+
};
|
|
673
|
+
|
|
674
|
+
/**
|
|
675
|
+
* Enables or disables reporter to include diff in test failure output.
|
|
676
|
+
*
|
|
677
|
+
* @public
|
|
678
|
+
* @see [CLI option](../#-diff)
|
|
679
|
+
* @param {boolean} [diff=true] - Whether to show diff on failure.
|
|
680
|
+
* @return {Mocha} this
|
|
681
|
+
* @chainable
|
|
682
|
+
*/
|
|
683
|
+
Mocha.prototype.diff = function(diff) {
|
|
684
|
+
this.options.diff = diff !== false;
|
|
606
685
|
return this;
|
|
607
686
|
};
|
|
608
687
|
|
|
@@ -615,8 +694,8 @@ Mocha.prototype.hideDiff = function(hideDiff) {
|
|
|
615
694
|
* If the value is `0`, timeouts will be disabled.
|
|
616
695
|
*
|
|
617
696
|
* @public
|
|
618
|
-
* @see
|
|
619
|
-
* @see
|
|
697
|
+
* @see [CLI option](../#-timeout-ms-t-ms)
|
|
698
|
+
* @see [Timeouts](../#timeouts)
|
|
620
699
|
* @see {@link Mocha#enableTimeouts}
|
|
621
700
|
* @param {number|string} msecs - Timeout threshold value.
|
|
622
701
|
* @return {Mocha} this
|
|
@@ -639,7 +718,8 @@ Mocha.prototype.timeout = function(msecs) {
|
|
|
639
718
|
* Sets the number of times to retry failed tests.
|
|
640
719
|
*
|
|
641
720
|
* @public
|
|
642
|
-
* @see
|
|
721
|
+
* @see [CLI option](../#-retries-n)
|
|
722
|
+
* @see [Retry Tests](../#retry-tests)
|
|
643
723
|
* @param {number} retry - Number of times to retry failed tests.
|
|
644
724
|
* @return {Mocha} this
|
|
645
725
|
* @chainable
|
|
@@ -657,7 +737,7 @@ Mocha.prototype.retries = function(n) {
|
|
|
657
737
|
* Sets slowness threshold value.
|
|
658
738
|
*
|
|
659
739
|
* @public
|
|
660
|
-
* @see
|
|
740
|
+
* @see [CLI option](../#-slow-ms-s-ms)
|
|
661
741
|
* @param {number} msecs - Slowness threshold value.
|
|
662
742
|
* @return {Mocha} this
|
|
663
743
|
* @chainable
|
|
@@ -679,7 +759,7 @@ Mocha.prototype.slow = function(msecs) {
|
|
|
679
759
|
* Enables or disables timeouts.
|
|
680
760
|
*
|
|
681
761
|
* @public
|
|
682
|
-
* @see
|
|
762
|
+
* @see [CLI option](../#-timeout-ms-t-ms)
|
|
683
763
|
* @param {boolean} enableTimeouts - Whether to enable timeouts.
|
|
684
764
|
* @return {Mocha} this
|
|
685
765
|
* @chainable
|
|
@@ -695,11 +775,13 @@ Mocha.prototype.enableTimeouts = function(enableTimeouts) {
|
|
|
695
775
|
* Forces all tests to either accept a `done` callback or return a promise.
|
|
696
776
|
*
|
|
697
777
|
* @public
|
|
778
|
+
* @see [CLI option](../#-async-only-a)
|
|
779
|
+
* @param {boolean} [asyncOnly=true] - Wether to force `done` callback or promise.
|
|
698
780
|
* @return {Mocha} this
|
|
699
781
|
* @chainable
|
|
700
782
|
*/
|
|
701
|
-
Mocha.prototype.asyncOnly = function() {
|
|
702
|
-
this.options.asyncOnly =
|
|
783
|
+
Mocha.prototype.asyncOnly = function(asyncOnly) {
|
|
784
|
+
this.options.asyncOnly = asyncOnly !== false;
|
|
703
785
|
return this;
|
|
704
786
|
};
|
|
705
787
|
|
|
@@ -716,14 +798,16 @@ Mocha.prototype.noHighlighting = function() {
|
|
|
716
798
|
};
|
|
717
799
|
|
|
718
800
|
/**
|
|
719
|
-
* Enables uncaught errors to propagate
|
|
801
|
+
* Enables or disables uncaught errors to propagate.
|
|
720
802
|
*
|
|
721
803
|
* @public
|
|
804
|
+
* @see [CLI option](../#-allow-uncaught)
|
|
805
|
+
* @param {boolean} [allowUncaught=true] - Whether to propagate uncaught errors.
|
|
722
806
|
* @return {Mocha} this
|
|
723
807
|
* @chainable
|
|
724
808
|
*/
|
|
725
|
-
Mocha.prototype.allowUncaught = function() {
|
|
726
|
-
this.options.allowUncaught =
|
|
809
|
+
Mocha.prototype.allowUncaught = function(allowUncaught) {
|
|
810
|
+
this.options.allowUncaught = allowUncaught !== false;
|
|
727
811
|
return this;
|
|
728
812
|
};
|
|
729
813
|
|
|
@@ -735,7 +819,7 @@ Mocha.prototype.allowUncaught = function() {
|
|
|
735
819
|
* Used to perform asynch operations before any suites are run.
|
|
736
820
|
*
|
|
737
821
|
* @public
|
|
738
|
-
* @see
|
|
822
|
+
* @see [delayed root suite](../#delayed-root-suite)
|
|
739
823
|
* @returns {Mocha} this
|
|
740
824
|
* @chainable
|
|
741
825
|
*/
|
|
@@ -748,11 +832,13 @@ Mocha.prototype.delay = function delay() {
|
|
|
748
832
|
* Causes tests marked `only` to fail the suite.
|
|
749
833
|
*
|
|
750
834
|
* @public
|
|
835
|
+
* @see [CLI option](../#-forbid-only)
|
|
836
|
+
* @param {boolean} [forbidOnly=true] - Whether tests marked `only` fail the suite.
|
|
751
837
|
* @returns {Mocha} this
|
|
752
838
|
* @chainable
|
|
753
839
|
*/
|
|
754
|
-
Mocha.prototype.forbidOnly = function() {
|
|
755
|
-
this.options.forbidOnly =
|
|
840
|
+
Mocha.prototype.forbidOnly = function(forbidOnly) {
|
|
841
|
+
this.options.forbidOnly = forbidOnly !== false;
|
|
756
842
|
return this;
|
|
757
843
|
};
|
|
758
844
|
|
|
@@ -760,11 +846,13 @@ Mocha.prototype.forbidOnly = function() {
|
|
|
760
846
|
* Causes pending tests and tests marked `skip` to fail the suite.
|
|
761
847
|
*
|
|
762
848
|
* @public
|
|
849
|
+
* @see [CLI option](../#-forbid-pending)
|
|
850
|
+
* @param {boolean} [forbidPending=true] - Whether pending tests fail the suite.
|
|
763
851
|
* @returns {Mocha} this
|
|
764
852
|
* @chainable
|
|
765
853
|
*/
|
|
766
|
-
Mocha.prototype.forbidPending = function() {
|
|
767
|
-
this.options.forbidPending =
|
|
854
|
+
Mocha.prototype.forbidPending = function(forbidPending) {
|
|
855
|
+
this.options.forbidPending = forbidPending !== false;
|
|
768
856
|
return this;
|
|
769
857
|
};
|
|
770
858
|
|
|
@@ -798,14 +886,17 @@ Object.defineProperty(Mocha.prototype, 'version', {
|
|
|
798
886
|
* the cache first!
|
|
799
887
|
*
|
|
800
888
|
* @public
|
|
801
|
-
* @see {@link Mocha#loadFiles}
|
|
802
889
|
* @see {@link Mocha#unloadFiles}
|
|
803
890
|
* @see {@link Runner#run}
|
|
804
891
|
* @param {DoneCB} [fn] - Callback invoked when test execution completed.
|
|
805
|
-
* @
|
|
892
|
+
* @returns {Runner} runner instance
|
|
893
|
+
* @example
|
|
894
|
+
*
|
|
895
|
+
* // exit with non-zero status if there were test failures
|
|
896
|
+
* mocha.run(failures => process.exitCode = failures ? 1 : 0);
|
|
806
897
|
*/
|
|
807
898
|
Mocha.prototype.run = function(fn) {
|
|
808
|
-
if (this.files.length) {
|
|
899
|
+
if (this.files.length && !this.loadAsync) {
|
|
809
900
|
this.loadFiles();
|
|
810
901
|
}
|
|
811
902
|
var suite = this.suite;
|
|
@@ -814,8 +905,8 @@ Mocha.prototype.run = function(fn) {
|
|
|
814
905
|
var runner = new exports.Runner(suite, options.delay);
|
|
815
906
|
createStatsCollector(runner);
|
|
816
907
|
var reporter = new this._reporter(runner, options);
|
|
817
|
-
runner.
|
|
818
|
-
runner.fullStackTrace = options.
|
|
908
|
+
runner.checkLeaks = options.checkLeaks === true;
|
|
909
|
+
runner.fullStackTrace = options.fullTrace;
|
|
819
910
|
runner.asyncOnly = options.asyncOnly;
|
|
820
911
|
runner.allowUncaught = options.allowUncaught;
|
|
821
912
|
runner.forbidOnly = options.forbidOnly;
|
|
@@ -823,17 +914,17 @@ Mocha.prototype.run = function(fn) {
|
|
|
823
914
|
if (options.grep) {
|
|
824
915
|
runner.grep(options.grep, options.invert);
|
|
825
916
|
}
|
|
826
|
-
if (options.
|
|
827
|
-
runner.globals(options.
|
|
917
|
+
if (options.global) {
|
|
918
|
+
runner.globals(options.global);
|
|
828
919
|
}
|
|
829
920
|
if (options.growl) {
|
|
830
921
|
this._growl(runner);
|
|
831
922
|
}
|
|
832
|
-
if (options.
|
|
833
|
-
exports.reporters.Base.useColors = options.
|
|
923
|
+
if (options.color !== undefined) {
|
|
924
|
+
exports.reporters.Base.useColors = options.color;
|
|
834
925
|
}
|
|
835
|
-
exports.reporters.Base.inlineDiffs = options.
|
|
836
|
-
exports.reporters.Base.hideDiff = options.
|
|
926
|
+
exports.reporters.Base.inlineDiffs = options.inlineDiffs;
|
|
927
|
+
exports.reporters.Base.hideDiff = !options.diff;
|
|
837
928
|
|
|
838
929
|
function done(failures) {
|
|
839
930
|
fn = fn || utils.noop;
|
package/lib/mocharc.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"diff": true,
|
|
3
|
-
"extension": ["js"],
|
|
3
|
+
"extension": ["js", "cjs", "mjs"],
|
|
4
4
|
"opts": "./test/mocha.opts",
|
|
5
5
|
"package": "./package.json",
|
|
6
6
|
"reporter": "spec",
|
|
7
7
|
"slow": 75,
|
|
8
8
|
"timeout": 2000,
|
|
9
|
-
"ui": "bdd"
|
|
9
|
+
"ui": "bdd",
|
|
10
|
+
"watch-ignore": ["node_modules", ".git"]
|
|
10
11
|
}
|