mocha 11.0.0 → 11.0.2

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 CHANGED
@@ -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
- Error.stackTraceLimit = Infinity; // configurable via --stack-trace-limit?
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
 
@@ -87,10 +87,15 @@ module.exports = function lookupFiles(
87
87
  debug('looking for files using glob pattern: %s', pattern);
88
88
  }
89
89
  files.push(
90
- ...glob.sync(pattern, {
91
- nodir: true,
92
- windowsPathsNoEscape: true
93
- })
90
+ ...glob
91
+ .sync(pattern, {
92
+ nodir: true,
93
+ windowsPathsNoEscape: true
94
+ })
95
+ // glob@8 and earlier sorted results in en; glob@9 depends on OS sorting.
96
+ // This preserves the older glob behavior.
97
+ // https://github.com/mochajs/mocha/pull/5250/files#r1840469747
98
+ .sort((a, b) => a.localeCompare(b, 'en'))
94
99
  );
95
100
  if (!files.length) {
96
101
  throw createNoFilesMatchPatternError(
@@ -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 {types, aliases} = require('./run-option-metadata');
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 {createUnparsableFileError} = require('../errors');
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 nodeArgs = (Array.isArray(args) ? args : args.split(' ')).reduce(
112
- (acc, arg) => {
113
- const pair = arg.split('=');
114
- let flag = pair[0];
115
- if (isNodeFlag(flag, false)) {
116
- flag = flag.replace(/^--?/, '');
117
- return arg.includes('=')
118
- ? acc.concat([[flag, pair[1]]])
119
- : acc.concat([[flag, true]]);
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
+ };
@@ -374,16 +374,16 @@ class ParallelBufferedRunner extends Runner {
374
374
  * // this reporter needs proper object references when run in parallel mode
375
375
  * class MyReporter() {
376
376
  * constructor(runner) {
377
- * this.runner.linkPartialObjects(true)
377
+ * runner.linkPartialObjects(true)
378
378
  * .on(EVENT_SUITE_BEGIN, suite => {
379
- // this Suite may be the same object...
380
- * })
381
- * .on(EVENT_TEST_BEGIN, test => {
382
- * // ...as the `test.parent` property
383
- * });
384
- * }
385
- * }
386
- */
379
+ * // this Suite may be the same object...
380
+ * })
381
+ * .on(EVENT_TEST_BEGIN, test => {
382
+ * // ...as the `test.parent` property
383
+ * });
384
+ * }
385
+ * }
386
+ */
387
387
  linkPartialObjects(value) {
388
388
  this._linkPartialObjects = Boolean(value);
389
389
  return super.linkPartialObjects(value);
package/lib/runner.js CHANGED
@@ -1116,11 +1116,11 @@ Runner.prototype.run = function (fn, opts = {}) {
1116
1116
  * @public
1117
1117
  * @example
1118
1118
  * // this reporter needs proper object references when run in parallel mode
1119
- * class MyReporter() {
1119
+ * class MyReporter {
1120
1120
  * constructor(runner) {
1121
- * this.runner.linkPartialObjects(true)
1121
+ * runner.linkPartialObjects(true)
1122
1122
  * .on(EVENT_SUITE_BEGIN, suite => {
1123
- // this Suite may be the same object...
1123
+ * // this Suite may be the same object...
1124
1124
  * })
1125
1125
  * .on(EVENT_TEST_BEGIN, test => {
1126
1126
  * // ...as the `test.parent` property
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.0 in javascript ES2018
1
+ // mocha@11.0.2 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 = {};
@@ -15296,11 +15303,11 @@
15296
15303
  * @public
15297
15304
  * @example
15298
15305
  * // this reporter needs proper object references when run in parallel mode
15299
- * class MyReporter() {
15306
+ * class MyReporter {
15300
15307
  * constructor(runner) {
15301
- * this.runner.linkPartialObjects(true)
15308
+ * runner.linkPartialObjects(true)
15302
15309
  * .on(EVENT_SUITE_BEGIN, suite => {
15303
- // this Suite may be the same object...
15310
+ * // this Suite may be the same object...
15304
15311
  * })
15305
15312
  * .on(EVENT_TEST_BEGIN, test => {
15306
15313
  * // ...as the `test.parent` property
@@ -19201,7 +19208,7 @@
19201
19208
  };
19202
19209
 
19203
19210
  var name = "mocha";
19204
- var version = "11.0.0";
19211
+ var version = "11.0.2";
19205
19212
  var homepage = "https://mochajs.org/";
19206
19213
  var notifyLogo = "https://ibin.co/4QuRuGjXvl36.png";
19207
19214
  var require$$17 = {