Skip to content

Commit 973c574

Browse files
authored
#15632 Fix destruction of builtin node globals that was introduced in #15215 (#15636)
1 parent ef5aa2e commit 973c574

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

packages/jest-environment-node/src/__tests__/node_environment.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,8 @@ describe('NodeEnvironment', () => {
8787
test('TextEncoder references the same global Uint8Array constructor', () => {
8888
expect(new TextEncoder().encode('abc')).toBeInstanceOf(Uint8Array);
8989
});
90+
91+
test('dispatch event', () => {
92+
new EventTarget().dispatchEvent(new Event('foo'));
93+
});
9094
});
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
describe('NodeEnvironment 2', () => {
9+
test('dispatch event', () => {
10+
new EventTarget().dispatchEvent(new Event('foo'));
11+
});
12+
});

packages/jest-environment-node/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ export default class NodeEnvironment implements JestEnvironment<Timer> {
102102
Object.getOwnPropertyNames(global) as GlobalProperties,
103103
);
104104
for (const [nodeGlobalsKey, descriptor] of nodeGlobals) {
105+
protectProperties(globalThis[nodeGlobalsKey]);
105106
if (!contextGlobals.has(nodeGlobalsKey)) {
106107
if (descriptor.configurable) {
107108
Object.defineProperty(global, nodeGlobalsKey, {

0 commit comments

Comments
 (0)