mocha 7.0.0-esm1 → 7.1.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 +50 -1355
- package/LICENSE +1 -1
- package/README.md +1 -1
- package/browser-entry.js +2 -2
- package/lib/cli/run-helpers.js +6 -13
- package/lib/cli/run.js +1 -2
- package/lib/esm-utils.js +3 -7
- package/lib/mocha.js +25 -50
- package/lib/runnable.js +10 -1
- package/lib/runner.js +35 -52
- package/lib/test.js +13 -0
- package/lib/utils.js +10 -31
- package/mocha.js +95 -136
- package/package.json +15 -516
package/mocha.js
CHANGED
|
@@ -62,7 +62,7 @@ process.on = function(e, fn) {
|
|
|
62
62
|
if (e === 'uncaughtException') {
|
|
63
63
|
global.onerror = function(err, url, line) {
|
|
64
64
|
fn(new Error(err + ' (' + url + ':' + line + ')'));
|
|
65
|
-
return !mocha.allowUncaught;
|
|
65
|
+
return !mocha.options.allowUncaught;
|
|
66
66
|
};
|
|
67
67
|
uncaughtExceptionHandlers.push(fn);
|
|
68
68
|
}
|
|
@@ -131,7 +131,7 @@ mocha.setup = function(opts) {
|
|
|
131
131
|
opts = {ui: opts};
|
|
132
132
|
}
|
|
133
133
|
for (var opt in opts) {
|
|
134
|
-
if (
|
|
134
|
+
if (Object.prototype.hasOwnProperty.call(opts, opt)) {
|
|
135
135
|
this[opt](opts[opt]);
|
|
136
136
|
}
|
|
137
137
|
}
|
|
@@ -1495,7 +1495,10 @@ function Mocha(options) {
|
|
|
1495
1495
|
this.grep(options.grep)
|
|
1496
1496
|
.fgrep(options.fgrep)
|
|
1497
1497
|
.ui(options.ui)
|
|
1498
|
-
.reporter(
|
|
1498
|
+
.reporter(
|
|
1499
|
+
options.reporter,
|
|
1500
|
+
options.reporterOption || options.reporterOptions // reporterOptions was previously the only way to specify options to reporter
|
|
1501
|
+
)
|
|
1499
1502
|
.slow(options.slow)
|
|
1500
1503
|
.global(options.global);
|
|
1501
1504
|
|
|
@@ -1716,16 +1719,22 @@ Mocha.prototype.loadFiles = function(fn) {
|
|
|
1716
1719
|
* the test interface functions and will be subject to its cache.
|
|
1717
1720
|
* Supports both CJS and ESM modules.
|
|
1718
1721
|
*
|
|
1719
|
-
* @
|
|
1722
|
+
* @public
|
|
1720
1723
|
* @see {@link Mocha#addFile}
|
|
1721
1724
|
* @see {@link Mocha#run}
|
|
1722
1725
|
* @see {@link Mocha#unloadFiles}
|
|
1723
|
-
*
|
|
1724
1726
|
* @returns {Promise}
|
|
1727
|
+
* @example
|
|
1728
|
+
*
|
|
1729
|
+
* // loads ESM (and CJS) test files asynchronously, then runs root suite
|
|
1730
|
+
* mocha.loadFilesAsync()
|
|
1731
|
+
* .then(() => mocha.run(failures => process.exitCode = failures ? 1 : 0))
|
|
1732
|
+
* .catch(() => process.exitCode = 1);
|
|
1725
1733
|
*/
|
|
1726
1734
|
Mocha.prototype.loadFilesAsync = function() {
|
|
1727
1735
|
var self = this;
|
|
1728
1736
|
var suite = this.suite;
|
|
1737
|
+
this.loadAsync = true;
|
|
1729
1738
|
|
|
1730
1739
|
if (!esmUtils) {
|
|
1731
1740
|
return new Promise(function(resolve) {
|
|
@@ -1761,8 +1770,9 @@ Mocha.unloadFile = function(file) {
|
|
|
1761
1770
|
* Unloads `files` from Node's `require` cache.
|
|
1762
1771
|
*
|
|
1763
1772
|
* @description
|
|
1764
|
-
* This allows files to be "freshly" reloaded, providing the ability
|
|
1773
|
+
* This allows required files to be "freshly" reloaded, providing the ability
|
|
1765
1774
|
* to reuse a Mocha instance programmatically.
|
|
1775
|
+
* Note: does not clear ESM module files from the cache
|
|
1766
1776
|
*
|
|
1767
1777
|
* <strong>Intended for consumers — not used internally</strong>
|
|
1768
1778
|
*
|
|
@@ -2269,31 +2279,26 @@ Object.defineProperty(Mocha.prototype, 'version', {
|
|
|
2269
2279
|
* already in the `require` cache), make sure to clear them from
|
|
2270
2280
|
* the cache first!
|
|
2271
2281
|
*
|
|
2272
|
-
* This method supports only CommonJS test files, and not ES modules ones.
|
|
2273
|
-
* To use ES module (and CommonJS) test files, call Mocha#runAsync instead.
|
|
2274
|
-
*
|
|
2275
2282
|
* @public
|
|
2276
|
-
* @see {@link Mocha#runAsync}
|
|
2277
2283
|
* @see {@link Mocha#unloadFiles}
|
|
2278
2284
|
* @see {@link Runner#run}
|
|
2279
2285
|
* @param {DoneCB} [fn] - Callback invoked when test execution completed.
|
|
2280
|
-
* @
|
|
2286
|
+
* @returns {Runner} runner instance
|
|
2287
|
+
* @example
|
|
2288
|
+
*
|
|
2289
|
+
* // exit with non-zero status if there were test failures
|
|
2290
|
+
* mocha.run(failures => process.exitCode = failures ? 1 : 0);
|
|
2281
2291
|
*/
|
|
2282
2292
|
Mocha.prototype.run = function(fn) {
|
|
2283
|
-
if (this.files.length) {
|
|
2293
|
+
if (this.files.length && !this.loadAsync) {
|
|
2284
2294
|
this.loadFiles();
|
|
2285
2295
|
}
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
Mocha.prototype._startRunning = function(fn) {
|
|
2290
|
-
var self = this;
|
|
2291
|
-
var suite = self.suite;
|
|
2292
|
-
var options = self.options;
|
|
2293
|
-
options.files = self.files;
|
|
2296
|
+
var suite = this.suite;
|
|
2297
|
+
var options = this.options;
|
|
2298
|
+
options.files = this.files;
|
|
2294
2299
|
var runner = new exports.Runner(suite, options.delay);
|
|
2295
2300
|
createStatsCollector(runner);
|
|
2296
|
-
var reporter = new
|
|
2301
|
+
var reporter = new this._reporter(runner, options);
|
|
2297
2302
|
runner.checkLeaks = options.checkLeaks === true;
|
|
2298
2303
|
runner.fullStackTrace = options.fullTrace;
|
|
2299
2304
|
runner.asyncOnly = options.asyncOnly;
|
|
@@ -2307,7 +2312,7 @@ Mocha.prototype._startRunning = function(fn) {
|
|
|
2307
2312
|
runner.globals(options.global);
|
|
2308
2313
|
}
|
|
2309
2314
|
if (options.growl) {
|
|
2310
|
-
|
|
2315
|
+
this._growl(runner);
|
|
2311
2316
|
}
|
|
2312
2317
|
if (options.color !== undefined) {
|
|
2313
2318
|
exports.reporters.Base.useColors = options.color;
|
|
@@ -2327,36 +2332,6 @@ Mocha.prototype._startRunning = function(fn) {
|
|
|
2327
2332
|
return runner.run(done);
|
|
2328
2333
|
};
|
|
2329
2334
|
|
|
2330
|
-
/**
|
|
2331
|
-
* Runs root suite and invokes `fn()` when complete. Supports ES Modules.
|
|
2332
|
-
*
|
|
2333
|
-
* @description
|
|
2334
|
-
* To run tests multiple times (or to run tests in files that are
|
|
2335
|
-
* already in the `require` cache), make sure to clear them from
|
|
2336
|
-
* the cache first!
|
|
2337
|
-
*
|
|
2338
|
-
* This method supports both ES Modules and CommonJS test files.
|
|
2339
|
-
*
|
|
2340
|
-
* @public
|
|
2341
|
-
* @see {@link Mocha#unloadFiles}
|
|
2342
|
-
* @see {@link Runner#run}
|
|
2343
|
-
* @return {Promise<Runner>} runner instance
|
|
2344
|
-
*/
|
|
2345
|
-
Mocha.prototype.runAsync = function() {
|
|
2346
|
-
var loadResult = this.files.length
|
|
2347
|
-
? this.loadFilesAsync()
|
|
2348
|
-
: Promise.resolve();
|
|
2349
|
-
|
|
2350
|
-
var self = this;
|
|
2351
|
-
return loadResult.then(function() {
|
|
2352
|
-
return new Promise(function(resolve) {
|
|
2353
|
-
self._startRunning(function(result) {
|
|
2354
|
-
resolve(result);
|
|
2355
|
-
});
|
|
2356
|
-
});
|
|
2357
|
-
});
|
|
2358
|
-
};
|
|
2359
|
-
|
|
2360
2335
|
}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
|
2361
2336
|
},{"../package.json":90,"./context":5,"./errors":6,"./esm-utils":42,"./growl":2,"./hook":7,"./interfaces":11,"./mocharc.json":15,"./reporters":21,"./runnable":33,"./runner":34,"./stats-collector":35,"./suite":36,"./test":37,"./utils":38,"_process":69,"escape-string-regexp":49,"path":42}],15:[function(require,module,exports){
|
|
2362
2337
|
module.exports={
|
|
@@ -5448,9 +5423,18 @@ Runnable.prototype.run = function(fn) {
|
|
|
5448
5423
|
fn(err);
|
|
5449
5424
|
}
|
|
5450
5425
|
|
|
5451
|
-
// for .resetTimeout()
|
|
5426
|
+
// for .resetTimeout() and Runner#uncaught()
|
|
5452
5427
|
this.callback = done;
|
|
5453
5428
|
|
|
5429
|
+
if (this.fn && typeof this.fn.call !== 'function') {
|
|
5430
|
+
done(
|
|
5431
|
+
new TypeError(
|
|
5432
|
+
'A runnable must be passed a function as its second argument.'
|
|
5433
|
+
)
|
|
5434
|
+
);
|
|
5435
|
+
return;
|
|
5436
|
+
}
|
|
5437
|
+
|
|
5454
5438
|
// explicit async with `done` argument
|
|
5455
5439
|
if (this.async) {
|
|
5456
5440
|
this.resetTimeout();
|
|
@@ -5747,6 +5731,11 @@ function Runner(suite, delay) {
|
|
|
5747
5731
|
this.total = suite.total();
|
|
5748
5732
|
this.failures = 0;
|
|
5749
5733
|
this.on(constants.EVENT_TEST_END, function(test) {
|
|
5734
|
+
if (test.retriedTest() && test.parent) {
|
|
5735
|
+
var idx =
|
|
5736
|
+
test.parent.tests && test.parent.tests.indexOf(test.retriedTest());
|
|
5737
|
+
if (idx > -1) test.parent.tests[idx] = test;
|
|
5738
|
+
}
|
|
5750
5739
|
self.checkGlobals(test);
|
|
5751
5740
|
});
|
|
5752
5741
|
this.on(constants.EVENT_HOOK_END, function(hook) {
|
|
@@ -6266,7 +6255,7 @@ Runner.prototype.runTests = function(suite, fn) {
|
|
|
6266
6255
|
self.emit(constants.EVENT_TEST_END, test);
|
|
6267
6256
|
// skip inner afterEach hooks below errSuite level
|
|
6268
6257
|
var origSuite = self.suite;
|
|
6269
|
-
self.suite = errSuite;
|
|
6258
|
+
self.suite = errSuite || self.suite;
|
|
6270
6259
|
return self.hookUp(HOOK_TYPE_AFTER_EACH, function(e, eSuite) {
|
|
6271
6260
|
self.suite = origSuite;
|
|
6272
6261
|
next(e, eSuite);
|
|
@@ -6336,7 +6325,6 @@ Runner.prototype.runSuite = function(suite, fn) {
|
|
|
6336
6325
|
var i = 0;
|
|
6337
6326
|
var self = this;
|
|
6338
6327
|
var total = this.grepTotal(suite);
|
|
6339
|
-
var afterAllHookCalled = false;
|
|
6340
6328
|
|
|
6341
6329
|
debug('run suite %s', suite.fullTitle());
|
|
6342
6330
|
|
|
@@ -6384,21 +6372,13 @@ Runner.prototype.runSuite = function(suite, fn) {
|
|
|
6384
6372
|
self.suite = suite;
|
|
6385
6373
|
self.nextSuite = next;
|
|
6386
6374
|
|
|
6387
|
-
|
|
6388
|
-
|
|
6389
|
-
} else {
|
|
6390
|
-
// mark that the afterAll block has been called once
|
|
6391
|
-
// and so can be skipped if there is an error in it.
|
|
6392
|
-
afterAllHookCalled = true;
|
|
6393
|
-
|
|
6394
|
-
// remove reference to test
|
|
6395
|
-
delete self.test;
|
|
6375
|
+
// remove reference to test
|
|
6376
|
+
delete self.test;
|
|
6396
6377
|
|
|
6397
|
-
|
|
6398
|
-
|
|
6399
|
-
|
|
6400
|
-
|
|
6401
|
-
}
|
|
6378
|
+
self.hook(HOOK_TYPE_AFTER_ALL, function() {
|
|
6379
|
+
self.emit(constants.EVENT_SUITE_END, suite);
|
|
6380
|
+
fn(errSuite);
|
|
6381
|
+
});
|
|
6402
6382
|
}
|
|
6403
6383
|
|
|
6404
6384
|
this.nextSuite = next;
|
|
@@ -6412,7 +6392,7 @@ Runner.prototype.runSuite = function(suite, fn) {
|
|
|
6412
6392
|
};
|
|
6413
6393
|
|
|
6414
6394
|
/**
|
|
6415
|
-
* Handle uncaught exceptions.
|
|
6395
|
+
* Handle uncaught exceptions within runner.
|
|
6416
6396
|
*
|
|
6417
6397
|
* @param {Error} err
|
|
6418
6398
|
* @private
|
|
@@ -6421,7 +6401,8 @@ Runner.prototype.uncaught = function(err) {
|
|
|
6421
6401
|
if (err instanceof Pending) {
|
|
6422
6402
|
return;
|
|
6423
6403
|
}
|
|
6424
|
-
|
|
6404
|
+
// browser does not exit script when throwing in global.onerror()
|
|
6405
|
+
if (this.allowUncaught && !process.browser) {
|
|
6425
6406
|
throw err;
|
|
6426
6407
|
}
|
|
6427
6408
|
|
|
@@ -6473,36 +6454,24 @@ Runner.prototype.uncaught = function(err) {
|
|
|
6473
6454
|
|
|
6474
6455
|
// we cannot recover gracefully if a Runnable has already passed
|
|
6475
6456
|
// then fails asynchronously
|
|
6476
|
-
|
|
6477
|
-
|
|
6478
|
-
|
|
6479
|
-
|
|
6480
|
-
// recover from test
|
|
6481
|
-
if (runnable.type === constants.EVENT_TEST_BEGIN) {
|
|
6482
|
-
this.emit(constants.EVENT_TEST_END, runnable);
|
|
6483
|
-
this.hookUp(HOOK_TYPE_AFTER_EACH, this.next);
|
|
6484
|
-
return;
|
|
6485
|
-
}
|
|
6457
|
+
if (runnable.isPassed()) {
|
|
6458
|
+
this.fail(runnable, err);
|
|
6459
|
+
this.abort();
|
|
6460
|
+
} else {
|
|
6486
6461
|
debug(runnable);
|
|
6487
|
-
|
|
6488
|
-
// recover from hooks
|
|
6489
|
-
var errSuite = this.suite;
|
|
6490
|
-
|
|
6491
|
-
// XXX how about a less awful way to determine this?
|
|
6492
|
-
// if hook failure is in afterEach block
|
|
6493
|
-
if (runnable.fullTitle().indexOf('after each') > -1) {
|
|
6494
|
-
return this.hookErr(err, errSuite, true);
|
|
6495
|
-
}
|
|
6496
|
-
// if hook failure is in beforeEach block
|
|
6497
|
-
if (runnable.fullTitle().indexOf('before each') > -1) {
|
|
6498
|
-
return this.hookErr(err, errSuite, false);
|
|
6499
|
-
}
|
|
6500
|
-
// if hook failure is in after or before blocks
|
|
6501
|
-
return this.nextSuite(errSuite);
|
|
6462
|
+
return runnable.callback(err);
|
|
6502
6463
|
}
|
|
6464
|
+
};
|
|
6503
6465
|
|
|
6504
|
-
|
|
6505
|
-
|
|
6466
|
+
/**
|
|
6467
|
+
* Handle uncaught exceptions after runner's end event.
|
|
6468
|
+
*
|
|
6469
|
+
* @param {Error} err
|
|
6470
|
+
* @private
|
|
6471
|
+
*/
|
|
6472
|
+
Runner.prototype.uncaughtEnd = function uncaughtEnd(err) {
|
|
6473
|
+
if (err instanceof Pending) return;
|
|
6474
|
+
throw err;
|
|
6506
6475
|
};
|
|
6507
6476
|
|
|
6508
6477
|
/**
|
|
@@ -6552,16 +6521,12 @@ Runner.prototype.run = function(fn) {
|
|
|
6552
6521
|
this.on(constants.EVENT_RUN_END, function() {
|
|
6553
6522
|
debug(constants.EVENT_RUN_END);
|
|
6554
6523
|
process.removeListener('uncaughtException', uncaught);
|
|
6555
|
-
process.on('uncaughtException',
|
|
6556
|
-
if (err instanceof Pending) {
|
|
6557
|
-
return;
|
|
6558
|
-
}
|
|
6559
|
-
throw err;
|
|
6560
|
-
});
|
|
6524
|
+
process.on('uncaughtException', self.uncaughtEnd);
|
|
6561
6525
|
fn(self.failures);
|
|
6562
6526
|
});
|
|
6563
6527
|
|
|
6564
6528
|
// uncaught exception
|
|
6529
|
+
process.removeListener('uncaughtException', self.uncaughtEnd);
|
|
6565
6530
|
process.on('uncaughtException', uncaught);
|
|
6566
6531
|
|
|
6567
6532
|
if (this._delay) {
|
|
@@ -6570,7 +6535,9 @@ Runner.prototype.run = function(fn) {
|
|
|
6570
6535
|
this.emit(constants.EVENT_DELAY_BEGIN, rootSuite);
|
|
6571
6536
|
rootSuite.once(EVENT_ROOT_SUITE_RUN, start);
|
|
6572
6537
|
} else {
|
|
6573
|
-
|
|
6538
|
+
Runner.immediately(function() {
|
|
6539
|
+
start();
|
|
6540
|
+
});
|
|
6574
6541
|
}
|
|
6575
6542
|
|
|
6576
6543
|
return this;
|
|
@@ -7438,6 +7405,18 @@ function Test(title, fn) {
|
|
|
7438
7405
|
*/
|
|
7439
7406
|
utils.inherits(Test, Runnable);
|
|
7440
7407
|
|
|
7408
|
+
/**
|
|
7409
|
+
* Set or get retried test
|
|
7410
|
+
*
|
|
7411
|
+
* @private
|
|
7412
|
+
*/
|
|
7413
|
+
Test.prototype.retriedTest = function(n) {
|
|
7414
|
+
if (!arguments.length) {
|
|
7415
|
+
return this._retriedTest;
|
|
7416
|
+
}
|
|
7417
|
+
this._retriedTest = n;
|
|
7418
|
+
};
|
|
7419
|
+
|
|
7441
7420
|
Test.prototype.clone = function() {
|
|
7442
7421
|
var test = new Test(this.title, this.fn);
|
|
7443
7422
|
test.timeout(this.timeout());
|
|
@@ -7445,6 +7424,7 @@ Test.prototype.clone = function() {
|
|
|
7445
7424
|
test.enableTimeouts(this.enableTimeouts());
|
|
7446
7425
|
test.retries(this.retries());
|
|
7447
7426
|
test.currentRetry(this.currentRetry());
|
|
7427
|
+
test.retriedTest(this.retriedTest() || this);
|
|
7448
7428
|
test.globals(this.globals());
|
|
7449
7429
|
test.parent = this.parent;
|
|
7450
7430
|
test.file = this.file;
|
|
@@ -8294,41 +8274,20 @@ exports.defineConstants = function(obj) {
|
|
|
8294
8274
|
* @description
|
|
8295
8275
|
* Versions prior to 10 did not support ES Modules, and version 10 has an old incompatibile version of ESM.
|
|
8296
8276
|
* This function returns whether Node.JS has ES Module supports that is compatible with Mocha's needs,
|
|
8297
|
-
* which is version 12
|
|
8277
|
+
* which is version >=12.11.
|
|
8298
8278
|
*
|
|
8299
|
-
* @
|
|
8300
|
-
* @returns {Boolean} whether the current version of Node.JS supports ES Modules in a way that is compatbile with Mocha
|
|
8279
|
+
* @returns {Boolean} whether the current version of Node.JS supports ES Modules in a way that is compatible with Mocha
|
|
8301
8280
|
*/
|
|
8302
|
-
exports.supportsEsModules = function(
|
|
8303
|
-
if (
|
|
8304
|
-
|
|
8305
|
-
|
|
8306
|
-
|
|
8307
|
-
typeof process !== 'object' ||
|
|
8308
|
-
!process.versions ||
|
|
8309
|
-
!process.versions.node
|
|
8310
|
-
) {
|
|
8311
|
-
return false;
|
|
8312
|
-
}
|
|
8313
|
-
var versionFields = process.versions.node.split('.');
|
|
8314
|
-
var major = +versionFields[0];
|
|
8315
|
-
var minor = +versionFields[1];
|
|
8281
|
+
exports.supportsEsModules = function() {
|
|
8282
|
+
if (!process.browser && process.versions && process.versions.node) {
|
|
8283
|
+
var versionFields = process.versions.node.split('.');
|
|
8284
|
+
var major = +versionFields[0];
|
|
8285
|
+
var minor = +versionFields[1];
|
|
8316
8286
|
|
|
8317
|
-
|
|
8318
|
-
|
|
8319
|
-
return minor >= 2;
|
|
8287
|
+
if (major >= 13 || (major === 12 && minor >= 11)) {
|
|
8288
|
+
return true;
|
|
8320
8289
|
}
|
|
8321
|
-
return true;
|
|
8322
8290
|
}
|
|
8323
|
-
if (unflagged) {
|
|
8324
|
-
return false;
|
|
8325
|
-
}
|
|
8326
|
-
if (major < 12) {
|
|
8327
|
-
return false;
|
|
8328
|
-
}
|
|
8329
|
-
// major === 12
|
|
8330
|
-
|
|
8331
|
-
return minor >= 11;
|
|
8332
8291
|
};
|
|
8333
8292
|
|
|
8334
8293
|
}).call(this,require('_process'),require("buffer").Buffer)
|
|
@@ -18212,7 +18171,7 @@ function hasOwnProperty(obj, prop) {
|
|
|
18212
18171
|
},{"./support/isBuffer":88,"_process":69,"inherits":56}],90:[function(require,module,exports){
|
|
18213
18172
|
module.exports={
|
|
18214
18173
|
"name": "mocha",
|
|
18215
|
-
"version": "7.
|
|
18174
|
+
"version": "7.1.1",
|
|
18216
18175
|
"homepage": "https://mochajs.org/",
|
|
18217
18176
|
"notifyLogo": "https://ibin.co/4QuRuGjXvl36.png"
|
|
18218
18177
|
}
|