Update Mocha to 8.2.1
The changes can be seen here between 8.0.1 and 8.2.1:
https://github.com/mochajs/mocha/releases
There are no breaking changes.
The upgrade will give us the ability to use global fixtures which
may speed up parallel mode. I'm also hoping this fixes a bug with
describe.skip() not working properly for parallel mode.
DISABLE_THIRD_PARTY_CHECK=Update Mocha
Bug: chromium:1101784
Change-Id: Ia052a80c0f6dcefb1a2f21444cdfd3789a3203f8
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2529149
Reviewed-by: Tim van der Lippe <tvanderlippe@chromium.org>
Commit-Queue: Peter Marshall <petermarshall@chromium.org>
diff --git a/node_modules/mocha/lib/errors.js b/node_modules/mocha/lib/errors.js
index 929f563..29f76c6 100644
--- a/node_modules/mocha/lib/errors.js
+++ b/node_modules/mocha/lib/errors.js
@@ -1,13 +1,58 @@
'use strict';
-var format = require('util').format;
+const {format} = require('util');
/**
- * Factory functions to create throwable error objects
- * @module Errors
+ * Contains error codes, factory functions to create throwable error objects,
+ * and warning/deprecation functions.
+ * @module
*/
/**
+ * process.emitWarning or a polyfill
+ * @see https://nodejs.org/api/process.html#process_process_emitwarning_warning_options
+ * @ignore
+ */
+const emitWarning = (msg, type) => {
+ if (process.emitWarning) {
+ process.emitWarning(msg, type);
+ } else {
+ process.nextTick(function() {
+ console.warn(type + ': ' + msg);
+ });
+ }
+};
+
+/**
+ * Show a deprecation warning. Each distinct message is only displayed once.
+ * Ignores empty messages.
+ *
+ * @param {string} [msg] - Warning to print
+ * @private
+ */
+const deprecate = msg => {
+ msg = String(msg);
+ if (msg && !deprecate.cache[msg]) {
+ deprecate.cache[msg] = true;
+ emitWarning(msg, 'DeprecationWarning');
+ }
+};
+deprecate.cache = {};
+
+/**
+ * Show a generic warning.
+ * Ignores empty messages.
+ *
+ * @param {string} [msg] - Warning to print
+ * @private
+ */
+const warn = msg => {
+ if (msg) {
+ emitWarning(msg);
+ }
+};
+
+/**
* When Mocha throw exceptions (or otherwise errors), it attempts to assign a
* `code` property to the `Error` object, for easier handling. These are the
* potential values of `code`.
@@ -59,21 +104,33 @@
UNSUPPORTED: 'ERR_MOCHA_UNSUPPORTED',
/**
- * Invalid state transition occuring in `Mocha` instance
+ * Invalid state transition occurring in `Mocha` instance
*/
INSTANCE_ALREADY_RUNNING: 'ERR_MOCHA_INSTANCE_ALREADY_RUNNING',
/**
- * Invalid state transition occuring in `Mocha` instance
+ * Invalid state transition occurring in `Mocha` instance
*/
INSTANCE_ALREADY_DISPOSED: 'ERR_MOCHA_INSTANCE_ALREADY_DISPOSED',
/**
* Use of `only()` w/ `--forbid-only` results in this error.
*/
- FORBIDDEN_EXCLUSIVITY: 'ERR_MOCHA_FORBIDDEN_EXCLUSIVITY'
+ FORBIDDEN_EXCLUSIVITY: 'ERR_MOCHA_FORBIDDEN_EXCLUSIVITY',
+
+ /**
+ * To be thrown when a user-defined plugin implementation (e.g., `mochaHooks`) is invalid
+ */
+ INVALID_PLUGIN_IMPLEMENTATION: 'ERR_MOCHA_INVALID_PLUGIN_IMPLEMENTATION',
+
+ /**
+ * To be thrown when a builtin or third-party plugin definition (the _definition_ of `mochaHooks`) is invalid
+ */
+ INVALID_PLUGIN_DEFINITION: 'ERR_MOCHA_INVALID_PLUGIN_DEFINITION'
};
+const MOCHA_ERRORS = new Set(Object.values(constants));
+
/**
* Creates an error object to be thrown when no files to be tested could be found using specified pattern.
*
@@ -221,7 +278,7 @@
* @public
* @returns {Error}
*/
-function createInvalidPluginError(message, pluginType, pluginId) {
+function createInvalidLegacyPluginError(message, pluginType, pluginId) {
switch (pluginType) {
case 'reporter':
return createInvalidReporterError(message, pluginId);
@@ -233,6 +290,21 @@
}
/**
+ * **DEPRECATED**. Use {@link createInvalidLegacyPluginError} instead Dynamically creates a plugin-type-specific error based on plugin type
+ * @deprecated
+ * @param {string} message - Error message
+ * @param {"reporter"|"interface"} pluginType - Plugin type. Future: expand as needed
+ * @param {string} [pluginId] - Name/path of plugin, if any
+ * @throws When `pluginType` is not known
+ * @public
+ * @returns {Error}
+ */
+function createInvalidPluginError(...args) {
+ deprecate('Use createInvalidLegacyPluginError() instead');
+ return createInvalidLegacyPluginError(...args);
+}
+
+/**
* Creates an error object to be thrown when a mocha object's `run` method is executed while it is already disposed.
* @param {string} message The error message to be displayed.
* @param {boolean} cleanReferencesAfterRun the value of `cleanReferencesAfterRun`
@@ -315,20 +387,70 @@
return err;
}
+/**
+ * Creates an error object to be thrown when a plugin definition is invalid
+ * @param {string} msg - Error message
+ * @param {PluginDefinition} [pluginDef] - Problematic plugin definition
+ * @public
+ * @returns {Error} Error with code {@link constants.INVALID_PLUGIN_DEFINITION}
+ */
+function createInvalidPluginDefinitionError(msg, pluginDef) {
+ const err = new Error(msg);
+ err.code = constants.INVALID_PLUGIN_DEFINITION;
+ err.pluginDef = pluginDef;
+ return err;
+}
+
+/**
+ * Creates an error object to be thrown when a plugin implementation (user code) is invalid
+ * @param {string} msg - Error message
+ * @param {Object} [opts] - Plugin definition and user-supplied implementation
+ * @param {PluginDefinition} [opts.pluginDef] - Plugin Definition
+ * @param {*} [opts.pluginImpl] - Plugin Implementation (user-supplied)
+ * @public
+ * @returns {Error} Error with code {@link constants.INVALID_PLUGIN_DEFINITION}
+ */
+function createInvalidPluginImplementationError(
+ msg,
+ {pluginDef, pluginImpl} = {}
+) {
+ const err = new Error(msg);
+ err.code = constants.INVALID_PLUGIN_IMPLEMENTATION;
+ err.pluginDef = pluginDef;
+ err.pluginImpl = pluginImpl;
+ return err;
+}
+
+/**
+ * Returns `true` if an error came out of Mocha.
+ * _Can suffer from false negatives, but not false positives._
+ * @public
+ * @param {*} err - Error, or anything
+ * @returns {boolean}
+ */
+const isMochaError = err =>
+ Boolean(err && typeof err === 'object' && MOCHA_ERRORS.has(err.code));
+
module.exports = {
- createInvalidArgumentTypeError: createInvalidArgumentTypeError,
- createInvalidArgumentValueError: createInvalidArgumentValueError,
- createInvalidExceptionError: createInvalidExceptionError,
- createInvalidInterfaceError: createInvalidInterfaceError,
- createInvalidReporterError: createInvalidReporterError,
- createMissingArgumentError: createMissingArgumentError,
- createNoFilesMatchPatternError: createNoFilesMatchPatternError,
- createUnsupportedError: createUnsupportedError,
- createInvalidPluginError: createInvalidPluginError,
- createMochaInstanceAlreadyDisposedError: createMochaInstanceAlreadyDisposedError,
- createMochaInstanceAlreadyRunningError: createMochaInstanceAlreadyRunningError,
- createFatalError: createFatalError,
- createMultipleDoneError: createMultipleDoneError,
- createForbiddenExclusivityError: createForbiddenExclusivityError,
- constants: constants
+ constants,
+ createFatalError,
+ createForbiddenExclusivityError,
+ createInvalidArgumentTypeError,
+ createInvalidArgumentValueError,
+ createInvalidExceptionError,
+ createInvalidInterfaceError,
+ createInvalidLegacyPluginError,
+ createInvalidPluginDefinitionError,
+ createInvalidPluginError,
+ createInvalidPluginImplementationError,
+ createInvalidReporterError,
+ createMissingArgumentError,
+ createMochaInstanceAlreadyDisposedError,
+ createMochaInstanceAlreadyRunningError,
+ createMultipleDoneError,
+ createNoFilesMatchPatternError,
+ createUnsupportedError,
+ deprecate,
+ isMochaError,
+ warn
};