Skip to content

Commit 167aad4

Browse files
authored
fix(env-jsdom): remove setImmediate and clearImmediate (#11222)
1 parent 1afabf5 commit 167aad4

7 files changed

Lines changed: 21 additions & 13 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
- `[babel-plugin-jest-hoist]` Add `__dirname` and `__filename` to whitelisted globals ([#10903](https://github.com/facebook/jest/pull/10903))
3939
- `[expect]` [**BREAKING**] Revise `expect.not.objectContaining()` to be the inverse of `expect.objectContaining()`, as documented. ([#10708](https://github.com/facebook/jest/pull/10708))
4040
- `[expect]` [**BREAKING**] Make `toContain` more strict with the received type ([#10119](https://github.com/facebook/jest/pull/10119) & [#10929](https://github.com/facebook/jest/pull/10929))
41-
- `[expect]` [**BREAKING**] `matcherResult` on `JestAssertionError` are now strings rather than functions ([#10989] (https://github.com/facebook/jest/pull/10989))
41+
- `[expect]` [**BREAKING**] `matcherResult` on `JestAssertionError` are now strings rather than functions ([#10989](https://github.com/facebook/jest/pull/10989))
4242
- `[jest-circus]` Fixed the issue of beforeAll & afterAll hooks getting executed even if it is inside a skipped `describe` block [#10451](https://github.com/facebook/jest/issues/10451)
4343
- `[jest-circus]` Fix `testLocation` on Windows when using `test.each` ([#10871](https://github.com/facebook/jest/pull/10871))
4444
- `[jest-cli]` Use testFailureExitCode when bailing from a failed test ([#10958](https://github.com/facebook/jest/pull/10958))
@@ -49,10 +49,11 @@
4949
- `[jest-each]` [**BREAKING**] Ignore excess words in headings ([#8766](https://github.com/facebook/jest/pull/8766))
5050
- `[jest-environment]` [**BREAKING**] Drop support for `runScript` for test environments ([#11155](https://github.com/facebook/jest/pull/11155))
5151
- `[jest-environment-jsdom]` Use inner realm’s `ArrayBuffer` constructor ([#10885](https://github.com/facebook/jest/pull/10885))
52+
- `[jest-environment-jsdom]` [**BREAKING**] Remove Node globals `setImmediate` and `clearImmediate` [#11222](https://github.com/facebook/jest/pull/11222)
5253
- `[jest-globals]` [**BREAKING**] Disallow return values other than a `Promise` from hooks and tests ([#10512](https://github.com/facebook/jest/pull/10512))
5354
- `[jest-globals]` [**BREAKING**] Disallow mixing a done callback and returning a `Promise` from hooks and tests ([#10512](https://github.com/facebook/jest/pull/10512))
5455
- `[jest-haste-map]` Vendor `NodeWatcher` from `sane` ([#10919](https://github.com/facebook/jest/pull/10919))
55-
- `[jest-jasmine2]` Fixed the issue of beforeAll & afterAll hooks getting executed even if it is inside a skipped `describe` block when it has child `tests` marked as either `only` or `todo` [#10451](https://github.com/facebook/jest/issues/10451)
56+
- `[jest-jasmine2]` Fixed the issue of `beforeAll` & `afterAll` hooks getting executed even if it is inside a skipped `describe` block when it has child `tests` marked as either `only` or `todo` [#10451](https://github.com/facebook/jest/issues/10451)
5657
- `[jest-jasmine2]` Fixed the issues of child `tests` marked with `only` or `todo` getting executed even if it is inside a skipped parent `describe` block [#10451](https://github.com/facebook/jest/issues/10451)
5758
- `[jest-reporter]` Handle empty files when reporting code coverage with V8 ([#10819](https://github.com/facebook/jest/pull/10819))
5859
- `[jest-resolve]` Replace read-pkg-up with escalade package ([#10781](https://github.com/facebook/jest/pull/10781))

e2e/env-test/__tests__/equivalent.test.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ const {isArrayBuffer} = require('util').types;
1010
const isJSDOM =
1111
typeof window !== 'undefined' && typeof document !== 'undefined';
1212

13-
test('Buffer', () => {
13+
const skipTestJSDOM = isJSDOM ? test.skip : test;
14+
15+
skipTestJSDOM('Buffer', () => {
1416
const bufFromArray = Buffer.from([0x62, 0x75, 0x66, 0x66, 0x65, 0x72]);
1517
expect(isArrayBuffer(bufFromArray.buffer)).toBeTruthy();
1618
const bufFromArrayBuffer = Buffer.from(new ArrayBuffer(6));

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ class JSDOMEnvironment implements JestEnvironment {
5353
this.global.Error.stackTraceLimit = 100;
5454
installCommonGlobals(global as any, config.globals);
5555

56+
// TODO: remove this ASAP, but it currntly causes tests to run really slow
57+
global.Buffer = Buffer;
58+
5659
// Report uncaught errors.
5760
this.errorEventListener = event => {
5861
if (userErrorListenerCount === 0 && event.error) {

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ class NodeEnvironment implements JestEnvironment {
3636
global.clearTimeout = clearTimeout;
3737
global.setInterval = setInterval;
3838
global.setTimeout = setTimeout;
39+
global.Buffer = Buffer;
40+
global.setImmediate = setImmediate;
41+
global.clearImmediate = clearImmediate;
3942
global.ArrayBuffer = ArrayBuffer;
4043
// TextEncoder (global or via 'util') references a Uint8Array constructor
4144
// different than the global one used by users in tests. This makes sure the
@@ -64,6 +67,7 @@ class NodeEnvironment implements JestEnvironment {
6467
global.AbortController = AbortController;
6568
}
6669
installCommonGlobals(global, config.globals);
70+
6771
this.moduleMocker = new ModuleMocker(global);
6872

6973
const timerIdToRef = (id: number) => ({

packages/jest-matcher-utils/src/deepCyclicCopyReplaceable.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@
77

88
import {plugins} from 'pretty-format';
99

10-
const builtInObject = [
10+
const builtInObject: Array<unknown> = [
1111
Array,
12-
Buffer,
1312
Date,
1413
Float32Array,
1514
Float64Array,
@@ -25,6 +24,10 @@ const builtInObject = [
2524
Uint8ClampedArray,
2625
];
2726

27+
if (typeof Buffer !== 'undefined') {
28+
builtInObject.push(Buffer);
29+
}
30+
2831
const isBuiltInObject = (object: any) =>
2932
builtInObject.includes(object.constructor);
3033

packages/jest-util/src/installCommonGlobals.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,5 @@ export default function (
6262
};
6363
});
6464

65-
// Forward some others (this breaks the sandbox but for now it's OK).
66-
globalObject.Buffer = global.Buffer;
67-
globalObject.setImmediate = global.setImmediate;
68-
globalObject.clearImmediate = global.clearImmediate;
69-
7065
return Object.assign(globalObject, deepCyclicCopy(globals));
7166
}

yarn.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4287,8 +4287,8 @@ __metadata:
42874287
linkType: hard
42884288

42894289
"@testing-library/dom@npm:^7.28.1":
4290-
version: 7.29.6
4291-
resolution: "@testing-library/dom@npm:7.29.6"
4290+
version: 7.30.1
4291+
resolution: "@testing-library/dom@npm:7.30.1"
42924292
dependencies:
42934293
"@babel/code-frame": ^7.10.4
42944294
"@babel/runtime": ^7.12.5
@@ -4298,7 +4298,7 @@ __metadata:
42984298
dom-accessibility-api: ^0.5.4
42994299
lz-string: ^1.4.4
43004300
pretty-format: ^26.6.2
4301-
checksum: 6102dabce8526f9ccfd4c4e08d60d1c7f2bd125482587cb4664cd652b9c00dd430faf5e08701513f3d5bfa90e89fdcca26313b9ffe644fd1936bbf449ac62a14
4301+
checksum: a886bdb20955e5f029fa10932184128dd701dac866dc8016e66f339d89ab5b63185c3584ea5eb2a5ffbcb779bad6952f1f0933cc47f6772450211cd85b55861e
43024302
languageName: node
43034303
linkType: hard
43044304

0 commit comments

Comments
 (0)