-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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 TextEncoder.encode not referencing same global Uint8Array constructor #9261
Merged
SimenB
merged 7 commits into
jestjs:master
from
wsmd:fix-equality-for-iint8array-textencoder
Dec 7, 2019
Merged
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ab8501c
Update reference of global.Uint8Array
wsmd cff81ee
Update test
wsmd c4e342f
Remove error snapshot assertion due to conditional testing
wsmd bfffce0
Update reference of global.Uint8Array
wsmd 9c17fde
Add changelog entry
wsmd d5200ae
add failing test for Uint8Array
wsmd 8858ed4
Merge branch 'master' into fix-equality-for-iint8array-textencoder
SimenB File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs its own if block to check whether
typeof Uint8Array !== 'undefined'
is true. Feel free to also leave a comment on which Node version supports it, like it's done for other globalsThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@thymikee that's not a bad idea!
My initial thinking was that this is only a workaround specific to the
TextDecoder
as it seems to be referencing a differentUint8Array
constructor, so I grouped them all together in the same block.If(#9261 (comment)).TextEncoder
isn't defined then re-assigningUint8Array
isn't really neededCould you please help me understand under what conditions
Uint8Array
would beundefined
? I think this helps me better understand the Jest architecture =)Uint8Array
is very well supported since nodev0.10
, unlikeTextEncoder
that was only made available in the global namespace with nodev11.0.0
(which is relatively recent). I'm not sure if there will be a case whereUint8Array
isn't defined (v0.10
dates back to 2013).Isn't this similar? We're not checking for
ArrayBuffers
here:https://github.com/facebook/jest/blob/c4e342f86cac12a965ce3974212102a88d0fef55/packages/jest-environment-node/src/index.ts#L47-L49
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should be good with adding
Uint8Array
next to theArrayBuffer
then, wdyt @SimenB?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey hey! this conversation made me realize that this issue does not only occur with the global
TextEncoder
(in Node v11), but also withrequire('util').TextEncoder
(in any version of node)! 😬In Node v10 (or older), this test would still fail for the same reason:
Looks like after all we actually need to assign
global.Uint8Array
regardless ofTextEncoder
being global or not to support both cases 😅..I'll go ahead and push the changes 👍