-
-
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
RangeError: Maximum call stack size exceeded with .toBe
on a large string
#8936
Comments
Does it also happen with |
node.js doesn't seem to like really long strings. I'm able to reproduce the bug and I think I found a fix. But testing this takes ages. Especially with my fix, as the console output grinds to a halt. Anyway: // Problematic regex:
const messageMatch = content.match(/(^(.|\n)*?(?=\n\s*at\s.*\:\d*\:\d*))/);
let message = messageMatch ? messageMatch[0] : 'Error';
const stack = messageMatch ? content.slice(message.length) : content; My monkeypatched fix: const callstackPos = content.search(/((\n\s*at\s.*\:\d*\:\d*))/);
let message = callstackPos ? content.substring(0, callstackPos) : 'Error';
const stack = callstackPos ? content.substring(callstackPos+1) : content; That should work the same, but cuts |
Reproducion: it("compares the strings correcty", () => {
expect(string1 + "w").toBe(string1);
}); whereas |
.toBe
on a large string
While it fails here https://github.com/facebook/jest/blob/736edd2ea6c9aadfb6e8794ecdc8a726f8a76b1a/packages/jest-message-util/src/index.ts#L358-L360, I think it makes more sense to avoid huge strings here: https://github.com/facebook/jest/blob/736edd2ea6c9aadfb6e8794ecdc8a726f8a76b1a/packages/jest-matcher-utils/src/index.ts#L307-L313 rather than trying to fix the regex part. This ends up generating a huge string, which is used when throwing the assertion error, which we later run the regex against. I think such a huge string is not useful anyways That said, the change @StringEpsilon suggests seems reasonable regardless? |
Yes, the way Jest hangs is as annoying as #1772 and #5392 but for different reason Because base64 strings do not contain newlines, it was:
Can yβall suggest any good examples of software tools that Jest might follow to limit:
in the report when a matcher fails? |
@Genuifx To help me think what is relevant information that Jest should provide, the type mismatch of array as received value and string as expected value was which of the following:
|
I'm not entirely sure if a unit test suite does that, but think a good way of dealing with overly long lines would just be to chop to the relevant section. That would be the start of the differences + whatever surroundings can be added reasonably. Samples for comparing against
It's not entirely uncommon for compilers or intrepeters to chop lines to the relevant section. I'm not entirely sure how much overhead this would introduce. I'm also not sure about the UX aspects of chopping strings that should be equal but aren't (i.E. introducing headaches to the guy debugging that test) |
@pedrottimark error in the test is preferred. Actually, That was my bug while mocking some kind of function. @StringEpsilon I was doing redux compatible work for mini-app, one case needs consider is the store's data is too large to connect the page (every single time |
I was getting this error with |
This happen when I use functions with two ways. This will be generate call stack error because Javascript is single thread, example: const a = () => { const b = () => { Function a call function b and function b call function a, this will fill the call stack and generate this error |
This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 14 days. |
This issue was closed because it has been stalled for 7 days with no activity. Please open a new issue if the issue is still relevant, linking to this one. |
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
Writing code like this, jest will throw RangeError, here is the error message:
the Array
expect
function got has an item that is an about 3MB string (base64 image), andtoBe
got the same base64 String.To Reproduce
like above.
Expected behavior
should fail the test, but not throw range error
Link to repl or repo (highly encouraged)
envinfo
The text was updated successfully, but these errors were encountered: