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 buffer property is not ArrayBuffer issue. #7626

Merged
merged 2 commits into from
Jan 14, 2019
Merged

Conversation

H1Gdev
Copy link
Contributor

@H1Gdev H1Gdev commented Jan 14, 2019

In node environment Buffer class buffer property become ArrayBuffer.

  • Set ArrayBuffer to global.ArrayBuffer.
  • Add tests.

Summary

In the following code.

const bufFromArray = Buffer.from([0x62, 0x75, 0x66, 0x66, 0x65, 0x72]);
bufFromArray.buffer instanceof ArrayBuffer; // (A)
const bufFromArrayBuffer = Buffer.from(new ArrayBuffer(6));
bufFromArrayBuffer.buffer instanceof ArrayBuffer; // (B)

Execute in each environment.(--env=node, --env=jsdom, and node)

Expect:

  • (A) and (B) are always true.

Actual:

  • In --env=node, (A) is not true.

ref.
https://nodejs.org/api/buffer.html#buffer_buf_buffer

Test plan

  • The same results in all environments.

In node environment Buffer class buffer property become ArrayBuffer.

* Set ArrayBuffer to global.ArrayBuffer.
* Add tests.
Copy link
Member

@SimenB SimenB left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thanks! I've verified in the node repl that they should pass instanceof, so this change is correct

Mind updating the changelog? 🙂

@codecov-io
Copy link

Codecov Report

Merging #7626 into master will decrease coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #7626      +/-   ##
==========================================
- Coverage   68.27%   68.26%   -0.01%     
==========================================
  Files         249      249              
  Lines        9623     9624       +1     
  Branches        5        6       +1     
==========================================
  Hits         6570     6570              
- Misses       3051     3052       +1     
  Partials        2        2
Impacted Files Coverage Δ
packages/jest-environment-node/src/index.js 62.06% <100%> (+1.35%) ⬆️
packages/jest-circus/src/utils.js 19.83% <0%> (-0.66%) ⬇️
packages/babel-plugin-jest-hoist/src/index.js 0% <0%> (ø) ⬆️
...ages/jest-worker/src/workers/ChildProcessWorker.js 88.37% <0%> (ø) ⬆️
...es/pretty-format/src/plugins/ReactTestComponent.js 100% <0%> (ø) ⬆️
packages/jest-haste-map/src/worker.js 94.44% <0%> (ø) ⬆️
packages/jest-cli/src/watch.js 81.14% <0%> (ø) ⬆️
packages/jest-cli/src/plugins/quit.js 42.85% <0%> (ø) ⬆️
...ackages/jest-util/src/convertDescriptorToString.js 0% <0%> (ø) ⬆️
packages/jest-circus/src/eventHandler.js 12% <0%> (+0.15%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 258c170...142cc35. Read the comment docs.

@SimenB SimenB merged commit 805ec3c into jestjs:master Jan 14, 2019
@H1Gdev H1Gdev deleted the environment branch January 14, 2019 15:21
captain-yossarian pushed a commit to captain-yossarian/jest that referenced this pull request Jul 18, 2019
PsychoLlama added a commit to PsychoLlama/bin-json that referenced this pull request May 22, 2020
There was an unfortunate quirk of upgrading Jest. They changed their
node globals to include an `ArrayBuffer` override, synchronizing the
value with `Buffer.from([]).buffer.constructor`. I didn't dive too deep,
but what became clear was `new Uint8Array(0).buffer` and
`Buffer.from([]).buffer` reference different `ArrayBuffer` constructors.
This failed the tests because I was comparing the constructor from two
separate realms.

See: jestjs/jest#7626

This affects production code, not just tests. Because the global
constructor was different between environments, it forced me to check by
string tag instead of instance. That's probably a good change anyway.

I manually checked the string tag in Node, IE11, Firefox, and Chrome.
@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants