Skip to content

armgit / mocha

Public Imported from GitHub
0

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

chore: remove nanoid as dependency (#5024)

Aras Abbasi45e97af81f87
diff --git a/lib/utils.js b/lib/utils.js
index 7e1d5668..fc7271d0 100644
--- a/lib/utils.js
+++ b/lib/utils.js
@@ -8,8 +8,6 @@
/**
* Module dependencies.
*/
-
-const {nanoid} = require('nanoid/non-secure');
var path = require('path');
var util = require('util');
var he = require('he');
@@ -615,11 +613,22 @@ exports.constants = exports.defineConstants({
MOCHA_ID_PROP_NAME
});
+const uniqueIDBase =
+ 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_';
+
/**
* Creates a new unique identifier
+ * Does not create cryptographically safe ids.
+ * Trivial copy of nanoid/non-secure
* @returns {string} Unique identifier
*/
-exports.uniqueID = () => nanoid();
+exports.uniqueID = () => {
+ let id = '';
+ for (let i = 0; i < 21; i++) {
+ id += uniqueIDBase[(Math.random() * 64) | 0];
+ }
+ return id;
+};
exports.assignNewMochaID = obj => {
const id = exports.uniqueID();
diff --git a/package-lock.json b/package-lock.json
index 8f1ed396..542c4097 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -22,7 +22,6 @@
"log-symbols": "4.1.0",
"minimatch": "5.0.1",
"ms": "2.1.3",
- "nanoid": "3.3.3",
"serialize-javascript": "6.0.0",
"strip-json-comments": "3.1.1",
"supports-color": "8.1.1",
@@ -14069,17 +14068,6 @@
"integrity": "sha512-2ZTgtl0nJsO0KQCjEpxcIr5D+Yv90plTitZt9JBfQvVJDS5seMl3FOvsh3+9CoYWXf/1l5OaZzzF6nDm4cagaQ==",
"dev": true
},
- "node_modules/nanoid": {
- "version": "3.3.3",
- "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.3.tgz",
- "integrity": "sha512-p1sjXuopFs0xg+fPASzQ28agW1oHD7xDsd9Xkf3T15H3c/cifrFHVwrh74PdoklAPi+i7MdRsE47vm2r6JoB+w==",
- "bin": {
- "nanoid": "bin/nanoid.cjs"
- },
- "engines": {
- "node": "^10 || ^12 || ^13.7 || ^14 || >=15.0.1"
- }
- },
"node_modules/natural-compare": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz",
@@ -33952,11 +33940,6 @@
"integrity": "sha512-2ZTgtl0nJsO0KQCjEpxcIr5D+Yv90plTitZt9JBfQvVJDS5seMl3FOvsh3+9CoYWXf/1l5OaZzzF6nDm4cagaQ==",
"dev": true
},
- "nanoid": {
- "version": "3.3.3",
- "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.3.tgz",
- "integrity": "sha512-p1sjXuopFs0xg+fPASzQ28agW1oHD7xDsd9Xkf3T15H3c/cifrFHVwrh74PdoklAPi+i7MdRsE47vm2r6JoB+w=="
- },
"natural-compare": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz",
diff --git a/package.json b/package.json
index 14c013a9..89258110 100644
--- a/package.json
+++ b/package.json
@@ -63,7 +63,6 @@
"log-symbols": "4.1.0",
"minimatch": "5.0.1",
"ms": "2.1.3",
- "nanoid": "3.3.3",
"serialize-javascript": "6.0.0",
"strip-json-comments": "3.1.1",
"supports-color": "8.1.1",
diff --git a/test/unit/utils.spec.js b/test/unit/utils.spec.js
index adb36c4c..46f27b57 100644
--- a/test/unit/utils.spec.js
+++ b/test/unit/utils.spec.js
@@ -760,5 +760,8 @@ describe('lib/utils', function () {
it('should return a non-empty string', function () {
expect(utils.uniqueID(), 'to be a string').and('not to be empty');
});
+ it('should have length of 21', function () {
+ expect(utils.uniqueID().length, 'to equal', 21);
+ });
});
});