From b3aeaae92d0f52a71baee9b839cae05184ab251f Mon Sep 17 00:00:00 2001 From: ExE Boss <3889017+ExE-Boss@users.noreply.github.com> Date: Sun, 29 Nov 2020 11:50:00 +0100 Subject: [PATCH 1/2] =?UTF-8?q?fix(jest=E2=80=91environment=E2=80=91jsdom)?= =?UTF-8?q?:=20Use=C2=A0inner=C2=A0realm=E2=80=99s=20ArrayBuffer=C2=A0cons?= =?UTF-8?q?tructor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- e2e/env-test/__tests__/equivalent.test.js | 24 +++++++++++++++++++- packages/jest-environment-jsdom/src/index.ts | 4 ---- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/e2e/env-test/__tests__/equivalent.test.js b/e2e/env-test/__tests__/equivalent.test.js index 710ee767940e..7bc5ed20dd0b 100644 --- a/e2e/env-test/__tests__/equivalent.test.js +++ b/e2e/env-test/__tests__/equivalent.test.js @@ -6,9 +6,31 @@ */ 'use strict'; +const {isArrayBuffer} = require('util').types; +const isJSDOM = + typeof window !== 'undefined' && typeof document !== 'undefined'; + test('Buffer', () => { const bufFromArray = Buffer.from([0x62, 0x75, 0x66, 0x66, 0x65, 0x72]); - expect(bufFromArray.buffer instanceof ArrayBuffer).toBeTruthy(); + expect(isArrayBuffer(bufFromArray.buffer)).toBeTruthy(); const bufFromArrayBuffer = Buffer.from(new ArrayBuffer(6)); expect(bufFromArrayBuffer.buffer instanceof ArrayBuffer).toBeTruthy(); }); + +test.each([ + ['Int8Array', Int8Array, isJSDOM], + ['Int16Array', Int16Array, isJSDOM], + ['Int32Array', Int32Array, isJSDOM], + ['Uint8Array', Uint8Array], + ['Uint8ClampedArray', Uint8ClampedArray, isJSDOM], + ['Uint16Array', Uint16Array, isJSDOM], + ['Uint32Array', Uint32Array, isJSDOM], + ['Float32Array', Float32Array, isJSDOM], + ['Float64Array', Float64Array, isJSDOM], +])('%s', (name, ctor, testInstanceof = true) => { + const typedArray = ctor.of(); + expect(isArrayBuffer(typedArray.buffer)).toBeTruthy(); + if (testInstanceof) { + expect(typedArray.buffer instanceof ArrayBuffer).toBeTruthy(); + } +}); diff --git a/packages/jest-environment-jsdom/src/index.ts b/packages/jest-environment-jsdom/src/index.ts index cb383201364b..b466af646069 100644 --- a/packages/jest-environment-jsdom/src/index.ts +++ b/packages/jest-environment-jsdom/src/index.ts @@ -48,10 +48,6 @@ class JSDOMEnvironment implements JestEnvironment { // for "universal" code (code should use `globalThis`) global.global = global; - // In the `jsdom@16`, ArrayBuffer was not added to Window, ref: https://github.com/jsdom/jsdom/commit/3a4fd6258e6b13e9cf8341ddba60a06b9b5c7b5b - // Install ArrayBuffer to Window to fix it. Make sure the test is passed, ref: https://github.com/facebook/jest/pull/7626 - global.ArrayBuffer = ArrayBuffer; - // Node's error-message stack size is limited at 10, but it's pretty useful // to see more than that when a test fails. this.global.Error.stackTraceLimit = 100; From 80ec956ff59fbcf03aef44b7fa7e5495831db662 Mon Sep 17 00:00:00 2001 From: ExE Boss <3889017+ExE-Boss@users.noreply.github.com> Date: Sun, 29 Nov 2020 14:00:00 +0100 Subject: [PATCH 2/2] =?UTF-8?q?fixup!=20fix(jest=E2=80=91environment?= =?UTF-8?q?=E2=80=91jsdom):=20Use=C2=A0inner=C2=A0realm=E2=80=99s=20ArrayB?= =?UTF-8?q?uffer=C2=A0constructor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3cfecb820074..abeb94985e4e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ - `[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-console]` `console.dir` now respects the second argument correctly ([#10638](https://github.com/facebook/jest/pull/10638)) +- `[jest-environment-jsdom]` Use inner realm’s `ArrayBuffer` constructor ([#10885](https://github.com/facebook/jest/pull/10885)) - `[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))