Socket
Socket
Sign inDemoInstall

mocha

Package Overview
Dependencies
Maintainers
4
Versions
199
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 8.4.0 to 9.0.0

10

lib/cli/lookup-files.js

@@ -11,7 +11,5 @@ 'use strict';

var glob = require('glob');
var {format} = require('util');
var errors = require('../errors');
var createNoFilesMatchPatternError = errors.createNoFilesMatchPatternError;
var createMissingArgumentError = errors.createMissingArgumentError;
var {sQuote, dQuote} = require('../utils');
const debug = require('debug')('mocha:cli:lookup-files');

@@ -95,3 +93,3 @@

throw createNoFilesMatchPatternError(
'Cannot find any files matching pattern ' + dQuote(filepath),
`Cannot find any files matching pattern "${filepath}"`,
filepath

@@ -132,7 +130,3 @@ );

throw createMissingArgumentError(
format(
'Argument %s required when argument %s is a directory',
sQuote('extensions'),
sQuote('filepath')
),
`Argument '${extensions}' required when argument '${filepath}' is a directory`,
'extensions',

@@ -139,0 +133,0 @@ 'array'

1

lib/cli/run-option-metadata.js

@@ -35,2 +35,3 @@ 'use strict';

'diff',
'dry-run',
'exit',

@@ -37,0 +38,0 @@ 'forbid-only',

@@ -86,2 +86,6 @@ 'use strict';

},
'dry-run': {
description: 'Report tests without executing them',
group: GROUPS.RULES
},
exit: {

@@ -88,0 +92,0 @@ description: 'Force Mocha to quit after tests complete',

@@ -33,10 +33,52 @@ const path = require('path');

exports.requireOrImport = async file => {
const hasStableEsmImplementation = (() => {
const [major, minor] = process.version.split('.');
// ESM is stable from v12.22.0 onward
// https://nodejs.org/api/esm.html#esm_modules_ecmascript_modules
return parseInt(major.slice(1), 10) > 12 || parseInt(minor, 10) >= 22;
})();
exports.requireOrImport = hasStableEsmImplementation
? async file => {
if (path.extname(file) === '.mjs') {
return formattedImport(file);
}
try {
return dealWithExports(await formattedImport(file));
} catch (err) {
if (
err.code === 'ERR_MODULE_NOT_FOUND' ||
err.code === 'ERR_UNKNOWN_FILE_EXTENSION'
) {
return require(file);
} else {
throw err;
}
}
}
: implementationOfRequireOrImportForUnstableEsm;
function dealWithExports(module) {
if (module.default) {
return module.default;
} else {
return {...module, default: undefined};
}
}
exports.loadFilesAsync = async (files, preLoadFunc, postLoadFunc) => {
for (const file of files) {
preLoadFunc(file);
const result = await exports.requireOrImport(path.resolve(file));
postLoadFunc(file, result);
}
};
/* istanbul ignore next */
async function implementationOfRequireOrImportForUnstableEsm(file) {
if (path.extname(file) === '.mjs') {
return formattedImport(file);
}
// This is currently the only known way of figuring out whether a file is CJS or ESM.
// If Node.js or the community establish a better procedure for that, we can fix this code.
// Another option here would be to always use `import()`, as this also supports CJS, but I would be
// wary of using it for _all_ existing test files, till ESM is fully stable.
// This is currently the only known way of figuring out whether a file is CJS or ESM in
// Node.js that doesn't necessitate calling `import` first.
try {

@@ -51,10 +93,2 @@ return require(file);

}
};
exports.loadFilesAsync = async (files, preLoadFunc, postLoadFunc) => {
for (const file of files) {
preLoadFunc(file);
const result = await exports.requireOrImport(path.resolve(file));
postLoadFunc(file, result);
}
};
}

@@ -33,3 +33,2 @@ 'use strict';

} = Suite.constants;
var sQuote = utils.sQuote;
var debug = require('debug')('mocha:mocha');

@@ -168,2 +167,3 @@

* @param {boolean} [options.diff] - Show diff on failure?
* @param {boolean} [options.dryRun] - Report tests without running them?
* @param {string} [options.fgrep] - Test filter given string.

@@ -205,3 +205,3 @@ * @param {boolean} [options.forbidOnly] - Tests marked `only` fail the suite?

options.reporter,
options.reporterOption || options.reporterOptions // reporterOptions was previously the only way to specify options to reporter
options.reporterOption || options.reporterOptions // for backwards compability
)

@@ -228,2 +228,3 @@ .slow(options.slow)

'diff',
'dryRun',
'forbidOnly',

@@ -353,13 +354,9 @@ 'forbidPending',

_err.code === 'MODULE_NOT_FOUND'
? warn(sQuote(reporterName) + ' reporter not found')
? warn(`'${reporterName}' reporter not found`)
: warn(
sQuote(reporterName) +
' reporter blew up with error:\n' +
err.stack
`'${reporterName}' reporter blew up with error:\n ${err.stack}`
);
}
} else {
warn(
sQuote(reporterName) + ' reporter blew up with error:\n' + err.stack
);
warn(`'${reporterName}' reporter blew up with error:\n ${err.stack}`);
}

@@ -370,3 +367,3 @@ }

throw createInvalidReporterError(
'invalid reporter ' + sQuote(reporterName),
`invalid reporter '${reporterName}'`,
reporterName

@@ -405,6 +402,3 @@ );

} catch (err) {
throw createInvalidInterfaceError(
'invalid interface ' + sQuote(ui),
ui
);
throw createInvalidInterfaceError(`invalid interface '${ui}'`, ui);
}

@@ -795,2 +789,16 @@ }

/**
* Enables or disables running tests in dry-run mode.
*
* @public
* @see [CLI option](../#-dry-run)
* @param {boolean} [dryRun=true] - Whether to activate dry-run mode.
* @return {Mocha} this
* @chainable
*/
Mocha.prototype.dryRun = function(dryRun) {
this.options.dryRun = dryRun !== false;
return this;
};
/**
* @summary

@@ -1027,2 +1035,3 @@ * Sets timeout threshold value.

delay: options.delay,
dryRun: options.dryRun,
cleanReferencesAfterRun: this._cleanReferencesAfterRun

@@ -1029,0 +1038,0 @@ });

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

var supportsColor = require('supports-color');
var symbols = require('log-symbols');
var constants = require('../runner').constants;

@@ -92,5 +93,5 @@ var EVENT_TEST_PASS = constants.EVENT_TEST_PASS;

exports.symbols = {
ok: '✓',
err: '✖',
dot: '․',
ok: symbols.success,
err: symbols.err,
dot: '.',
comma: ',',

@@ -100,9 +101,2 @@ bang: '!'

// With node.js on Windows: use symbols available in terminal default fonts
if (process.platform === 'win32') {
exports.symbols.ok = '\u221A';
exports.symbols.err = '\u00D7';
exports.symbols.dot = '.';
}
/**

@@ -202,2 +196,9 @@ * Color `str` with the given `type`,

try {
const diffSize = 2048;
if (actual.length > diffSize) {
actual = actual.substring(0, diffSize) + ' ... Lines skipped';
}
if (expected.length > diffSize) {
expected = expected.substring(0, diffSize) + ' ... Lines skipped';
}
return exports.inlineDiffs

@@ -249,6 +250,6 @@ ? inlineDiff(actual, expected)

var message;
if (err.message && typeof err.message.toString === 'function') {
if (typeof err.inspect === 'function') {
message = err.inspect() + '';
} else if (err.message && typeof err.message.toString === 'function') {
message = err.message + '';
} else if (typeof err.inspect === 'function') {
message = err.inspect() + '';
} else {

@@ -255,0 +256,0 @@ message = '';

@@ -7,3 +7,2 @@ 'use strict';

*/
var util = require('util');
var EventEmitter = require('events').EventEmitter;

@@ -23,4 +22,2 @@ var Pending = require('./pending');

var STATE_PENDING = Runnable.constants.STATE_PENDING;
var dQuote = utils.dQuote;
var sQuote = utils.sQuote;
var stackFilter = utils.stackTraceFilter();

@@ -143,4 +140,5 @@ var stringify = utils.stringify;

* @param {Suite} suite - Root suite
* @param {Object|boolean} [opts] - Options. If `boolean`, whether or not to delay execution of root suite until ready (for backwards compatibility).
* @param {Object|boolean} [opts] - Options. If `boolean` (deprecated), whether or not to delay execution of root suite until ready.
* @param {boolean} [opts.delay] - Whether to delay execution of root suite until ready.
* @param {boolean} [opts.dryRun] - Whether to report tests without running them.
* @param {boolean} [opts.cleanReferencesAfterRun] - Whether to clean references to test fns and hooks when a suite is done.

@@ -154,3 +152,6 @@ */

if (typeof opts === 'boolean') {
// TODO: deprecate this
// TODO: remove this
require('./errors').deprecate(
'"Runner(suite: Suite, delay: boolean)" is deprecated. Use "Runner(suite: Suite, {delay: boolean})" instead.'
);
this._delay = opts;

@@ -414,5 +415,4 @@ opts = {};

if (leaks.length) {
var msg = 'global leak(s) detected: %s';
var error = new Error(util.format(msg, leaks.map(sQuote).join(', ')));
this.fail(test, error);
var msg = `global leak(s) detected: ${leaks.map(e => `'${e}'`).join(', ')}`;
this.fail(test, new Error(msg));
}

@@ -484,2 +484,4 @@ };

Runner.prototype.hook = function(name, fn) {
if (this._opts.dryRun) return fn();
var suite = this.suite;

@@ -563,4 +565,3 @@ var hooks = suite.getHooks(name);

if (hook.ctx && hook.ctx.currentTest) {
hook.title =
hook.originalTitle + ' for ' + dQuote(hook.ctx.currentTest.title);
hook.title = `${hook.originalTitle} for "${hook.ctx.currentTest.title}"`;
} else {

@@ -573,3 +574,3 @@ var parentTitle;

}
hook.title = hook.originalTitle + ' in ' + dQuote(parentTitle);
hook.title = `${hook.originalTitle} in "${parentTitle}"`;
}

@@ -620,3 +621,3 @@ }

/**
* Run hooks from the top level down.
* Run 'afterEach' hooks from bottom up.
*

@@ -633,3 +634,3 @@ * @param {String} name

/**
* Run hooks from the bottom up.
* Run 'beforeEach' hooks from top level down.
*

@@ -669,2 +670,4 @@ * @param {String} name

Runner.prototype.runTest = function(fn) {
if (this._opts.dryRun) return fn();
var self = this;

@@ -715,3 +718,2 @@ var test = this.test;

if (self.suite) {
// call hookUp afterEach
self.hookUp(HOOK_TYPE_AFTER_EACH, function(err2, errSuite2) {

@@ -718,0 +720,0 @@ self.suite = orig;

@@ -16,3 +16,2 @@ 'use strict';

var he = require('he');
const errors = require('./errors');

@@ -524,40 +523,2 @@ const MOCHA_ID_PROP_NAME = '__mocha_id__';

/**
* Single quote text by combining with undirectional ASCII quotation marks.
*
* @description
* Provides a simple means of markup for quoting text to be used in output.
* Use this to quote names of variables, methods, and packages.
*
* <samp>package 'foo' cannot be found</samp>
*
* @private
* @param {string} str - Value to be quoted.
* @returns {string} quoted value
* @example
* sQuote('n') // => 'n'
*/
exports.sQuote = function(str) {
return "'" + str + "'";
};
/**
* Double quote text by combining with undirectional ASCII quotation marks.
*
* @description
* Provides a simple means of markup for quoting text to be used in output.
* Use this to quote names of datatypes, classes, pathnames, and strings.
*
* <samp>argument 'value' must be "string" or "number"</samp>
*
* @private
* @param {string} str - Value to be quoted.
* @returns {string} quoted value
* @example
* dQuote('number') // => "number"
*/
exports.dQuote = function(str) {
return '"' + str + '"';
};
/**
* It's a noop.

@@ -655,31 +616,2 @@ * @public

/**
* Lookup file names at the given `path`.
*
* @description
* Filenames are returned in _traversal_ order by the OS/filesystem.
* **Make no assumption that the names will be sorted in any fashion.**
*
* @public
* @alias module:lib/cli.lookupFiles
* @param {string} filepath - Base path to start searching from.
* @param {string[]} [extensions=[]] - File extensions to look for.
* @param {boolean} [recursive=false] - Whether to recurse into subdirectories.
* @return {string[]} An array of paths.
* @throws {Error} if no files match pattern.
* @throws {TypeError} if `filepath` is directory and `extensions` not provided.
* @deprecated Moved to {@link module:lib/cli.lookupFiles}
*/
exports.lookupFiles = (...args) => {
if (exports.isBrowser()) {
throw errors.createUnsupportedError(
'lookupFiles() is only supported in Node.js!'
);
}
errors.deprecate(
'`lookupFiles()` in module `mocha/lib/utils` has moved to module `mocha/lib/cli` and will be removed in the next major revision of Mocha'
);
return require('./cli').lookupFiles(...args);
};
/*

@@ -686,0 +618,0 @@ * Casts `value` to an array; useful for optionally accepting array parameters

{
"name": "mocha",
"version": "8.4.0",
"version": "9.0.0",
"description": "simple, flexible, fun test framework",

@@ -45,3 +45,3 @@ "keywords": [

"engines": {
"node": ">= 10.12.0"
"node": ">= 12.0.0"
},

@@ -64,10 +64,10 @@ "scripts": {

"find-up": "5.0.0",
"glob": "7.1.6",
"glob": "7.1.7",
"growl": "1.10.5",
"he": "1.2.0",
"js-yaml": "4.0.0",
"log-symbols": "4.0.0",
"js-yaml": "4.1.0",
"log-symbols": "4.1.0",
"minimatch": "3.0.4",
"ms": "2.1.3",
"nanoid": "3.1.20",
"nanoid": "3.1.23",
"serialize-javascript": "5.0.1",

@@ -78,3 +78,3 @@ "strip-json-comments": "3.1.1",

"wide-align": "1.1.3",
"workerpool": "6.1.0",
"workerpool": "6.1.4",
"yargs": "16.2.0",

@@ -87,3 +87,7 @@ "yargs-parser": "20.2.4",

"@11ty/eleventy-plugin-inclusive-language": "^1.0.0",
"@babel/preset-env": "^7.12.17",
"@babel/preset-env": "7.12.17",
"@babel/plugin-transform-regenerator": "7.12.1",
"regenerator-transform": "0.14.5",
"@babel/runtime": "7.12.5",
"regenerator-runtime": "0.13.7",
"@mocha/docdash": "^3.0.1",

@@ -90,0 +94,0 @@ "@rollup/plugin-babel": "^5.1.0",

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

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