Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mocha

Package Overview
Dependencies
Maintainers
0
Versions
206
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mocha - npm Package Compare versions

Comparing version 11.0.1 to 11.0.2

6

lib/cli/cli.js

@@ -45,3 +45,7 @@ #!/usr/bin/env node

Error.stackTraceLimit = Infinity; // configurable via --stack-trace-limit?
try {
Error.stackTraceLimit = Infinity; // configurable via --stack-trace-limit?
} catch (err) {
debug('unable to set Error.stackTraceLimit = Infinity', err);
}

@@ -48,0 +52,0 @@ var args = mochaArgs || loadOptions(argv);

@@ -13,3 +13,8 @@ 'use strict';

const yargsParser = require('yargs-parser');
const {types, aliases} = require('./run-option-metadata');
const {
types,
aliases,
isMochaFlag,
expectedTypeForFlag
} = require('./run-option-metadata');
const {ONE_AND_DONE_ARGS} = require('./one-and-dones');

@@ -22,3 +27,8 @@ const mocharc = require('../mocharc.json');

const {isNodeFlag} = require('./node-flags');
const {createUnparsableFileError} = require('../errors');
const {
createUnparsableFileError,
createInvalidArgumentTypeError,
createUnsupportedError
} = require('../errors');
const {isNumeric} = require('../utils');

@@ -99,2 +109,40 @@ /**

/**
* Throws either "UNSUPPORTED" error or "INVALID_ARG_TYPE" error for numeric positional arguments.
* @param {string[]} allArgs - Stringified args passed to mocha cli
* @param {number} numericArg - Numeric positional arg for which error must be thrown
* @param {Object} parsedResult - Result from `yargs-parser`
* @private
* @ignore
*/
const createErrorForNumericPositionalArg = (
numericArg,
allArgs,
parsedResult
) => {
// A flag for `numericArg` exists if:
// 1. A mocha flag immediately preceeded the numericArg in `allArgs` array and
// 2. `numericArg` value could not be assigned to this flag by `yargs-parser` because of incompatible datatype.
const flag = allArgs.find((arg, index) => {
const normalizedArg = arg.replace(/^--?/, '');
return (
isMochaFlag(arg) &&
allArgs[index + 1] === String(numericArg) &&
parsedResult[normalizedArg] !== String(numericArg)
);
});
if (flag) {
throw createInvalidArgumentTypeError(
`Mocha flag '${flag}' given invalid option: '${numericArg}'`,
numericArg,
expectedTypeForFlag(flag)
);
} else {
throw createUnsupportedError(
`Option ${numericArg} is unsupported by the mocha cli`
);
}
};
/**
* Wrapper around `yargs-parser` which applies our settings

@@ -110,20 +158,16 @@ * @param {string|string[]} args - Arguments to parse

// 1. when these args have a "=" they should be considered to have values
// 2. if they don't, they just boolean flags
// 2. if they don't, they are just boolean flags
// 3. to avoid explicitly defining the set of them, we tell yargs-parser they
// are ALL boolean flags.
// 4. we can then reapply the values after yargs-parser is done.
const nodeArgs = (Array.isArray(args) ? args : args.split(' ')).reduce(
(acc, arg) => {
const pair = arg.split('=');
let flag = pair[0];
if (isNodeFlag(flag, false)) {
flag = flag.replace(/^--?/, '');
return arg.includes('=')
? acc.concat([[flag, pair[1]]])
: acc.concat([[flag, true]]);
}
return acc;
},
[]
);
const allArgs = Array.isArray(args) ? args : args.split(' ');
const nodeArgs = allArgs.reduce((acc, arg) => {
const pair = arg.split('=');
let flag = pair[0];
if (isNodeFlag(flag, false)) {
flag = flag.replace(/^--?/, '');
return acc.concat([[flag, arg.includes('=') ? pair[1] : true]]);
}
return acc;
}, []);

@@ -147,2 +191,11 @@ const result = yargsParser.detailed(args, {

const numericPositionalArg = result.argv._.find(arg => isNumeric(arg));
if (numericPositionalArg) {
createErrorForNumericPositionalArg(
numericPositionalArg,
allArgs,
result.argv
);
}
// reapply "=" arg values from above

@@ -149,0 +202,0 @@ nodeArgs.forEach(([key, value]) => {

@@ -117,1 +117,22 @@ 'use strict';

};
/**
* Returns expected yarg option type for a given mocha flag.
* @param {string} flag - Flag to check (can be with or without leading dashes "--"")
* @returns {string | undefined} - If flag is a valid mocha flag, the expected type of argument for this flag is returned, otherwise undefined is returned.
* @private
*/
exports.expectedTypeForFlag = flag => {
const normalizedName = flag.replace(/^--?/, '');
// If flag is an alias, get it's full name.
const aliases = exports.aliases;
const fullFlagName =
Object.keys(aliases).find(flagName =>
aliases[flagName].includes(normalizedName)
) || normalizedName;
return Object.keys(TYPES).find(flagType =>
TYPES[flagType].includes(fullFlagName)
);
};

@@ -692,1 +692,8 @@ 'use strict';

};
/**
* Checks if provided input can be parsed as a JavaScript Number.
*/
exports.isNumeric = input => {
return !isNaN(parseFloat(input));
};

2

package.json
{
"name": "mocha",
"version": "11.0.1",
"version": "11.0.2",
"type": "commonjs",

@@ -5,0 +5,0 @@ "description": "simple, flexible, fun test framework",

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc