-
-
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
[Bug]: Jest runs out of memory when trying to print wide objects #12364
Labels
Comments
Happy to take a PR that fixes this (either |
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. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Version
27.5.1
Steps to reproduce
yarn install
yarn test deep-array.test.js
you should expect this to fail with an appropriate error messageyarn test wide-array.test.js
you should expect this to crashExpected behavior
I expect that when Jest has found that two objects don't match, and one of them is an array/objects with many (potentially deeply nested) elements, it should be able to print a message to the screen, even if it requires the array/object to be truncated.
This is currently the case for very deep elements, as shown by the
deep-array.test.js
test case, which simulates an infinitely deep array, and Jest correctly fails quickly with an error message that is limited in scope but does not try to print to infinity.Actual behavior
Jest will run out of memory when trying to print wide arrays. Objects are passed to the
pretty-format
which has amaxDepth
parameter to prevent printing very deep, but it does not have amaxWidth
parameter (or similar) to prevent printing very wide.This can be easily simulated with a test such as:
Even though the runtime can very easily create an empty array of length 1 Billion, when we try to compare it against something, Jest will try to print the entire width of it.
This can also be an issue for objects that aren't extremely wide, but the combination of their widths at each depth result in the same. For example, a nested array that is 10 levels deep, but is 10 elements wide at each level contains 10^10 elements.
Additional context
No response
Environment
System: OS: macOS 12.2 CPU: (8) arm64 Apple M1 Pro Binaries: Node: 17.2.0 - /opt/homebrew/bin/node Yarn: 1.22.17 - /opt/homebrew/bin/yarn npm: 8.1.4 - /opt/homebrew/bin/npm npmPackages: jest: 27.5.1 => 27.5.1
The text was updated successfully, but these errors were encountered: