Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 1 addition & 66 deletions lib/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -430,7 +368,6 @@ module.exports = {
createInvalidInterfaceError,
createInvalidLegacyPluginError,
createInvalidPluginDefinitionError,
createInvalidPluginError,
Comment thread
mark-wiemer marked this conversation as resolved.
Resolved
createInvalidPluginImplementationError,
createInvalidReporterError,
createMissingArgumentError,
Expand All @@ -441,7 +378,5 @@ module.exports = {
createTimeoutError,
createUnparsableFileError,
createUnsupportedError,
deprecate,
isMochaError,
warn,
};
23 changes: 0 additions & 23 deletions test/integration/deprecate.spec.js

This file was deleted.

9 changes: 0 additions & 9 deletions test/integration/fixtures/deprecate.fixture.js

This file was deleted.

76 changes: 0 additions & 76 deletions test/unit/errors.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
2 changes: 0 additions & 2 deletions test/unit/mocha.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
/**
Expand Down Expand Up @@ -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");
});
Expand Down
5 changes: 0 additions & 5 deletions test/unit/suite.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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 () {
Expand Down
Loading