Skip to content

Commit 71d53fe

Browse files
committed
console: Fix cypress
1 parent b30bf9b commit 71d53fe

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

cypress/support/utils.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,18 @@ const generateJoinServerOnlyConfig = config => {
124124
* @param {number} length - The length of the resulting hex value.
125125
* @returns {string} - Pseudorandom hex value of length `length`.
126126
*/
127-
const generateHexValue = length => crypto.randomBytes(Math.floor(length / 2)).toString('hex')
127+
const generateHexValue = (length) => {
128+
const byteLen = Math.ceil(length / 2)
129+
const bytes = new Uint8Array(byteLen)
130+
if (globalThis.crypto?.getRandomValues) {
131+
globalThis.crypto.getRandomValues(bytes)
132+
} else {
133+
for (let i = 0; i < byteLen; i++) bytes[i] = Math.floor(Math.random() * 256)
134+
}
135+
let hex = ''
136+
for (let i = 0; i < byteLen; i++) hex += bytes[i].toString(16).padStart(2, '0')
137+
return hex.slice(0, length)
138+
}
128139

129140
const generateCollaborator = (entity, type) => {
130141
const collabUserId = 'test-collab-user'

0 commit comments

Comments
 (0)