mocha 10.1.0 → 10.2.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/lib/mocha.js +5 -2
- package/lib/nodejs/esm-utils.js +20 -8
- package/mocha.css +1 -1
- package/mocha.js +7 -4
- package/mocha.js.map +1 -1
- package/package.json +1 -4
package/lib/mocha.js
CHANGED
|
@@ -429,6 +429,8 @@ Mocha.prototype.loadFiles = function (fn) {
|
|
|
429
429
|
* @see {@link Mocha#addFile}
|
|
430
430
|
* @see {@link Mocha#run}
|
|
431
431
|
* @see {@link Mocha#unloadFiles}
|
|
432
|
+
* @param {Object} [options] - Settings object.
|
|
433
|
+
* @param {Function} [options.esmDecorator] - Function invoked on esm module name right before importing it. By default will passthrough as is.
|
|
432
434
|
* @returns {Promise}
|
|
433
435
|
* @example
|
|
434
436
|
*
|
|
@@ -437,7 +439,7 @@ Mocha.prototype.loadFiles = function (fn) {
|
|
|
437
439
|
* .then(() => mocha.run(failures => process.exitCode = failures ? 1 : 0))
|
|
438
440
|
* .catch(() => process.exitCode = 1);
|
|
439
441
|
*/
|
|
440
|
-
Mocha.prototype.loadFilesAsync = function () {
|
|
442
|
+
Mocha.prototype.loadFilesAsync = function ({esmDecorator} = {}) {
|
|
441
443
|
var self = this;
|
|
442
444
|
var suite = this.suite;
|
|
443
445
|
this.lazyLoadFiles(true);
|
|
@@ -450,7 +452,8 @@ Mocha.prototype.loadFilesAsync = function () {
|
|
|
450
452
|
function (file, resultModule) {
|
|
451
453
|
suite.emit(EVENT_FILE_REQUIRE, resultModule, file, self);
|
|
452
454
|
suite.emit(EVENT_FILE_POST_REQUIRE, global, file, self);
|
|
453
|
-
}
|
|
455
|
+
},
|
|
456
|
+
esmDecorator
|
|
454
457
|
);
|
|
455
458
|
};
|
|
456
459
|
|
package/lib/nodejs/esm-utils.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
const path = require('path');
|
|
2
2
|
const url = require('url');
|
|
3
3
|
|
|
4
|
-
const
|
|
4
|
+
const forward = x => x;
|
|
5
|
+
|
|
6
|
+
const formattedImport = async (file, esmDecorator = forward) => {
|
|
5
7
|
if (path.isAbsolute(file)) {
|
|
6
8
|
try {
|
|
7
|
-
return await
|
|
9
|
+
return await exports.doImport(esmDecorator(url.pathToFileURL(file)));
|
|
8
10
|
} catch (err) {
|
|
9
11
|
// This is a hack created because ESM in Node.js (at least in Node v15.5.1) does not emit
|
|
10
12
|
// the location of the syntax error in the error thrown.
|
|
@@ -27,15 +29,17 @@ const formattedImport = async file => {
|
|
|
27
29
|
throw err;
|
|
28
30
|
}
|
|
29
31
|
}
|
|
30
|
-
return
|
|
32
|
+
return exports.doImport(esmDecorator(file));
|
|
31
33
|
};
|
|
32
34
|
|
|
33
|
-
exports.
|
|
35
|
+
exports.doImport = async file => import(file);
|
|
36
|
+
|
|
37
|
+
exports.requireOrImport = async (file, esmDecorator) => {
|
|
34
38
|
if (path.extname(file) === '.mjs') {
|
|
35
|
-
return formattedImport(file);
|
|
39
|
+
return formattedImport(file, esmDecorator);
|
|
36
40
|
}
|
|
37
41
|
try {
|
|
38
|
-
return dealWithExports(await formattedImport(file));
|
|
42
|
+
return dealWithExports(await formattedImport(file, esmDecorator));
|
|
39
43
|
} catch (err) {
|
|
40
44
|
if (
|
|
41
45
|
err.code === 'ERR_MODULE_NOT_FOUND' ||
|
|
@@ -85,10 +89,18 @@ function dealWithExports(module) {
|
|
|
85
89
|
}
|
|
86
90
|
}
|
|
87
91
|
|
|
88
|
-
exports.loadFilesAsync = async (
|
|
92
|
+
exports.loadFilesAsync = async (
|
|
93
|
+
files,
|
|
94
|
+
preLoadFunc,
|
|
95
|
+
postLoadFunc,
|
|
96
|
+
esmDecorator
|
|
97
|
+
) => {
|
|
89
98
|
for (const file of files) {
|
|
90
99
|
preLoadFunc(file);
|
|
91
|
-
const result = await exports.requireOrImport(
|
|
100
|
+
const result = await exports.requireOrImport(
|
|
101
|
+
path.resolve(file),
|
|
102
|
+
esmDecorator
|
|
103
|
+
);
|
|
92
104
|
postLoadFunc(file, result);
|
|
93
105
|
}
|
|
94
106
|
};
|
package/mocha.css
CHANGED
package/mocha.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// mocha@10.
|
|
1
|
+
// mocha@10.2.0 in javascript ES2018
|
|
2
2
|
(function (global, factory) {
|
|
3
3
|
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
|
4
4
|
typeof define === 'function' && define.amd ? define(factory) :
|
|
@@ -19076,7 +19076,7 @@
|
|
|
19076
19076
|
};
|
|
19077
19077
|
|
|
19078
19078
|
var name = "mocha";
|
|
19079
|
-
var version = "10.
|
|
19079
|
+
var version = "10.2.0";
|
|
19080
19080
|
var homepage = "https://mochajs.org/";
|
|
19081
19081
|
var notifyLogo = "https://ibin.co/4QuRuGjXvl36.png";
|
|
19082
19082
|
var require$$17 = {
|
|
@@ -19517,6 +19517,8 @@
|
|
|
19517
19517
|
* @see {@link Mocha#addFile}
|
|
19518
19518
|
* @see {@link Mocha#run}
|
|
19519
19519
|
* @see {@link Mocha#unloadFiles}
|
|
19520
|
+
* @param {Object} [options] - Settings object.
|
|
19521
|
+
* @param {Function} [options.esmDecorator] - Function invoked on esm module name right before importing it. By default will passthrough as is.
|
|
19520
19522
|
* @returns {Promise}
|
|
19521
19523
|
* @example
|
|
19522
19524
|
*
|
|
@@ -19525,7 +19527,7 @@
|
|
|
19525
19527
|
* .then(() => mocha.run(failures => process.exitCode = failures ? 1 : 0))
|
|
19526
19528
|
* .catch(() => process.exitCode = 1);
|
|
19527
19529
|
*/
|
|
19528
|
-
Mocha.prototype.loadFilesAsync = function () {
|
|
19530
|
+
Mocha.prototype.loadFilesAsync = function ({esmDecorator} = {}) {
|
|
19529
19531
|
var self = this;
|
|
19530
19532
|
var suite = this.suite;
|
|
19531
19533
|
this.lazyLoadFiles(true);
|
|
@@ -19538,7 +19540,8 @@
|
|
|
19538
19540
|
function (file, resultModule) {
|
|
19539
19541
|
suite.emit(EVENT_FILE_REQUIRE, resultModule, file, self);
|
|
19540
19542
|
suite.emit(EVENT_FILE_POST_REQUIRE, commonjsGlobal, file, self);
|
|
19541
|
-
}
|
|
19543
|
+
},
|
|
19544
|
+
esmDecorator
|
|
19542
19545
|
);
|
|
19543
19546
|
};
|
|
19544
19547
|
|