From c04713890b0f3f1792f5cc5265ce2b12738dca01 Mon Sep 17 00:00:00 2001 From: William Ferreira da Silva Date: Thu, 29 May 2025 21:56:19 -0300 Subject: [PATCH 1/2] fix(tests): populate Set in idGenerator tests (#266) --- test/idGenerator.test.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/test/idGenerator.test.js b/test/idGenerator.test.js index 21f0821..6028bc8 100644 --- a/test/idGenerator.test.js +++ b/test/idGenerator.test.js @@ -3,7 +3,7 @@ const test = require('node:test') const idGenerator = require('../lib/idGenerator') -const cacheSize = 1 << 7 + 1 +const cacheSize = (1 << 7) + 1 if (Buffer.isEncoding('base64url')) { test('should have no collisions, base64url', async (t) => { @@ -11,12 +11,13 @@ if (Buffer.isEncoding('base64url')) { t.plan(cacheSize) const ids = new Set() - for (let i = 0; i < (cacheSize); ++i) { + for (let i = 0; i < cacheSize; ++i) { const id = idGen() if (ids.has(id)) { t.assert.ifError('had a collision') } t.assert.strictEqual(id.length, 32) + ids.add(id) } }) } @@ -26,11 +27,12 @@ test('should have no collisions, base64', async (t) => { t.plan(cacheSize) const ids = new Set() - for (let i = 0; i < (cacheSize); ++i) { + for (let i = 0; i < cacheSize; ++i) { const id = idGen() if (ids.has(id)) { t.assert.ifError('had a collision') } t.assert.strictEqual(id.length, 32) + ids.add(id) } }) From f9779f4d69df0d83e43101b62ba1fc6e8d4af36a Mon Sep 17 00:00:00 2001 From: William Ferreira da Silva Date: Sun, 1 Jun 2025 09:53:15 -0300 Subject: [PATCH 2/2] fix: correct operator precedence in cacheSize definition --- test/idGenerator.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/idGenerator.test.js b/test/idGenerator.test.js index 6028bc8..afdf2a2 100644 --- a/test/idGenerator.test.js +++ b/test/idGenerator.test.js @@ -3,7 +3,7 @@ const test = require('node:test') const idGenerator = require('../lib/idGenerator') -const cacheSize = (1 << 7) + 1 +const cacheSize = 1 << 7 + 1 if (Buffer.isEncoding('base64url')) { test('should have no collisions, base64url', async (t) => {