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

[Bug]: Buffer is not instance of UInt8Array in jsdom #13547

Closed
sergekh2 opened this issue Nov 1, 2022 · 4 comments
Closed

[Bug]: Buffer is not instance of UInt8Array in jsdom #13547

sergekh2 opened this issue Nov 1, 2022 · 4 comments

Comments

@sergekh2
Copy link

sergekh2 commented Nov 1, 2022

Version

29.2.2

Steps to reproduce

Clone https://github.com/sergekh2/jest-buffer-test-fail
yarn install
yarn test-node
yarn test-jsdom

Expected behavior

Last test passes.

Actual behavior

Test fails since Buffer is not instance of UInt8Array

Additional context

In node environment node's Buffer is instance of UInt8Array and test passes.

In jsdom Jest brings in Buffer implementation which is not instance of UInt8Array, test fails.

Test code:

test("i-need-buffer", () => {
  const buffer = Buffer.from("hello");
  expect(buffer instanceof Uint8Array).toBe(true);
});

Environment

System:
    OS: macOS 12.6
    CPU: (10) arm64 Apple M1 Max
  Binaries:
    Node: 18.11.0 - ~/.nvm/versions/node/v18.11.0/bin/node
    Yarn: 1.22.18 - /opt/homebrew/bin/yarn
    npm: 8.19.2 - ~/.nvm/versions/node/v18.11.0/bin/npm
  npmPackages:
    jest: ^29.2.2 => 29.2.2
@sergekh2
Copy link
Author

sergekh2 commented Nov 1, 2022

I checked previous versions: it succeeds in Jest 25, and fails from 26 onward.

@SimenB
Copy link
Member

SimenB commented Nov 1, 2022

Buffer shouldn't exist in JSDOM at all - it's a node specific global and will break if you run it in a real browser. I wanna remove it entirely, but there's a performance regression for some reason: #11241.

@SimenB SimenB closed this as completed Nov 1, 2022
@sergekh2
Copy link
Author

sergekh2 commented Nov 1, 2022

For the browser there are packages like https://www.npmjs.com/package/buffer (which is used by browserify). So it's not a problem at all. The question is how to get consistent experience in JSDOM.

@github-actions
Copy link

github-actions bot commented Dec 2, 2022

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 Dec 2, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants