Skip to content

Commit

Permalink
fix(jest‑environment‑jsdom): Use inner realm’s ArrayBuffer constructor (
Browse files Browse the repository at this point in the history
  • Loading branch information
ExE-Boss authored Nov 29, 2020
1 parent 245a582 commit daf4d02
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
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

0 comments on commit daf4d02

Please sign in to comment.