diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 153b1891..033d4c8a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -20,7 +20,7 @@ jobs: - name: Install Node.js uses: actions/setup-node@v3 with: - node-version: 18 + node-version: 19 cache: pnpm - name: Install dependencies run: pnpm install --frozen-lockfile --ignore-scripts @@ -33,6 +33,7 @@ jobs: strategy: matrix: node-version: + - 18 - 16 - 14 name: Node.js ${{ matrix.node-version }} Quick diff --git a/test/async.test.js b/test/async.test.js index ecaa141b..ea1eb19d 100644 --- a/test/async.test.js +++ b/test/async.test.js @@ -5,14 +5,16 @@ import { urlAlphabet } from '../index.js' import * as browser from '../async/index.browser.js' import * as node from '../async/index.js' -global.crypto = { - getRandomValues(array) { - for (let i = 0; i < array.length; i++) { - array[i] = Math.floor(Math.random() * 256) +Object.defineProperty(global, 'crypto', { + value: { + getRandomValues(array) { + for (let i = 0; i < array.length; i++) { + array[i] = Math.floor(Math.random() * 256) + } + return array } - return array } -} +}) function times(size, callback) { let array = [] diff --git a/test/index.test.js b/test/index.test.js index ce0ec1ce..e12aa5ef 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -5,14 +5,16 @@ import * as browser from '../index.browser.js' import * as node from '../index.js' test.before(() => { - global.crypto = { - getRandomValues(array) { - for (let i = 0; i < array.length; i++) { - array[i] = Math.floor(Math.random() * 256) + Object.defineProperty(global, 'crypto', { + value: { + getRandomValues(array) { + for (let i = 0; i < array.length; i++) { + array[i] = Math.floor(Math.random() * 256) + } + return array } - return array } - } + }) }) test.after(() => { diff --git a/test/react-native-polyfill.test.js b/test/react-native-polyfill.test.js index 7dd730ab..642e13d2 100644 --- a/test/react-native-polyfill.test.js +++ b/test/react-native-polyfill.test.js @@ -8,19 +8,20 @@ test.before(() => { product: 'ReactNative' } - global.crypto = { - getRandomValues(array) { - for (let i = 0; i < array.length; i++) { - array[i] = Math.floor(Math.random() * 256) + Object.defineProperty(global, 'crypto', { + value: { + getRandomValues(array) { + for (let i = 0; i < array.length; i++) { + array[i] = Math.floor(Math.random() * 256) + } + return array } - return array } - } + }) }) test.after(() => { delete global.navigator - delete global.crypto }) test('works with polyfill', () => {