mocha 11.0.1 → 11.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/lib/cli/cli.js +8 -4
- package/lib/cli/options.js +70 -17
- package/lib/cli/run-option-metadata.js +21 -0
- package/lib/cli/run.js +2 -2
- package/lib/mocha.js +3 -1
- package/lib/utils.js +7 -0
- package/mocha.js +12 -3
- package/mocha.js.map +1 -1
- package/package.json +3 -4
package/lib/cli/cli.js
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
|
|
13
13
|
const debug = require('debug')('mocha:cli:cli');
|
|
14
14
|
const symbols = require('log-symbols');
|
|
15
|
-
const yargs = require('yargs
|
|
15
|
+
const yargs = require('yargs');
|
|
16
16
|
const path = require('path');
|
|
17
17
|
const {
|
|
18
18
|
loadRc,
|
|
@@ -42,7 +42,11 @@ exports.main = (argv = process.argv.slice(2), mochaArgs) => {
|
|
|
42
42
|
module.paths.push(cwd(), path.resolve('node_modules'));
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
|
|
45
|
+
try {
|
|
46
|
+
Error.stackTraceLimit = Infinity; // configurable via --stack-trace-limit?
|
|
47
|
+
} catch (err) {
|
|
48
|
+
debug('unable to set Error.stackTraceLimit = Infinity', err);
|
|
49
|
+
}
|
|
46
50
|
|
|
47
51
|
var args = mochaArgs || loadOptions(argv);
|
|
48
52
|
|
|
@@ -59,7 +63,7 @@ exports.main = (argv = process.argv.slice(2), mochaArgs) => {
|
|
|
59
63
|
debug('caught error sometime before command handler: %O', err);
|
|
60
64
|
yargs.showHelp();
|
|
61
65
|
console.error(`\n${symbols.error} ${ansi.red('ERROR:')} ${msg}`);
|
|
62
|
-
process.
|
|
66
|
+
process.exit(1);
|
|
63
67
|
})
|
|
64
68
|
.help('help', 'Show usage information & exit')
|
|
65
69
|
.alias('help', 'h')
|
|
@@ -67,7 +71,7 @@ exports.main = (argv = process.argv.slice(2), mochaArgs) => {
|
|
|
67
71
|
.alias('version', 'V')
|
|
68
72
|
.wrap(process.stdout.columns ? Math.min(process.stdout.columns, 80) : 80)
|
|
69
73
|
.epilog(
|
|
70
|
-
|
|
74
|
+
`${ansi.reset("Mocha Resources")}
|
|
71
75
|
Chat: ${ansi.magenta(discord)}
|
|
72
76
|
GitHub: ${ansi.blue(repository.url)}
|
|
73
77
|
Docs: ${ansi.yellow(homepage)}
|
package/lib/cli/options.js
CHANGED
|
@@ -10,7 +10,12 @@
|
|
|
10
10
|
const fs = require('fs');
|
|
11
11
|
const ansi = require('ansi-colors');
|
|
12
12
|
const yargsParser = require('yargs-parser');
|
|
13
|
-
const {
|
|
13
|
+
const {
|
|
14
|
+
types,
|
|
15
|
+
aliases,
|
|
16
|
+
isMochaFlag,
|
|
17
|
+
expectedTypeForFlag
|
|
18
|
+
} = require('./run-option-metadata');
|
|
14
19
|
const {ONE_AND_DONE_ARGS} = require('./one-and-dones');
|
|
15
20
|
const mocharc = require('../mocharc.json');
|
|
16
21
|
const {list} = require('./run-helpers');
|
|
@@ -18,7 +23,12 @@ const {loadConfig, findConfig} = require('./config');
|
|
|
18
23
|
const findUp = require('find-up');
|
|
19
24
|
const debug = require('debug')('mocha:cli:options');
|
|
20
25
|
const {isNodeFlag} = require('./node-flags');
|
|
21
|
-
const {
|
|
26
|
+
const {
|
|
27
|
+
createUnparsableFileError,
|
|
28
|
+
createInvalidArgumentTypeError,
|
|
29
|
+
createUnsupportedError
|
|
30
|
+
} = require('../errors');
|
|
31
|
+
const {isNumeric} = require('../utils');
|
|
22
32
|
|
|
23
33
|
/**
|
|
24
34
|
* The `yargs-parser` namespace
|
|
@@ -93,6 +103,44 @@ const nargOpts = types.array
|
|
|
93
103
|
.concat(types.string, types.number)
|
|
94
104
|
.reduce((acc, arg) => Object.assign(acc, {[arg]: 1}), {});
|
|
95
105
|
|
|
106
|
+
/**
|
|
107
|
+
* Throws either "UNSUPPORTED" error or "INVALID_ARG_TYPE" error for numeric positional arguments.
|
|
108
|
+
* @param {string[]} allArgs - Stringified args passed to mocha cli
|
|
109
|
+
* @param {number} numericArg - Numeric positional arg for which error must be thrown
|
|
110
|
+
* @param {Object} parsedResult - Result from `yargs-parser`
|
|
111
|
+
* @private
|
|
112
|
+
* @ignore
|
|
113
|
+
*/
|
|
114
|
+
const createErrorForNumericPositionalArg = (
|
|
115
|
+
numericArg,
|
|
116
|
+
allArgs,
|
|
117
|
+
parsedResult
|
|
118
|
+
) => {
|
|
119
|
+
// A flag for `numericArg` exists if:
|
|
120
|
+
// 1. A mocha flag immediately preceeded the numericArg in `allArgs` array and
|
|
121
|
+
// 2. `numericArg` value could not be assigned to this flag by `yargs-parser` because of incompatible datatype.
|
|
122
|
+
const flag = allArgs.find((arg, index) => {
|
|
123
|
+
const normalizedArg = arg.replace(/^--?/, '');
|
|
124
|
+
return (
|
|
125
|
+
isMochaFlag(arg) &&
|
|
126
|
+
allArgs[index + 1] === String(numericArg) &&
|
|
127
|
+
parsedResult[normalizedArg] !== String(numericArg)
|
|
128
|
+
);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
if (flag) {
|
|
132
|
+
throw createInvalidArgumentTypeError(
|
|
133
|
+
`Mocha flag '${flag}' given invalid option: '${numericArg}'`,
|
|
134
|
+
numericArg,
|
|
135
|
+
expectedTypeForFlag(flag)
|
|
136
|
+
);
|
|
137
|
+
} else {
|
|
138
|
+
throw createUnsupportedError(
|
|
139
|
+
`Option ${numericArg} is unsupported by the mocha cli`
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
|
|
96
144
|
/**
|
|
97
145
|
* Wrapper around `yargs-parser` which applies our settings
|
|
98
146
|
* @param {string|string[]} args - Arguments to parse
|
|
@@ -104,24 +152,20 @@ const nargOpts = types.array
|
|
|
104
152
|
const parse = (args = [], defaultValues = {}, ...configObjects) => {
|
|
105
153
|
// save node-specific args for special handling.
|
|
106
154
|
// 1. when these args have a "=" they should be considered to have values
|
|
107
|
-
// 2. if they don't, they just boolean flags
|
|
155
|
+
// 2. if they don't, they are just boolean flags
|
|
108
156
|
// 3. to avoid explicitly defining the set of them, we tell yargs-parser they
|
|
109
157
|
// are ALL boolean flags.
|
|
110
158
|
// 4. we can then reapply the values after yargs-parser is done.
|
|
111
|
-
const
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
return acc;
|
|
122
|
-
},
|
|
123
|
-
[]
|
|
124
|
-
);
|
|
159
|
+
const allArgs = Array.isArray(args) ? args : args.split(' ');
|
|
160
|
+
const nodeArgs = allArgs.reduce((acc, arg) => {
|
|
161
|
+
const pair = arg.split('=');
|
|
162
|
+
let flag = pair[0];
|
|
163
|
+
if (isNodeFlag(flag, false)) {
|
|
164
|
+
flag = flag.replace(/^--?/, '');
|
|
165
|
+
return acc.concat([[flag, arg.includes('=') ? pair[1] : true]]);
|
|
166
|
+
}
|
|
167
|
+
return acc;
|
|
168
|
+
}, []);
|
|
125
169
|
|
|
126
170
|
const result = yargsParser.detailed(args, {
|
|
127
171
|
configuration,
|
|
@@ -140,6 +184,15 @@ const parse = (args = [], defaultValues = {}, ...configObjects) => {
|
|
|
140
184
|
process.exit(1);
|
|
141
185
|
}
|
|
142
186
|
|
|
187
|
+
const numericPositionalArg = result.argv._.find(arg => isNumeric(arg));
|
|
188
|
+
if (numericPositionalArg) {
|
|
189
|
+
createErrorForNumericPositionalArg(
|
|
190
|
+
numericPositionalArg,
|
|
191
|
+
allArgs,
|
|
192
|
+
result.argv
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
|
|
143
196
|
// reapply "=" arg values from above
|
|
144
197
|
nodeArgs.forEach(([key, value]) => {
|
|
145
198
|
result.argv[key] = value;
|
|
@@ -114,3 +114,24 @@ const ALL_MOCHA_FLAGS = Object.keys(TYPES).reduce((acc, key) => {
|
|
|
114
114
|
exports.isMochaFlag = flag => {
|
|
115
115
|
return ALL_MOCHA_FLAGS.has(flag.replace(/^--?/, ''));
|
|
116
116
|
};
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Returns expected yarg option type for a given mocha flag.
|
|
120
|
+
* @param {string} flag - Flag to check (can be with or without leading dashes "--"")
|
|
121
|
+
* @returns {string | undefined} - If flag is a valid mocha flag, the expected type of argument for this flag is returned, otherwise undefined is returned.
|
|
122
|
+
* @private
|
|
123
|
+
*/
|
|
124
|
+
exports.expectedTypeForFlag = flag => {
|
|
125
|
+
const normalizedName = flag.replace(/^--?/, '');
|
|
126
|
+
|
|
127
|
+
// If flag is an alias, get it's full name.
|
|
128
|
+
const aliases = exports.aliases;
|
|
129
|
+
const fullFlagName =
|
|
130
|
+
Object.keys(aliases).find(flagName =>
|
|
131
|
+
aliases[flagName].includes(normalizedName)
|
|
132
|
+
) || normalizedName;
|
|
133
|
+
|
|
134
|
+
return Object.keys(TYPES).find(flagType =>
|
|
135
|
+
TYPES[flagType].includes(fullFlagName)
|
|
136
|
+
);
|
|
137
|
+
};
|
package/lib/cli/run.js
CHANGED
|
@@ -169,11 +169,11 @@ exports.builder = yargs =>
|
|
|
169
169
|
group: GROUPS.RULES
|
|
170
170
|
},
|
|
171
171
|
'list-interfaces': {
|
|
172
|
-
conflicts: Array.from(ONE_AND_DONE_ARGS),
|
|
172
|
+
conflicts: Array.from(ONE_AND_DONE_ARGS).filter(arg => arg !== "list-interfaces"),
|
|
173
173
|
description: 'List built-in user interfaces & exit'
|
|
174
174
|
},
|
|
175
175
|
'list-reporters': {
|
|
176
|
-
conflicts: Array.from(ONE_AND_DONE_ARGS),
|
|
176
|
+
conflicts: Array.from(ONE_AND_DONE_ARGS).filter(arg => arg !== "list-reporters"),
|
|
177
177
|
description: 'List built-in reporters & exit'
|
|
178
178
|
},
|
|
179
179
|
'no-colors': {
|
package/lib/mocha.js
CHANGED
|
@@ -194,7 +194,9 @@ function Mocha(options = {}) {
|
|
|
194
194
|
.ui(options.ui)
|
|
195
195
|
.reporter(
|
|
196
196
|
options.reporter,
|
|
197
|
-
options
|
|
197
|
+
options['reporter-option'] ||
|
|
198
|
+
options.reporterOption ||
|
|
199
|
+
options.reporterOptions // for backwards compatibility
|
|
198
200
|
)
|
|
199
201
|
.slow(options.slow)
|
|
200
202
|
.global(options.global);
|
package/lib/utils.js
CHANGED
|
@@ -689,3 +689,10 @@ exports.breakCircularDeps = inputObj => {
|
|
|
689
689
|
|
|
690
690
|
return _breakCircularDeps(inputObj);
|
|
691
691
|
};
|
|
692
|
+
|
|
693
|
+
/**
|
|
694
|
+
* Checks if provided input can be parsed as a JavaScript Number.
|
|
695
|
+
*/
|
|
696
|
+
exports.isNumeric = input => {
|
|
697
|
+
return !isNaN(parseFloat(input));
|
|
698
|
+
};
|
package/mocha.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// mocha@11.0
|
|
1
|
+
// mocha@11.1.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) :
|
|
@@ -11652,6 +11652,13 @@
|
|
|
11652
11652
|
|
|
11653
11653
|
return _breakCircularDeps(inputObj);
|
|
11654
11654
|
};
|
|
11655
|
+
|
|
11656
|
+
/**
|
|
11657
|
+
* Checks if provided input can be parsed as a JavaScript Number.
|
|
11658
|
+
*/
|
|
11659
|
+
exports.isNumeric = input => {
|
|
11660
|
+
return !isNaN(parseFloat(input));
|
|
11661
|
+
};
|
|
11655
11662
|
}(utils$3));
|
|
11656
11663
|
|
|
11657
11664
|
var _nodeResolve_empty = {};
|
|
@@ -19201,7 +19208,7 @@
|
|
|
19201
19208
|
};
|
|
19202
19209
|
|
|
19203
19210
|
var name = "mocha";
|
|
19204
|
-
var version = "11.0
|
|
19211
|
+
var version = "11.1.0";
|
|
19205
19212
|
var homepage = "https://mochajs.org/";
|
|
19206
19213
|
var notifyLogo = "https://ibin.co/4QuRuGjXvl36.png";
|
|
19207
19214
|
var require$$17 = {
|
|
@@ -19407,7 +19414,9 @@
|
|
|
19407
19414
|
.ui(options.ui)
|
|
19408
19415
|
.reporter(
|
|
19409
19416
|
options.reporter,
|
|
19410
|
-
options
|
|
19417
|
+
options['reporter-option'] ||
|
|
19418
|
+
options.reporterOption ||
|
|
19419
|
+
options.reporterOptions // for backwards compatibility
|
|
19411
19420
|
)
|
|
19412
19421
|
.slow(options.slow)
|
|
19413
19422
|
.global(options.global);
|