diff --git a/CHANGELOG.md b/CHANGELOG.md index 9c38f3bf4195..d00f74cc0afb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)) @@ -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)) diff --git a/e2e/env-test/__tests__/equivalent.test.js b/e2e/env-test/__tests__/equivalent.test.js index 7bc5ed20dd0b..9e21e72724c6 100644 --- a/e2e/env-test/__tests__/equivalent.test.js +++ b/e2e/env-test/__tests__/equivalent.test.js @@ -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)); diff --git a/packages/jest-environment-jsdom/src/index.ts b/packages/jest-environment-jsdom/src/index.ts index 9e795c520d4d..421370bcf628 100644 --- a/packages/jest-environment-jsdom/src/index.ts +++ b/packages/jest-environment-jsdom/src/index.ts @@ -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) { diff --git a/packages/jest-environment-node/src/index.ts b/packages/jest-environment-node/src/index.ts index 6cbb18339880..ebf6d4648e4f 100644 --- a/packages/jest-environment-node/src/index.ts +++ b/packages/jest-environment-node/src/index.ts @@ -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 @@ -64,6 +67,7 @@ class NodeEnvironment implements JestEnvironment { global.AbortController = AbortController; } installCommonGlobals(global, config.globals); + this.moduleMocker = new ModuleMocker(global); const timerIdToRef = (id: number) => ({ diff --git a/packages/jest-matcher-utils/src/deepCyclicCopyReplaceable.ts b/packages/jest-matcher-utils/src/deepCyclicCopyReplaceable.ts index 8928927b8d2d..9c3dd0ac9d26 100644 --- a/packages/jest-matcher-utils/src/deepCyclicCopyReplaceable.ts +++ b/packages/jest-matcher-utils/src/deepCyclicCopyReplaceable.ts @@ -7,9 +7,8 @@ import {plugins} from 'pretty-format'; -const builtInObject = [ +const builtInObject: Array = [ Array, - Buffer, Date, Float32Array, Float64Array, @@ -25,6 +24,10 @@ const builtInObject = [ Uint8ClampedArray, ]; +if (typeof Buffer !== 'undefined') { + builtInObject.push(Buffer); +} + const isBuiltInObject = (object: any) => builtInObject.includes(object.constructor); diff --git a/packages/jest-util/src/installCommonGlobals.ts b/packages/jest-util/src/installCommonGlobals.ts index ece4a40649d0..7f3526c8772f 100644 --- a/packages/jest-util/src/installCommonGlobals.ts +++ b/packages/jest-util/src/installCommonGlobals.ts @@ -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)); } diff --git a/yarn.lock b/yarn.lock index a0d3a5e91284..5711142a16dd 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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 @@ -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