You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
yarn test deep-array.test.js you should expect this to fail with an appropriate error message
yarn test wide-array.test.js you should expect this to crash
Expected 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 a maxDepth parameter to prevent printing very deep, but it does not have a maxWidth parameter (or similar) to prevent printing very wide.
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.
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.
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: