Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(env-jsdom): remove setImmediate and clearImmediate #11222

Merged
merged 7 commits into from
Mar 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
- `[babel-plugin-jest-hoist]` Add `__dirname` and `__filename` to whitelisted globals ([#10903](https://github.com/facebook/jest/pull/10903))
- `[expect]` [**BREAKING**] Revise `expect.not.objectContaining()` to be the inverse of `expect.objectContaining()`, as documented. ([#10708](https://github.com/facebook/jest/pull/10708))
- `[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))
- `[expect]` [**BREAKING**] `matcherResult` on `JestAssertionError` are now strings rather than functions ([#10989] (https://github.com/facebook/jest/pull/10989))
- `[expect]` [**BREAKING**] `matcherResult` on `JestAssertionError` are now strings rather than functions ([#10989](https://github.com/facebook/jest/pull/10989))
- `[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)
- `[jest-circus]` Fix `testLocation` on Windows when using `test.each` ([#10871](https://github.com/facebook/jest/pull/10871))
- `[jest-cli]` Use testFailureExitCode when bailing from a failed test ([#10958](https://github.com/facebook/jest/pull/10958))
Expand All @@ -49,10 +49,11 @@
- `[jest-each]` [**BREAKING**] Ignore excess words in headings ([#8766](https://github.com/facebook/jest/pull/8766))
- `[jest-environment]` [**BREAKING**] Drop support for `runScript` for test environments ([#11155](https://github.com/facebook/jest/pull/11155))
- `[jest-environment-jsdom]` Use inner realm’s `ArrayBuffer` constructor ([#10885](https://github.com/facebook/jest/pull/10885))
- `[jest-environment-jsdom]` [**BREAKING**] Remove Node globals `setImmediate` and `clearImmediate` [#11222](https://github.com/facebook/jest/pull/11222)
- `[jest-globals]` [**BREAKING**] Disallow return values other than a `Promise` from hooks and tests ([#10512](https://github.com/facebook/jest/pull/10512))
- `[jest-globals]` [**BREAKING**] Disallow mixing a done callback and returning a `Promise` from hooks and tests ([#10512](https://github.com/facebook/jest/pull/10512))
- `[jest-haste-map]` Vendor `NodeWatcher` from `sane` ([#10919](https://github.com/facebook/jest/pull/10919))
- `[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)
- `[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)
- `[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)
- `[jest-reporter]` Handle empty files when reporting code coverage with V8 ([#10819](https://github.com/facebook/jest/pull/10819))
- `[jest-resolve]` Replace read-pkg-up with escalade package ([#10781](https://github.com/facebook/jest/pull/10781))
Expand Down
4 changes: 3 additions & 1 deletion e2e/env-test/__tests__/equivalent.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ const {isArrayBuffer} = require('util').types;
const isJSDOM =
typeof window !== 'undefined' && typeof document !== 'undefined';

test('Buffer', () => {
const skipTestJSDOM = isJSDOM ? test.skip : test;

skipTestJSDOM('Buffer', () => {
const bufFromArray = Buffer.from([0x62, 0x75, 0x66, 0x66, 0x65, 0x72]);
expect(isArrayBuffer(bufFromArray.buffer)).toBeTruthy();
const bufFromArrayBuffer = Buffer.from(new ArrayBuffer(6));
Expand Down
3 changes: 3 additions & 0 deletions packages/jest-environment-jsdom/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ class JSDOMEnvironment implements JestEnvironment {
this.global.Error.stackTraceLimit = 100;
installCommonGlobals(global as any, config.globals);

// TODO: remove this ASAP, but it currntly causes tests to run really slow
global.Buffer = Buffer;

// Report uncaught errors.
this.errorEventListener = event => {
if (userErrorListenerCount === 0 && event.error) {
Expand Down
4 changes: 4 additions & 0 deletions packages/jest-environment-node/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ class NodeEnvironment implements JestEnvironment {
global.clearTimeout = clearTimeout;
global.setInterval = setInterval;
global.setTimeout = setTimeout;
global.Buffer = Buffer;
global.setImmediate = setImmediate;
global.clearImmediate = clearImmediate;
global.ArrayBuffer = ArrayBuffer;
// TextEncoder (global or via 'util') references a Uint8Array constructor
// different than the global one used by users in tests. This makes sure the
Expand Down Expand Up @@ -64,6 +67,7 @@ class NodeEnvironment implements JestEnvironment {
global.AbortController = AbortController;
}
installCommonGlobals(global, config.globals);

this.moduleMocker = new ModuleMocker(global);

const timerIdToRef = (id: number) => ({
Expand Down
7 changes: 5 additions & 2 deletions packages/jest-matcher-utils/src/deepCyclicCopyReplaceable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@

import {plugins} from 'pretty-format';

const builtInObject = [
const builtInObject: Array<unknown> = [
Array,
Buffer,
Date,
Float32Array,
Float64Array,
Expand All @@ -25,6 +24,10 @@ const builtInObject = [
Uint8ClampedArray,
];

if (typeof Buffer !== 'undefined') {
builtInObject.push(Buffer);
}

const isBuiltInObject = (object: any) =>
builtInObject.includes(object.constructor);

Expand Down
5 changes: 0 additions & 5 deletions packages/jest-util/src/installCommonGlobals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,5 @@ export default function (
};
});

// Forward some others (this breaks the sandbox but for now it's OK).
globalObject.Buffer = global.Buffer;
globalObject.setImmediate = global.setImmediate;
globalObject.clearImmediate = global.clearImmediate;

return Object.assign(globalObject, deepCyclicCopy(globals));
}
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4287,8 +4287,8 @@ __metadata:
linkType: hard

"@testing-library/dom@npm:^7.28.1":
version: 7.29.6
resolution: "@testing-library/dom@npm:7.29.6"
version: 7.30.1
resolution: "@testing-library/dom@npm:7.30.1"
dependencies:
"@babel/code-frame": ^7.10.4
"@babel/runtime": ^7.12.5
Expand All @@ -4298,7 +4298,7 @@ __metadata:
dom-accessibility-api: ^0.5.4
lz-string: ^1.4.4
pretty-format: ^26.6.2
checksum: 6102dabce8526f9ccfd4c4e08d60d1c7f2bd125482587cb4664cd652b9c00dd430faf5e08701513f3d5bfa90e89fdcca26313b9ffe644fd1936bbf449ac62a14
checksum: a886bdb20955e5f029fa10932184128dd701dac866dc8016e66f339d89ab5b63185c3584ea5eb2a5ffbcb779bad6952f1f0933cc47f6772450211cd85b55861e
languageName: node
linkType: hard

Expand Down