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]: Jest, jsdom and maybe ts-jest trouble with Buffer being an instance of Uint8Array #14363

Closed
lemoustachiste opened this issue Jul 25, 2023 · 6 comments

Comments

@lemoustachiste
Copy link

Version

29.6.1

Steps to reproduce

  1. clone the repo: https://github.com/lemoustachiste/repro-jest-buffer-uint8array
  2. npm install
  3. npm test # this shows the tests failing
  4. (npm run test:only-one) # this runs only one test to show that it works with only one file
  5. (npm run node:compare) # this runs a node script to show that a Buffer should be an instanceof Uint8Array

Expected behavior

a Buffer should be an instance of Uint8Array when running multiple tests

Actual behavior

a Buffer is not an instance of Uint8Array when running multiple tests

Additional context

If only one test file is run it works (but not in watch mode).

If 2 files (accessing Uint8Array) are run it fails.

If I remove jsdom as test env, it works (but I need it in my origin repo)

If I remove ts-jest as a transformer, it sometimes work, but sometimes not (seems to be inconsistent with cache). But I need ts-jest in my origin repo.

A similar issue was reported here: #4422, however while it solves the general problem, the described issue persists.

Environment

System:
    OS: macOS 13.5
    CPU: (8) x64 Intel(R) Core(TM) i5-1038NG7 CPU @ 2.00GHz
  Binaries:
    Node: 16.20.0 - ~/.nvm/versions/node/v16.20.0/bin/node
    Yarn: 1.22.18 - /usr/local/bin/yarn
    npm: 9.8.0 - ~/.nvm/versions/node/v16.20.0/bin/npm
  npmPackages:
    jest: ^29.6.1 => 29.6.1
@mrazauskas
Copy link
Contributor

Did you try using jest-light-runner for those specific tests which need instanceof? Reference: #2549 (comment)

@SimenB
Copy link
Member

SimenB commented Jul 25, 2023

Duplicate of above linked issue

@SimenB SimenB closed this as not planned Won't fix, can't repro, duplicate, stale Jul 25, 2023
@lemoustachiste
Copy link
Author

Thanks for the support.

So my goal is to eliminate tech-debt from my project, but adding jest light runner, while it solves my js repro, feels like heavily accepting new one.

My main problem being typescript support: nicolo-ribaudo/jest-light-runner#53.

Isn't there a better solution? Uint8Array support works when only one test runs, but not multiple. It seems like a problem with jest, but having to setup convoluted scaffolding just to run tests feels like a code smell.

@SimenB
Copy link
Member

SimenB commented Jul 26, 2023

It's #2549 as mentioned. That issue contains a bunch of different workarounds.
Unfortunately, cross realm instanceof is a hard problem to solve.

@lemoustachiste
Copy link
Author

I solved it by removing jsdom as the default environment and using it on a per test basis

@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 Aug 27, 2023
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

3 participants