Skip to content

armgit / mocha

Public Imported from GitHub
0

☕️ Classic, reliable, trusted test framework for Node.js and the browser

refactor!: remove unused legacy `errors.js` functions (#5835)

Pelle Wessman41163689264c
diff --git a/lib/errors.js b/lib/errors.js
index 7c1eb298..97509f49 100644
--- a/lib/errors.js
+++ b/lib/errors.js
@@ -12,56 +12,10 @@ const { constants } = require("./error-constants.mjs");
const { isCI } = require("./utils");
/**
- * Contains error codes, factory functions to create throwable error objects,
- * and warning/deprecation functions.
+ * Contains error codes and factory functions to create throwable error objects
* @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 {
- /* istanbul ignore next */
- 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);
- }
-};
-
/**
* A set containing all string values of all Mocha error constants, for use by {@link isMochaError}.
* @private
@@ -235,22 +189,6 @@ function createInvalidLegacyPluginError(message, pluginType, pluginId) {
}
}
-/**
- * **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
- * @static
- * @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.
@@ -430,7 +368,6 @@ module.exports = {
createInvalidInterfaceError,
createInvalidLegacyPluginError,
createInvalidPluginDefinitionError,
- createInvalidPluginError,
createInvalidPluginImplementationError,
createInvalidReporterError,
createMissingArgumentError,
@@ -441,7 +378,5 @@ module.exports = {
createTimeoutError,
createUnparsableFileError,
createUnsupportedError,
- deprecate,
isMochaError,
- warn,
};
diff --git a/test/integration/deprecate.spec.js b/test/integration/deprecate.spec.js
deleted file mode 100644
index 20345330..00000000
--- a/test/integration/deprecate.spec.js
+++ /dev/null
@@ -1,23 +0,0 @@
-"use strict";
-
-var assert = require("node:assert");
-var run = require("./helpers").runMocha;
-var args = [];
-
-describe("utils.deprecate test", function () {
- it("should print unique deprecation only once", function (done) {
- run(
- "deprecate.fixture.js",
- args,
- function (err, res) {
- if (err) {
- return done(err);
- }
- var result = res.output.match(/deprecated thing/g) || [];
- assert.strictEqual(result.length, 2);
- done();
- },
- { stdio: "pipe" },
- );
- });
-});
diff --git a/test/integration/fixtures/deprecate.fixture.js b/test/integration/fixtures/deprecate.fixture.js
deleted file mode 100644
index 031ad74a..00000000
--- a/test/integration/fixtures/deprecate.fixture.js
+++ /dev/null
@@ -1,9 +0,0 @@
-'use strict';
-
-var errors = require("../../../lib/errors");
-
-it('consolidates identical calls to deprecate', function() {
- errors.deprecate("suite foo did a deprecated thing");
- errors.deprecate("suite foo did a deprecated thing");
- errors.deprecate("suite bar did a deprecated thing");
-});
diff --git a/test/unit/errors.spec.js b/test/unit/errors.spec.js
index 844980e5..2b258aa8 100644
--- a/test/unit/errors.spec.js
+++ b/test/unit/errors.spec.js
@@ -83,82 +83,6 @@ describe("Errors", function () {
});
});
- describe("deprecate()", function () {
- var emitWarning;
-
- beforeEach(function () {
- if (process.emitWarning) {
- emitWarning = process.emitWarning;
- sinon.stub(process, "emitWarning");
- } else {
- process.emitWarning = sinon.spy();
- }
- errors.deprecate.cache = {};
- });
-
- afterEach(function () {
- // if this is not set, then we created it, so we should remove it.
- if (!emitWarning) {
- delete process.emitWarning;
- }
- });
-
- it("should coerce its parameter to a string", function () {
- errors.deprecate(1);
- expect(process.emitWarning, "to have a call satisfying", [
- "1",
- "DeprecationWarning",
- ]);
- });
-
- it("should cache the message", function () {
- errors.deprecate("foo");
- errors.deprecate("foo");
- expect(process.emitWarning, "was called times", 1);
- });
-
- it("should ignore falsy messages", function () {
- errors.deprecate("");
- expect(process.emitWarning, "was not called");
- });
- });
-
- describe("warn()", function () {
- var emitWarning;
-
- beforeEach(function () {
- if (process.emitWarning) {
- emitWarning = process.emitWarning;
- sinon.stub(process, "emitWarning");
- } else {
- process.emitWarning = sinon.spy();
- }
- });
-
- afterEach(function () {
- // if this is not set, then we created it, so we should remove it.
- if (!emitWarning) {
- delete process.emitWarning;
- }
- });
-
- it("should call process.emitWarning", function () {
- errors.warn("foo");
- expect(process.emitWarning, "was called times", 1);
- });
-
- it("should not cache messages", function () {
- errors.warn("foo");
- errors.warn("foo");
- expect(process.emitWarning, "was called times", 2);
- });
-
- it("should ignore falsy messages", function () {
- errors.warn("");
- expect(process.emitWarning, "was not called");
- });
- });
-
describe("isMochaError()", function () {
describe("when provided an Error object having a known Mocha error code", function () {
it("should return true", function () {
diff --git a/test/unit/mocha.spec.js b/test/unit/mocha.spec.js
index 511ce653..a2efc505 100644
--- a/test/unit/mocha.spec.js
+++ b/test/unit/mocha.spec.js
@@ -4,7 +4,6 @@ var sinon = require("sinon");
var EventEmitter = require("node:events").EventEmitter;
var Mocha = require("../../lib/mocha");
var utils = require("../../lib/utils");
-const errors = require("../../lib/errors");
describe("Mocha", function () {
/**
@@ -78,7 +77,6 @@ describe("Mocha", function () {
Suite = sinon.stub(Mocha, "Suite").returns(suite);
Suite.constants = {};
- sinon.stub(errors, "warn");
sinon.stub(utils, "isString");
sinon.stub(utils, "noop");
});
diff --git a/test/unit/suite.spec.js b/test/unit/suite.spec.js
index c66cf149..daa4ae15 100644
--- a/test/unit/suite.spec.js
+++ b/test/unit/suite.spec.js
@@ -3,7 +3,6 @@
const Mocha = require("../../lib/mocha");
const { Suite, Test, Context } = Mocha;
const sinon = require("sinon");
-const errors = require("../../lib/errors");
function supportsFunctionNames() {
return function foo() {}.name === "foo";
@@ -527,10 +526,6 @@ describe("Suite", function () {
});
describe("constructor", function () {
- beforeEach(function () {
- sinon.stub(errors, "deprecate");
- });
-
/* eslint no-new: off */
it("should throw an error if the title isn't a string", function () {
expect(function () {