@@ -292,36 +292,29 @@ describe('checkOrSetAlreadyCaught()', () => {
292292
293293describe ( 'uuid4 generation' , ( ) => {
294294 const uuid4Regex = / ^ [ 0 - 9 A - F ] { 12 } [ 4 ] [ 0 - 9 A - F ] { 3 } [ 8 9 A B ] [ 0 - 9 A - F ] { 15 } $ / i;
295- it ( 'returns valid uuid v4 ids via Math.random' , ( ) => {
295+ it ( 'returns valid and unique uuid v4 ids via Math.random' , ( ) => {
296+ const uuids = new Set < string > ( ) ;
296297 for ( let index = 0 ; index < 1_000 ; index ++ ) {
297- expect ( uuid4 ( ) ) . toMatch ( uuid4Regex ) ;
298- }
299- } ) ;
300-
301- it ( 'returns valid uuid v4 ids via crypto.getRandomValues' , ( ) => {
302- // eslint-disable-next-line @typescript-eslint/no-var-requires
303- const cryptoMod = require ( 'crypto' ) ;
304-
305- const crypto = { getRandomValues : cryptoMod . getRandomValues } ;
306-
307- for ( let index = 0 ; index < 1_000 ; index ++ ) {
308- expect ( uuid4 ( crypto ) ) . toMatch ( uuid4Regex ) ;
298+ const id = uuid4 ( ) ;
299+ expect ( id ) . toMatch ( uuid4Regex ) ;
300+ uuids . add ( id ) ;
309301 }
302+ expect ( uuids . size ) . toBe ( 1_000 ) ;
310303 } ) ;
311304
312305 it ( 'returns valid uuid v4 ids via crypto.randomUUID' , ( ) => {
313306 // eslint-disable-next-line @typescript-eslint/no-var-requires
314307 const cryptoMod = require ( 'crypto' ) ;
315308
316- const crypto = { getRandomValues : cryptoMod . getRandomValues , randomUUID : cryptoMod . randomUUID } ;
309+ const crypto = { randomUUID : cryptoMod . randomUUID } ;
317310
318311 for ( let index = 0 ; index < 1_000 ; index ++ ) {
319312 expect ( uuid4 ( crypto ) ) . toMatch ( uuid4Regex ) ;
320313 }
321314 } ) ;
322315
323316 it ( "return valid uuid v4 even if crypto doesn't exists" , ( ) => {
324- const crypto = { getRandomValues : undefined , randomUUID : undefined } ;
317+ const crypto = { randomUUID : undefined } ;
325318
326319 for ( let index = 0 ; index < 1_000 ; index ++ ) {
327320 expect ( uuid4 ( crypto ) ) . toMatch ( uuid4Regex ) ;
@@ -330,9 +323,6 @@ describe('uuid4 generation', () => {
330323
331324 it ( 'return valid uuid v4 even if crypto invoked causes an error' , ( ) => {
332325 const crypto = {
333- getRandomValues : ( ) => {
334- throw new Error ( 'yo' ) ;
335- } ,
336326 randomUUID : ( ) => {
337327 throw new Error ( 'yo' ) ;
338328 } ,
@@ -342,25 +332,4 @@ describe('uuid4 generation', () => {
342332 expect ( uuid4 ( crypto ) ) . toMatch ( uuid4Regex ) ;
343333 }
344334 } ) ;
345-
346- // Corner case related to crypto.getRandomValues being only
347- // semi-implemented (e.g. Chromium 23.0.1235.0 (151422))
348- it ( 'returns valid uuid v4 even if crypto.getRandomValues does not return a typed array' , ( ) => {
349- // eslint-disable-next-line @typescript-eslint/no-var-requires
350- const cryptoMod = require ( 'crypto' ) ;
351-
352- const getRandomValues = ( typedArray : Uint8Array ) => {
353- if ( cryptoMod . getRandomValues ) {
354- cryptoMod . getRandomValues ( typedArray ) ;
355- }
356- } ;
357-
358- const crypto = { getRandomValues } ;
359-
360- for ( let index = 0 ; index < 1_000 ; index ++ ) {
361- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
362- // @ts -ignore - we are testing a corner case
363- expect ( uuid4 ( crypto ) ) . toMatch ( uuid4Regex ) ;
364- }
365- } ) ;
366335} ) ;
0 commit comments