Skip to content

Commit

Permalink
Try to fix Node.js 18 on CI
Browse files Browse the repository at this point in the history
  • Loading branch information
ai committed Oct 15, 2023
1 parent 87de3c5 commit 45fd836
Showing 1 changed file with 21 additions and 19 deletions.
40 changes: 21 additions & 19 deletions test/index.test.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,34 @@
import { equal, match, notEqual, ok } from 'node:assert'
import { describe, test } from 'node:test'
import { after, before, describe, test } from 'node:test'

import * as browser from '../index.browser.js'
import * as node from '../index.js'

test.before(() => {
Object.defineProperty(global, 'crypto', {
configurable: true,
value: {
getRandomValues(array) {
for (let i = 0; i < array.length; i++) {
array[i] = Math.floor(Math.random() * 256)
}
return array
}
}
})
})

test.after(() => {
Object.defineProperty(global, 'crypto', { value: undefined })
})

for (let type of ['node', 'browser']) {
let { customAlphabet, customRandom, nanoid, random, urlAlphabet } =
type === 'node' ? node : browser

describe(type, () => {
if (type === 'browser') {
before(() => {
Object.defineProperty(global, 'crypto', {
configurable: true,
value: {
getRandomValues(array) {
for (let i = 0; i < array.length; i++) {
array[i] = Math.floor(Math.random() * 256)
}
return array
}
}
})
})

after(() => {
Object.defineProperty(global, 'crypto', { value: undefined })
})
}

test(`generates URL-friendly IDs`, () => {
for (let i = 0; i < 100; i++) {
let id = nanoid()
Expand Down

0 comments on commit 45fd836

Please sign in to comment.