jest-environment-node
Advanced tools
Comparing version 28.0.0-alpha.9 to 28.0.0-alpha.10
@@ -61,6 +61,22 @@ 'use strict'; | ||
'ArrayBuffer', | ||
'Uint8Array' | ||
'Uint8Array', // if env is loaded within a jest test | ||
'jest-symbol-do-not-touch' | ||
]); | ||
const nodeGlobals = new Set( | ||
Object.getOwnPropertyNames(globalThis).filter(global => !denyList.has(global)) | ||
const nodeGlobals = new Map( | ||
Object.getOwnPropertyNames(globalThis) | ||
.filter(global => !denyList.has(global)) | ||
.map(nodeGlobalsKey => { | ||
const descriptor = Object.getOwnPropertyDescriptor( | ||
globalThis, | ||
nodeGlobalsKey | ||
); | ||
if (!descriptor) { | ||
throw new Error( | ||
`No property descriptor for ${nodeGlobalsKey}, this is a bug in Jest.` | ||
); | ||
} | ||
return [nodeGlobalsKey, descriptor]; | ||
}) | ||
); | ||
@@ -84,6 +100,31 @@ | ||
for (const nodeGlobalsKey of nodeGlobals) { | ||
for (const [nodeGlobalsKey, descriptor] of nodeGlobals) { | ||
if (!contextGlobals.has(nodeGlobalsKey)) { | ||
// @ts-expect-error | ||
global[nodeGlobalsKey] = globalThis[nodeGlobalsKey]; | ||
Object.defineProperty(global, nodeGlobalsKey, { | ||
configurable: descriptor.configurable, | ||
enumerable: descriptor.enumerable, | ||
get() { | ||
// @ts-expect-error | ||
const val = globalThis[nodeGlobalsKey]; // override lazy getter | ||
Object.defineProperty(global, nodeGlobalsKey, { | ||
configurable: descriptor.configurable, | ||
enumerable: descriptor.enumerable, | ||
value: val, | ||
writable: descriptor.writable | ||
}); | ||
return val; | ||
}, | ||
set(val) { | ||
// override lazy getter | ||
Object.defineProperty(global, nodeGlobalsKey, { | ||
configurable: descriptor.configurable, | ||
enumerable: descriptor.enumerable, | ||
value: val, | ||
writable: true | ||
}); | ||
} | ||
}); | ||
} | ||
@@ -90,0 +131,0 @@ } |
{ | ||
"name": "jest-environment-node", | ||
"version": "28.0.0-alpha.9", | ||
"version": "28.0.0-alpha.10", | ||
"repository": { | ||
@@ -36,3 +36,3 @@ "type": "git", | ||
}, | ||
"gitHead": "7c63f5981eb20d4b89a4c04f3675e0050d8d7887" | ||
"gitHead": "d5eda7f23571081cea24760261d209ff3e01a084" | ||
} |
7942
196