-
-
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
Jest breaks Buffer instanceof Uint8Array #4422
Comments
Update, tried setting |
passing a set of commong globals through to the env to ensure instanceof checks work as expected. Fixes jestjs#4422
The issue is that |
This is unfortunately a side-effect of Jest pulling in the node libraries from the parent context, but having its own instances of UInt8Array in the child contexts. One thing you could try is to create your own environment that runs all tests in the main process, or overwrites UInt8Array in the child context with the one in the parent context. We don't have a good fix for this yet. |
Passing more globals through to the child process works in my tests, see #4423. Currently I am not seeing a big drawback to doing that, except that that list needs to be maintained. But I might be missing some context there. |
Why the requirement of having the parent |
This is not expected, it is a bug, but because Jest tries to keep individual tests sandboxes and isolated, we cannot leak more things into the vm. Ideally we wrap all core libraries so that we swap out the prototypes later, like |
Makes sense, thank you 👍 |
Custom environment works like a charm, for anyone coming here I created this: https://github.com/ipfs/jest-environment-aegir |
Thanks for working on this env and sharing it with everybody :) I'll close this issue as I know it's tracked somewhere on our issue tracker but I can't find it right now :( I'm sure somebody in the future will reference the two together. |
This type check is incompatible with Jest because it injects its own version of Uint8Array into the environment which is different. See jestjs/jest#4422. The tests do not pass with this change.
While this technically is not necessary, because node.js' Buffer inherits from Uint8Array this contract is broken by jest. See jestjs/jest#4422. Add a `message instanceof NativeBuffer` to the function to fix the issue, it does no harm and *technically* would be the more correct check, because for node.js passing a raw Uint8Array does not return a Buffer.
While this technically is not necessary, because node.js' Buffer inherits from Uint8Array this contract is broken by jest. See jestjs/jest#4422. Add a `message instanceof NativeBuffer` to the function to fix the issue, it does no harm and *technically* would be the more correct check, because for node.js passing a raw Uint8Array does not return a Buffer.
- Remove mocha/chai/nyc dependencies - Add jest + ts-jest dependencies - Update eslintrc for jest - Move mocha/nyc configs to jest config - Add custom environment to fix Uint8Array issues (jestjs/jest#4422) - Add custom reporters for cleaner output - Update test files - Update npm scripts - Break up e2e tests into separate files for concurrency
As a possible solution:
|
so no recovery tests and no using jolo identities this is because of jestjs/jest#4422 which breaks hdkey
This should probably be reopened or a link to the other tracking issue should be found. |
The fix is to create a export default {
globals: {
Uint8Array: Uint8Array,
},
}; |
This is a work-around for the known jest bug. See: jestjs/jest#4422
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. |
Do you want to request a feature or report a bug?
Bug
What is the current behavior?
In nodejs (8.4.0)
In jest (21.0.1)
This breaks quite a few modules that assume (as they should be able to) that node buffers are Uint8Arrays.
The text was updated successfully, but these errors were encountered: