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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypedArrays Are not typed arrays at runtime #10854

Closed
richardspence opened this issue Nov 20, 2020 · 4 comments 路 Fixed by #10885
Closed

TypedArrays Are not typed arrays at runtime #10854

richardspence opened this issue Nov 20, 2020 · 4 comments 路 Fixed by #10885

Comments

@richardspence
Copy link

馃悰 Bug Report

Latest Jest destructively interferes with TypedArrays at runtime.

To Reproduce

Run this test on Jest 26.*. Reproduced on 26.6.3

test('foo', ()=>{
expect(new Uint8Array(4).buffer instanceof ArrayBuffer).toBe(true);
})

Impact

Not using the real types for typed arrays has trickle down affects like constructing DataViews (who reject input arguments that are not ArrayBuffers).

Expected behavior

The test should pass

Note: This test passes in jest 24.9.0 and 25.5.4

Link to repl or repo (highly encouraged)

Repro Link

envinfo

  System:
    OS: macOS Mojave 10.14.6
    CPU: (8) x64 Intel(R) Core(TM) i7-8559U CPU @ 2.70GHz
    Memory: 2.35 GB / 16.00 GB
    Shell: 5.3 - /bin/zsh
  Binaries:
    Node: 11.15.0 - ~/.nvm/versions/node/v11.15.0/bin/node
    Yarn: 1.12.1 - /usr/local/bin/yarn
    npm: 6.7.0 - ~/.nvm/versions/node/v11.15.0/bin/npm
  Managers:
    Homebrew: 2.4.8 - /usr/local/bin/brew
    pip3: 18.1 - /Library/Frameworks/Python.framework/Versions/3.7/bin/pip3
    RubyGems: 2.5.2.3 - /usr/bin/gem
  Utilities:
    Make: 3.81 - /usr/bin/make
    GCC: 4.2.1 - /usr/bin/gcc
    Git: 2.19.1 - /usr/local/bin/git
    Clang: 1100.0.33.17 - /usr/bin/clang
    Subversion: 1.10.4 - /usr/bin/svn
  Servers:
    Apache: 2.4.34 - /usr/sbin/apachectl
  Virtualization:
    Docker: 19.03.13 - /usr/local/bin/docker
  SDKs:
    iOS SDK:
      Platforms: iOS 13.2, DriverKit 19.0, macOS 10.15, tvOS 13.2, watchOS 6.1
  IDEs:
    Emacs: 22.1.1 - /usr/bin/emacs
    Nano: 2.0.6 - /usr/bin/nano
    VSCode: 1.51.1 - /usr/local/bin/code
    Vim: 8.0 - /usr/bin/vim
    Xcode: 11.3.1/11C504 - /usr/bin/xcodebuild
  Languages:
    Bash: 3.2.57 - /bin/bash
    Java: 11.0.1 - /usr/bin/javac
    Perl: 5.18.4 - /usr/bin/perl
    PHP: 7.1.23 - /usr/bin/php
    Python: 2.7.10 - /usr/bin/python
    Python3: 3.7.2 - /Library/Frameworks/Python.framework/Versions/3.7/bin/python3
    R: 4.0.0 - /usr/local/bin/R
    Ruby: 2.3.7 - /usr/bin/ruby
  Databases:
    SQLite: 3.24.0 - /usr/bin/sqlite3
  Browsers:
    Chrome: 86.0.4240.198
    Edge: 87.0.664.41
    Firefox: 74.0
    Safari: 13.0.1
@shartte
Copy link

shartte commented Nov 25, 2020

Likely duplicate of #10786

We're running into the same problem since updating to CRA4 (and hence Jest 26). In our case, it's new Uint8Array(...).buffer instanceof ArrayBuffer being false.

@richardspence: Can you try removing this line locally and see if the test will run for you?
https://github.com/facebook/jest/blame/890852b18a6c863015d54e9fb2894ec57f546e1e/packages/jest-environment-jsdom/src/index.ts#L53

That did it for me. That line seems suspicious. If it copies ArrayBuffer, it should likely also copy the global Uint8Array, but doesn't. Additionally, in spite of what that comment says, after removing the line, window.ArrayBuffer is still available.

@Kuirak
Copy link

Kuirak commented Nov 27, 2020

I got the same problem when using @peculiar/webcrypto as polyfill in jest.

Removing the line locally didn't fix it for me.

The only thing working for now is using jest-environment-jsdom@25 but it doesn't feel like a good solution.

@ExE-Boss
Copy link
Contributor

As聽I聽said in聽#10786 (comment):

That鈥檚 because Jest uses a聽new聽VM聽context, and聽overrides the聽VM聽context鈥檚 ArrayBuffer with聽the聽top鈥憀evel global聽object鈥檚聽ArrayBuffer, but聽doesn鈥檛聽do聽this for聽typed聽arrays, which聽construct their聽ArrayBuffers using聽the聽overwritten ArrayBuffer聽constructor:

new Uint8Array().buffer.constructor !== ArrayBuffer;

Regressed聽by: #9606

@github-actions
Copy link

This issue 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 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
4 participants