diff --git a/lib/utils.js b/lib/utils.js index 7e1d566819..c573903370 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,20 @@ exports.constants = exports.defineConstants({ MOCHA_ID_PROP_NAME }); +const uniqueIDBase = + 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_'; + /** * Creates a new unique identifier * @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/test/unit/utils.spec.js b/test/unit/utils.spec.js index adb36c4cd6..46f27b57ad 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); + }); }); });