[READ-ONLY] Mirror of https://github.com/vitest-dev/vitest. Next generation testing framework powered by Vite. vitest.dev
test testing-tools vite
12

Configure Feed

Select the types of activity you want to include in your feed.

fix: compat with frozen Math (#3527)

authored by

Turadg Aleahmad and committed by
GitHub
(Jun 20, 2023, 2:31 PM +0200) 0db67098 150cfaac

-8
-4
packages/browser/src/client/rpc.ts
··· 4 4 import type { VitestClient } from '@vitest/ws-client' 5 5 6 6 const { get } = Reflect 7 - const safeRandom = Math.random 8 7 9 8 function withSafeTimers(getTimers: typeof getSafeTimers, fn: () => void) { 10 9 const { setTimeout, clearTimeout, nextTick, setImmediate, clearImmediate } = getTimers() 11 10 12 11 const currentSetTimeout = globalThis.setTimeout 13 12 const currentClearTimeout = globalThis.clearTimeout 14 - const currentRandom = globalThis.Math.random 15 13 const currentNextTick = globalThis.process.nextTick 16 14 const currentSetImmediate = globalThis.setImmediate 17 15 const currentClearImmediate = globalThis.clearImmediate ··· 19 17 try { 20 18 globalThis.setTimeout = setTimeout 21 19 globalThis.clearTimeout = clearTimeout 22 - globalThis.Math.random = safeRandom 23 20 globalThis.process.nextTick = nextTick 24 21 globalThis.setImmediate = setImmediate 25 22 globalThis.clearImmediate = clearImmediate ··· 30 27 finally { 31 28 globalThis.setTimeout = currentSetTimeout 32 29 globalThis.clearTimeout = currentClearTimeout 33 - globalThis.Math.random = currentRandom 34 30 globalThis.setImmediate = currentSetImmediate 35 31 globalThis.clearImmediate = currentClearImmediate 36 32 nextTick(() => {
-4
packages/vitest/src/runtime/rpc.ts
··· 4 4 import { getWorkerState } from '../utils/global' 5 5 6 6 const { get } = Reflect 7 - const safeRandom = Math.random 8 7 9 8 function withSafeTimers(fn: () => void) { 10 9 const { setTimeout, clearTimeout, nextTick, setImmediate, clearImmediate } = getSafeTimers() 11 10 12 11 const currentSetTimeout = globalThis.setTimeout 13 12 const currentClearTimeout = globalThis.clearTimeout 14 - const currentRandom = globalThis.Math.random 15 13 const currentNextTick = globalThis.process.nextTick 16 14 const currentSetImmediate = globalThis.setImmediate 17 15 const currentClearImmediate = globalThis.clearImmediate ··· 19 17 try { 20 18 globalThis.setTimeout = setTimeout 21 19 globalThis.clearTimeout = clearTimeout 22 - globalThis.Math.random = safeRandom 23 20 globalThis.process.nextTick = nextTick 24 21 globalThis.setImmediate = setImmediate 25 22 globalThis.clearImmediate = clearImmediate ··· 30 27 finally { 31 28 globalThis.setTimeout = currentSetTimeout 32 29 globalThis.clearTimeout = currentClearTimeout 33 - globalThis.Math.random = currentRandom 34 30 globalThis.setImmediate = currentSetImmediate 35 31 globalThis.clearImmediate = currentClearImmediate 36 32 nextTick(() => {