Skip to content

Commit

Permalink
chore: remove nanoid
Browse files Browse the repository at this point in the history
  • Loading branch information
Uzlopak committed Nov 5, 2023
1 parent ee2b70e commit 03578df
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
13 changes: 10 additions & 3 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
/**
* Module dependencies.
*/

const {nanoid} = require('nanoid/non-secure');
var path = require('path');
var util = require('util');
var he = require('he');
Expand Down Expand Up @@ -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();
Expand Down
3 changes: 3 additions & 0 deletions test/unit/utils.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
});

0 comments on commit 03578df

Please sign in to comment.