-
-
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
ArrayBuffer regression in node env #7780
Comments
@H1Gdev ideas? |
This might be #2549 |
Oh...:cry: Seems that there are multiple type of There is also a way to add TypedArrays like ArrayBuffer is easy workaround. |
Execute the following code in each environment.(--env=node, --env=jsdom, and node). const bufFromArray = Buffer.from([0x62, 0x75, 0x66, 0x66, 0x65, 0x72]);
bufFromArray instanceof Uint8Array;
const bufFromArrayBuffer = Buffer.from(new ArrayBuffer(6));
bufFromArrayBuffer instanceof Uint8Array; In --env=node, results are not true. It seems that |
not only so both contexts (main and vm) has same Probably it's better to contextify |
Moreover since Buffer from different context this both fails: expect(Buffer instanceof Object).toBe(true);
expect(Buffer instanceof Function).toBe(true); Upd. Full test case of globals if needed: const data = [];
for (const key in global) {
const value = global[key];
if ("function" === typeof value || null !== value && "object" === typeof value) {
data.push(key);
}
}
test.each(data)("global[%p] instanceof Object", (key) => {
expect(global[key]).toBeInstanceOf(Object);
}); |
This is really painful in our project. Caused a lot of false positives and nagatives in tests involving checks for value types. |
Possible workaround:
|
This forced me to use mocha. |
I lied. I came back. Workaround: // __test-utils__/custom-jest-environment.js
// Stolen from: https://github.com/ipfs/jest-environment-aegir/blob/master/src/index.js
// Overcomes error from jest internals.. this thing: https://github.com/facebook/jest/issues/6248
"use strict";
const NodeEnvironment = require("jest-environment-node");
class MyEnvironment extends NodeEnvironment {
constructor(config) {
super(
Object.assign({}, config, {
globals: Object.assign({}, config.globals, {
Uint32Array: Uint32Array,
Uint8Array: Uint8Array,
ArrayBuffer: ArrayBuffer,
}),
}),
);
}
async setup() {}
async teardown() {}
}
module.exports = MyEnvironment; Then in package.json:
|
I just had to put a "jest": {
"testEnvironment": "./__test-utils__/custom-jest-environment.js",
...
}, |
Thanks for sharing the workaround, but it seems to me that the solution is already out of date. I've just installed module.exports = {
// ...
testEnvironment: 'node',
}; That's it. I didn't need to extend the Correct me if I'm wrong, but it seems that when Am I right? |
Setting |
let t = Buffer.alloc(0)
t instanceof Uint8Array
|
still bit me on jest 26.4.2… but wujekbogdan's solution above adding to jest.config.js did help me! |
I'm running Jest v26.4.0 and the problem occurs even though I added |
- had to update eslint deps - ran into palantir/blueprint#4112 - had to move beta.svg out of static/ - had to fix prettier formatting changes - ran into jestjs/jest#7780
- had to update eslint deps - ran into palantir/blueprint#4112 - had to move beta.svg out of static/ - had to fix prettier formatting changes - ran into jestjs/jest#7780
This reverts commit f825ea1. The upgrade to react-scripts includes an upgrade to jest-environment-jsdom which introduces a regression with firebase related tests detailed here: https://stackoverflow.com/q/61914567 jestjs/jest#7780 firebase/firebase-js-sdk#3096 It's easier to hold back on the react-scripts upgrade for now.
I am still experiencing this issue with jest-environment-jsdom@27. I tried the solution of adding a custom environment, but then the behavior of VSCode's jest extension becomes all wonky. It can't figure out the status of the tests. Ughh |
:( |
|
So, create-react-app doesn't allow you to override testEnvironment. Does anyone know a way to apply the workaround when using create-react-app? I tried using jest { setupGlobals } but that wouldn't let me modify the globals config.
|
@odbol We did this on the command line by replacing the |
@odbol You can also just add this
to the top of the file having this issue |
Wow, @nlinx, that worked perfectly. Who knew it was so easy? Thanks! |
See GitHub issue: jestjs/jest#7780
See GitHub issue: jestjs/jest#7780
This seems like it is still an issue for /**
* @jest-environment node
*/
test('Int32Array Buffer', () => {
expect(new Int32Array([]).buffer).toBeInstanceOf(ArrayBuffer);
}); expect(received).toBeInstanceOf(expected)
Expected constructor: ArrayBuffer
Received constructor: ArrayBuffer
61 | test('Int32Array Buffer', () => {
> 62 | expect(new Int32Array([]).buffer).toBeInstanceOf(ArrayBuffer);
| ^
63 | }); |
Includes workaround for jestjs/jest#7780
This doesn't work tho because Jest v27 seems to be required. The workarounds I see in jestjs/jest#7780 and firebase/firebase-js-sdk#3096 don't seem to work
Example in OP passes in newer versions of Jest. Please open new issues with reproductions for other environments. (the last example probably still fails due to https://github.com/facebook/jest/blob/b372332a8ff25aca23d36c5297db94581b6d439e/packages/jest-environment-node/src/index.ts#L42, but nevertheless it's a different issue) |
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. |
🐛 Bug Report
#7626 introduced regression
fails with
The text was updated successfully, but these errors were encountered: