Skip to content

Commit

Permalink
chore: instead of putting everyting on global, allow some to be rewri…
Browse files Browse the repository at this point in the history
…tten
  • Loading branch information
sheremet-va committed Feb 18, 2022
1 parent eb7f373 commit 3e5a634
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 18 deletions.
14 changes: 4 additions & 10 deletions packages/vitest/src/integrations/env/utils.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
import { getDescriptor } from '../../utils'
import { KEYS } from './jsdom-keys'

const filterKeys = new Set([
'clearInterval',
'clearTimeout',
'setInterval',
'setTimeout'
const allowRewrite = new Set([
'Event',
])

export function getWindowKeys(global: any, win: any) {
const keys = new Set(KEYS.concat(Object.getOwnPropertyNames(win))
.filter((k) => {
if (k.startsWith('_')) return false
if (k in global) {
const descriptor = getDescriptor(global, k)
if (!descriptor) return true
return descriptor.configurable === true
return allowRewrite.has(k)
}
return !filterKeys.has(k)
return true
}))

return keys
Expand Down
8 changes: 0 additions & 8 deletions packages/vitest/src/utils/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,6 @@ function isMergableObject(item: any): item is Object {
return isPlainObject(item) && !Array.isArray(item)
}

export function getDescriptor(obj: any, key: string): PropertyDescriptor | undefined {
if (!isObject(obj)) return undefined
const descriptor = Object.getOwnPropertyDescriptor(obj, key)
if (descriptor) return descriptor
const proto = Object.getPrototypeOf(obj)
return getDescriptor(proto, key)
}

export function assertTypes(value: unknown, name: string, types: string[]): void {
const receivedType = typeof value
const pass = types.includes(receivedType)
Expand Down

0 comments on commit 3e5a634

Please sign in to comment.