Skip to content

armgit / mocha

Public Imported from GitHub
0

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

feat: remove `log-symbols` dependency (#5469)

valadaptiveb92168f5625b
diff --git a/lib/cli/cli.js b/lib/cli/cli.js
index bc702fb1..de30ede2 100755
--- a/lib/cli/cli.js
+++ b/lib/cli/cli.js
@@ -9,7 +9,6 @@
*/
const debug = require("debug")("mocha:cli:cli");
-const symbols = require("log-symbols");
const yargs = require("yargs");
const path = require("node:path");
const {
@@ -27,7 +26,7 @@ const {
version,
discord,
} = require("../../package.json");
-const { cwd } = require("../utils");
+const { cwd, logSymbols } = require("../utils");
/**
* - Accepts an `Array` of arguments
@@ -65,7 +64,7 @@ exports.main = (argv = process.argv.slice(2), mochaArgs) => {
.fail((msg, err, yargs) => {
debug("caught error sometime before command handler: %O", err);
yargs.showHelp();
- console.error(`\n${symbols.error} ${pc.red("ERROR:")} ${msg}`);
+ console.error(`\n${logSymbols.error} ${pc.red("ERROR:")} ${msg}`);
if (!msg) {
// Log raw error and stack when an unexpected error is encountered, to
// make debugging easier (instead of an inactionable "ERROR: null").
diff --git a/lib/cli/run.js b/lib/cli/run.js
index 268c2194..3415811c 100644
--- a/lib/cli/run.js
+++ b/lib/cli/run.js
@@ -7,7 +7,6 @@
* @private
*/
-const symbols = require("log-symbols");
const pc = require("picocolors");
const Mocha = require("../mocha");
const {
@@ -26,7 +25,7 @@ const { ONE_AND_DONES, ONE_AND_DONE_ARGS } = require("./one-and-dones");
const debug = require("debug")("mocha:cli:run");
const defaults = require("../mocharc.json");
const { types, aliases } = require("./run-option-metadata");
-const { isCI } = require("../utils");
+const { isCI, logSymbols } = require("../utils");
/**
* Logical option groups
@@ -359,7 +358,7 @@ exports.builder = (yargs) =>
Object.assign(argv, plugins);
} catch (err) {
// this could be a bad --require, bad reporter, ui, etc.
- console.error(`\n${symbols.error} ${pc.red("ERROR:")}`, err);
+ console.error(`\n${logSymbols.error} ${pc.red("ERROR:")}`, err);
yargs.exit(1);
}
})
diff --git a/lib/cli/watch-run.js b/lib/cli/watch-run.js
index 72f161a8..109997b2 100644
--- a/lib/cli/watch-run.js
+++ b/lib/cli/watch-run.js
@@ -1,6 +1,5 @@
"use strict";
-const logSymbols = require("log-symbols");
const debug = require("debug")("mocha:cli:watch");
const path = require("node:path");
const chokidar = require("chokidar");
@@ -9,6 +8,7 @@ const isPathInside = require("is-path-inside");
const { minimatch } = require("minimatch");
const Context = require("../context");
const collectFiles = require("./collect-files");
+const { logSymbols } = require("../utils");
/**
* @typedef {import('chokidar').FSWatcher} FSWatcher
diff --git a/lib/reporters/base.js b/lib/reporters/base.js
index a091c910..eb25dc71 100644
--- a/lib/reporters/base.js
+++ b/lib/reporters/base.js
@@ -17,7 +17,6 @@ var diff = require("diff");
var milliseconds = require("ms");
var utils = require("../utils");
var supportsColor = require("supports-color");
-var symbols = require("log-symbols");
var constants = require("../runner").constants;
var EVENT_TEST_PASS = constants.EVENT_TEST_PASS;
var EVENT_TEST_FAIL = constants.EVENT_TEST_FAIL;
@@ -101,8 +100,8 @@ exports.colors = {
*/
exports.symbols = {
- ok: symbols.success,
- err: symbols.error,
+ ok: utils.logSymbols.success,
+ err: utils.logSymbols.error,
dot: ".",
comma: ",",
bang: "!",
diff --git a/lib/utils.js b/lib/utils.js
index 9c056f25..b25b7a3e 100644
--- a/lib/utils.js
+++ b/lib/utils.js
@@ -11,6 +11,8 @@
var path = require("node:path");
var util = require("node:util");
var he = require("he");
+var pc = require("picocolors");
+var isUnicodeSupported = require("is-unicode-supported")();
const MOCHA_ID_PROP_NAME = "__mocha_id__";
@@ -711,3 +713,10 @@ exports.isNumeric = (input) => {
exports.isCI = () => {
return !!process.env.CI;
};
+
+exports.logSymbols = {
+ info: pc.blue(isUnicodeSupported ? "ℹ" : "i"),
+ success: pc.green(isUnicodeSupported ? "✔" : "√"),
+ warning: pc.yellow(isUnicodeSupported ? "⚠" : "‼"),
+ error: pc.red(isUnicodeSupported ? "✖" : "×"),
+};
diff --git a/package-lock.json b/package-lock.json
index bd8cb5ca..ba36495e 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -18,8 +18,8 @@
"glob": "^13.0.0",
"he": "^1.2.0",
"is-path-inside": "^3.0.3",
+ "is-unicode-supported": "^0.1.0",
"js-yaml": "^4.1.0",
- "log-symbols": "^4.1.0",
"minimatch": "^9.0.5",
"ms": "^2.1.3",
"picocolors": "^1.1.1",
@@ -4604,6 +4604,7 @@
"version": "4.1.2",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz",
"integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==",
+ "dev": true,
"dependencies": {
"ansi-styles": "^4.1.0",
"supports-color": "^7.1.0"
@@ -4619,6 +4620,7 @@
"version": "7.2.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz",
"integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==",
+ "dev": true,
"dependencies": {
"has-flag": "^4.0.0"
},
@@ -7892,6 +7894,7 @@
"version": "0.1.0",
"resolved": "https://registry.npmjs.org/is-unicode-supported/-/is-unicode-supported-0.1.0.tgz",
"integrity": "sha512-knxG2q4UC3u8stRGyAVJCOdxFmv5DZiRcdlIaAQXAbSfJya+OhopNotLQrstBhququ4ZpuKbDc/8S6mgXgPFPw==",
+ "license": "MIT",
"engines": {
"node": ">=10"
},
@@ -8894,21 +8897,6 @@
"integrity": "sha512-C7IOaBBK/0gMORRBd8OETNx3kmOkgIWIPvyDpZSCTwUrpYmgZwJkjZeOD8ww4xbOUOs4/attY+pciKvadNfFbg==",
"dev": true
},
- "node_modules/log-symbols": {
- "version": "4.1.0",
- "resolved": "https://registry.npmjs.org/log-symbols/-/log-symbols-4.1.0.tgz",
- "integrity": "sha512-8XPvpAA8uyhfteu8pIvQxpJZ7SYYdpUivZpGy6sFsBuKRY/7rQGavedeB8aK+Zkyq6upMFVL/9AW6vOYzfRyLg==",
- "dependencies": {
- "chalk": "^4.1.0",
- "is-unicode-supported": "^0.1.0"
- },
- "engines": {
- "node": ">=10"
- },
- "funding": {
- "url": "https://github.com/sponsors/sindresorhus"
- }
- },
"node_modules/log4js": {
"version": "6.9.1",
"resolved": "https://registry.npmjs.org/log4js/-/log4js-6.9.1.tgz",
diff --git a/package.json b/package.json
index 1c3e7012..372dfa51 100644
--- a/package.json
+++ b/package.json
@@ -99,8 +99,8 @@
"glob": "^13.0.0",
"he": "^1.2.0",
"is-path-inside": "^3.0.3",
+ "is-unicode-supported": "^0.1.0",
"js-yaml": "^4.1.0",
- "log-symbols": "^4.1.0",
"minimatch": "^9.0.5",
"ms": "^2.1.3",
"picocolors": "^1.1.1",