mocha 8.1.2 → 8.1.3
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 +6 -0
- package/lib/cli/cli.js +19 -8
- package/lib/cli/index.js +0 -6
- package/lib/cli/lookup-files.js +7 -1
- package/lib/cli/options.js +5 -4
- package/lib/mocha.js +15 -12
- package/lib/nodejs/file-unloader.js +15 -0
- package/lib/utils.js +29 -0
- package/mocha.js +732 -700
- package/mocha.js.map +1 -1
- package/package.json +9 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
# 8.1.3 / 2020-08-28
|
|
2
|
+
|
|
3
|
+
## :bug: Fixes
|
|
4
|
+
|
|
5
|
+
- [#4425](https://github.com/mochajs/mocha/issues/4425): Restore `Mocha.utils.lookupFiles()` and Webpack compatibility (both broken since v8.1.0); `Mocha.utils.lookupFiles()` is now **deprecated** and will be removed in the next major revision of Mocha; use `require('mocha/lib/cli').lookupFiles` instead ([**@boneskull**](https://github.com/boneskull))
|
|
6
|
+
|
|
1
7
|
# 8.1.2 / 2020-08-25
|
|
2
8
|
|
|
3
9
|
## :bug: Fixes
|
package/lib/cli/cli.js
CHANGED
|
@@ -3,19 +3,24 @@
|
|
|
3
3
|
'use strict';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
7
|
-
* Option parsing is handled by {@link https://npm.im/yargs yargs}.
|
|
8
|
-
* If executed via `node`, this module will run {@linkcode module:lib/cli
|
|
9
|
-
*
|
|
10
|
-
* @
|
|
11
|
-
* @module
|
|
6
|
+
* Contains CLI entry point and public API for programmatic usage in Node.js.
|
|
7
|
+
* - Option parsing is handled by {@link https://npm.im/yargs yargs}.
|
|
8
|
+
* - If executed via `node`, this module will run {@linkcode module:lib/cli.main main()}.
|
|
9
|
+
* @public
|
|
10
|
+
* @module lib/cli
|
|
12
11
|
*/
|
|
13
12
|
|
|
14
13
|
const debug = require('debug')('mocha:cli:cli');
|
|
15
14
|
const symbols = require('log-symbols');
|
|
16
15
|
const yargs = require('yargs/yargs');
|
|
17
16
|
const path = require('path');
|
|
18
|
-
const {
|
|
17
|
+
const {
|
|
18
|
+
loadRc,
|
|
19
|
+
loadPkgRc,
|
|
20
|
+
loadOptions,
|
|
21
|
+
YARGS_PARSER_CONFIG
|
|
22
|
+
} = require('./options');
|
|
23
|
+
const lookupFiles = require('./lookup-files');
|
|
19
24
|
const commands = require('./commands');
|
|
20
25
|
const ansi = require('ansi-colors');
|
|
21
26
|
const {repository, homepage, version, gitter} = require('../../package.json');
|
|
@@ -25,7 +30,8 @@ const {cwd} = require('../utils');
|
|
|
25
30
|
* - Accepts an `Array` of arguments
|
|
26
31
|
* - Modifies {@link https://nodejs.org/api/modules.html#modules_module_paths Node.js' search path} for easy loading of consumer modules
|
|
27
32
|
* - Sets {@linkcode https://nodejs.org/api/errors.html#errors_error_stacktracelimit Error.stackTraceLimit} to `Infinity`
|
|
28
|
-
* @
|
|
33
|
+
* @public
|
|
34
|
+
* @summary Mocha's main command-line entry-point.
|
|
29
35
|
* @param {string[]} argv - Array of arguments to parse, or by default the lovely `process.argv.slice(2)`
|
|
30
36
|
*/
|
|
31
37
|
exports.main = (argv = process.argv.slice(2)) => {
|
|
@@ -71,6 +77,11 @@ exports.main = (argv = process.argv.slice(2)) => {
|
|
|
71
77
|
.parse(args._);
|
|
72
78
|
};
|
|
73
79
|
|
|
80
|
+
exports.lookupFiles = lookupFiles;
|
|
81
|
+
exports.loadOptions = loadOptions;
|
|
82
|
+
exports.loadPkgRc = loadPkgRc;
|
|
83
|
+
exports.loadRc = loadRc;
|
|
84
|
+
|
|
74
85
|
// allow direct execution
|
|
75
86
|
if (require.main === module) {
|
|
76
87
|
exports.main();
|
package/lib/cli/index.js
CHANGED
package/lib/cli/lookup-files.js
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Contains `lookupFiles`, which takes some globs/dirs/options and returns a list of files.
|
|
5
|
+
* @module
|
|
6
|
+
* @private
|
|
7
|
+
*/
|
|
8
|
+
|
|
3
9
|
var fs = require('fs');
|
|
4
10
|
var path = require('path');
|
|
5
11
|
var glob = require('glob');
|
|
@@ -53,7 +59,7 @@ function hasMatchingExtname(pathname, exts) {
|
|
|
53
59
|
* **Make no assumption that the names will be sorted in any fashion.**
|
|
54
60
|
*
|
|
55
61
|
* @public
|
|
56
|
-
* @
|
|
62
|
+
* @alias module:lib/cli.lookupFiles
|
|
57
63
|
* @param {string} filepath - Base path to start searching from.
|
|
58
64
|
* @param {string[]} [extensions=[]] - File extensions to look for.
|
|
59
65
|
* @param {boolean} [recursive=false] - Whether to recurse into subdirectories.
|
package/lib/cli/options.js
CHANGED
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
/**
|
|
4
4
|
* Main entry point for handling filesystem-based configuration,
|
|
5
5
|
* whether that's a config file or `package.json` or whatever.
|
|
6
|
-
* @module
|
|
6
|
+
* @module lib/cli/options
|
|
7
|
+
* @private
|
|
7
8
|
*/
|
|
8
9
|
|
|
9
10
|
const fs = require('fs');
|
|
@@ -150,7 +151,7 @@ const parse = (args = [], defaultValues = {}, ...configObjects) => {
|
|
|
150
151
|
* @param {Object} [args] - Arguments object
|
|
151
152
|
* @param {string|boolean} [args.config] - Path to config file or `false` to skip
|
|
152
153
|
* @public
|
|
153
|
-
* @
|
|
154
|
+
* @alias module:lib/cli.loadRc
|
|
154
155
|
* @returns {external:yargsParser.Arguments|void} Parsed config, or nothing if `args.config` is `false`
|
|
155
156
|
*/
|
|
156
157
|
const loadRc = (args = {}) => {
|
|
@@ -167,7 +168,7 @@ module.exports.loadRc = loadRc;
|
|
|
167
168
|
* @param {Object} [args] - Arguments object
|
|
168
169
|
* @param {string|boolean} [args.config] - Path to `package.json` or `false` to skip
|
|
169
170
|
* @public
|
|
170
|
-
* @
|
|
171
|
+
* @alias module:lib/cli.loadPkgRc
|
|
171
172
|
* @returns {external:yargsParser.Arguments|void} Parsed config, or nothing if `args.package` is `false`
|
|
172
173
|
*/
|
|
173
174
|
const loadPkgRc = (args = {}) => {
|
|
@@ -210,7 +211,7 @@ module.exports.loadPkgRc = loadPkgRc;
|
|
|
210
211
|
* @summary Parses options read from `.mocharc.*` and `package.json`.
|
|
211
212
|
* @param {string|string[]} [argv] - Arguments to parse
|
|
212
213
|
* @public
|
|
213
|
-
* @
|
|
214
|
+
* @alias module:lib/cli.loadOptions
|
|
214
215
|
* @returns {external:yargsParser.Arguments} Parsed args from everything
|
|
215
216
|
*/
|
|
216
217
|
const loadOptions = (argv = []) => {
|
package/lib/mocha.js
CHANGED
|
@@ -12,18 +12,18 @@ var builtinReporters = require('./reporters');
|
|
|
12
12
|
var growl = require('./nodejs/growl');
|
|
13
13
|
var utils = require('./utils');
|
|
14
14
|
var mocharc = require('./mocharc.json');
|
|
15
|
-
var errors = require('./errors');
|
|
16
15
|
var Suite = require('./suite');
|
|
17
16
|
var esmUtils = utils.supportsEsModules(true)
|
|
18
17
|
? require('./esm-utils')
|
|
19
18
|
: undefined;
|
|
20
19
|
var createStatsCollector = require('./stats-collector');
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
20
|
+
const {
|
|
21
|
+
createUnsupportedError,
|
|
22
|
+
createInvalidInterfaceError,
|
|
23
|
+
createInvalidReporterError,
|
|
24
|
+
createMochaInstanceAlreadyDisposedError,
|
|
25
|
+
createMochaInstanceAlreadyRunningError
|
|
26
|
+
} = require('./errors');
|
|
27
27
|
var EVENT_FILE_PRE_REQUIRE = Suite.constants.EVENT_FILE_PRE_REQUIRE;
|
|
28
28
|
var EVENT_FILE_POST_REQUIRE = Suite.constants.EVENT_FILE_POST_REQUIRE;
|
|
29
29
|
var EVENT_FILE_REQUIRE = Suite.constants.EVENT_FILE_REQUIRE;
|
|
@@ -445,7 +445,12 @@ Mocha.prototype.loadFilesAsync = function() {
|
|
|
445
445
|
* @param {string} file - Pathname of file to be unloaded.
|
|
446
446
|
*/
|
|
447
447
|
Mocha.unloadFile = function(file) {
|
|
448
|
-
|
|
448
|
+
if (utils.isBrowser()) {
|
|
449
|
+
throw createUnsupportedError(
|
|
450
|
+
'unloadFile() is only suported in a Node.js environment'
|
|
451
|
+
);
|
|
452
|
+
}
|
|
453
|
+
return require('./nodejs/file-unloader').unloadFile(file);
|
|
449
454
|
};
|
|
450
455
|
|
|
451
456
|
/**
|
|
@@ -1051,9 +1056,7 @@ Mocha.prototype.rootHooks = function rootHooks(hooks) {
|
|
|
1051
1056
|
*/
|
|
1052
1057
|
Mocha.prototype.parallelMode = function parallelMode(enable) {
|
|
1053
1058
|
if (utils.isBrowser()) {
|
|
1054
|
-
throw
|
|
1055
|
-
'parallel mode is only supported in Node.js'
|
|
1056
|
-
);
|
|
1059
|
+
throw createUnsupportedError('parallel mode is only supported in Node.js');
|
|
1057
1060
|
}
|
|
1058
1061
|
var parallel = enable === true;
|
|
1059
1062
|
if (
|
|
@@ -1064,7 +1067,7 @@ Mocha.prototype.parallelMode = function parallelMode(enable) {
|
|
|
1064
1067
|
return this;
|
|
1065
1068
|
}
|
|
1066
1069
|
if (this._state !== mochaStates.INIT) {
|
|
1067
|
-
throw
|
|
1070
|
+
throw createUnsupportedError(
|
|
1068
1071
|
'cannot change parallel mode after having called run()'
|
|
1069
1072
|
);
|
|
1070
1073
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* This module should not be in the browser bundle, so it's here.
|
|
5
|
+
* @private
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Deletes a file from the `require` cache.
|
|
11
|
+
* @param {string} file - File
|
|
12
|
+
*/
|
|
13
|
+
exports.unloadFile = file => {
|
|
14
|
+
delete require.cache[require.resolve(file)];
|
|
15
|
+
};
|
package/lib/utils.js
CHANGED
|
@@ -645,3 +645,32 @@ exports.cwd = function cwd() {
|
|
|
645
645
|
exports.isBrowser = function isBrowser() {
|
|
646
646
|
return Boolean(process.browser);
|
|
647
647
|
};
|
|
648
|
+
|
|
649
|
+
/**
|
|
650
|
+
* Lookup file names at the given `path`.
|
|
651
|
+
*
|
|
652
|
+
* @description
|
|
653
|
+
* Filenames are returned in _traversal_ order by the OS/filesystem.
|
|
654
|
+
* **Make no assumption that the names will be sorted in any fashion.**
|
|
655
|
+
*
|
|
656
|
+
* @public
|
|
657
|
+
* @alias module:lib/cli.lookupFiles
|
|
658
|
+
* @param {string} filepath - Base path to start searching from.
|
|
659
|
+
* @param {string[]} [extensions=[]] - File extensions to look for.
|
|
660
|
+
* @param {boolean} [recursive=false] - Whether to recurse into subdirectories.
|
|
661
|
+
* @return {string[]} An array of paths.
|
|
662
|
+
* @throws {Error} if no files match pattern.
|
|
663
|
+
* @throws {TypeError} if `filepath` is directory and `extensions` not provided.
|
|
664
|
+
* @deprecated Moved to {@link module:lib/cli.lookupFiles}
|
|
665
|
+
*/
|
|
666
|
+
exports.lookupFiles = (...args) => {
|
|
667
|
+
if (exports.isBrowser()) {
|
|
668
|
+
throw require('./errors').createUnsupportedError(
|
|
669
|
+
'lookupFiles() is only supported in Node.js!'
|
|
670
|
+
);
|
|
671
|
+
}
|
|
672
|
+
exports.deprecate(
|
|
673
|
+
'`lookupFiles()` in module `mocha/lib/utils` has moved to module `mocha/lib/cli` and will be removed in the next major revision of Mocha'
|
|
674
|
+
);
|
|
675
|
+
return require('./cli').lookupFiles(...args);
|
|
676
|
+
};
|