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(jest‑environment‑jsdom): Use inner realm’s ArrayBuffer constructor #10885

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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
24 changes: 23 additions & 1 deletion e2e/env-test/__tests__/equivalent.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
});
4 changes: 0 additions & 4 deletions packages/jest-environment-jsdom/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down