-
-
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 stalls after comparing to complex objects #1772
Comments
@sebmarkbage It looks like the original commit that caused this failure was dropped during a history rewrite. I checked out your fork and went to the next similar commit at sebmarkbage/react@f904163, then replaced the originally problematic line in src/renderers/shared/fiber/tests/ReactTopLevelFragment-test.js ReactNoop.flush();
var instanceC = instance;
- expect(instanceC === instanceA).toBe(true);
+ expect(instanceC).toBe(instanceA);
}); When running jest at master (commit 2e36e25), the test fails but does not stall. I doubt that this is comparing the correct object, because the expected and received values are both This is the output of the test: https://gist.github.com/chase/cc980da37005dc0d48bed7b3cdd9f4d5 It might be fixed in jest@master now, but I don't have access to the original commit where it broke. |
( This happens consistently when I |
I can reproduce this with a simple test: it('hangs', function() {
var elem = document.createElement('div');
expect(elem).toBe(undefined);
}); It hangs forever on Jest 16.0.1. |
@cpojer any idea if you guys will be able to get to this soonish? Keeps coming up for my team and tracking down the culprit assertion is not always easy. |
It's faster if you send a PR! Unfortunately I've been pretty backed up with a ton of work. |
Hmm, ok I'll try and make time to look into this tomorrow. |
I did a little digging and it seems that @sebmarkbage's analysis was right. I will put in a basic PR tomorrow morning that at least deals with the symptoms mentioned, but I think that a long term solution would be to limit the verbosity or object depth being printed with a CLI option to adjust it. |
Fix submitted to |
Downgrade to |
@yaycmyk, thanks for putting in the effort for HTML element printing. I'm sure your hours of work won't go to waste. I got pulled for some crunch time tasks and ultimately got distracted from my pull request. |
Sure, that's fine too. |
This still happens for us in React repo with the latest Jest. I made a repro case inside React repo.
Expected: it doesn't hang. Commit with the repro: gaearon/react@8a0e694. |
I have another case: I tried to patch in the fix in #2148 but it still stalls. |
@sebmarkbage can you send a PR to Jest with a failing test? |
@cpojer I don't know how to reduce it yet. Pretty complex and don't know how to debug. Looks to be something with |
The issues is that I tried to use the same fix as #2148 but that makes it way too slow because running it over and over again at different depths is very slow when the tree is large. Max depth is also not sufficient even for the first fix when you have a flat tree but many properties and large strings in each object. Even just a single long string at many characters (>10000) would probably be enough. Gotta run but I guess that's another plausible unit test. |
Here's a simple test that hangs jest: it('takes 37 seconds', () => {
expect(location).toBe({});
}); It actually finishes in ~37 seconds on my machine, seems like producing a huge diff. |
@cpojer @gaearon The comments about
Although depth of React elements wasn’t a problem here for If it’s hard to imagine limited depth for React elements, consider plugins for Immutable data. To be clear, this comment isn’t about the difference from expect(received).toBe(expected)
Expected value to be (using ===):
tweedle dee pretty format options include min and maxDepth…
Received:
tweedle dum …but plugins cannot enforce maxDepth, nor refs |
Is this still a problem with the latest Jest 21.3 betas? |
Does |
@cpojer AFAIK @pedrottimark is working on a proper fix for that (but it's probably going to be a big rewrite of our diffing algo, so it will take a while), so please keep this open for reference. |
Yes, I’m working on tests for new An update is overdue: if I came anywhere close to reproducing the original problem, when the test failed before implementing the feature:
For this edge case of many instead of few differences, the However, end result is that unusual looking assertion |
Got it, thanks for the update! |
…a multi-valued key. * feat: Add 'all' argument to git.config to return array of values for a multi-valued key. * chore: Consolidating tests * chore: Try to stop Travis tests from stalling by reducing snapshot sizes. (I think I'm affected by jestjs/jest#1772)
…nts.test.tsx Maybe related to Jest stalls after comparing to complex objects jestjs/jest#1772 Solution is to clone ValidityState
…nts.test.tsx Maybe related to Jest stalls after comparing to complex objects jestjs/jest#1772 Solution is to clone ValidityState
I got this to occur with image files. I was seeing if an image conversion tool I was using omitted an identical image as output by comparing buffers using Jest. If they were identical buffers, it passed without issue. If they weren't it hung. It seems to be just as @sebmarkbage described. Swapping to a simple boolean check or a hash was an easy workaround once I figured out this assertion was hanging. I can't seem to get it to repro with any ol' test image file though, so you get to see my test pdf 😅. Maybe this will help @pedrottimark ?
|
We're also seeing this issue with large snapshot files. Has anyone found a workaround? |
Currently, experiencing the same issue. any fix? |
I've also ran into this, where a failure in a comparison of two deep objects (with circular references) will cause the script to appear to stall for nearly a minute. I just want it to fail and say, "No, it's not the correct object reference," not a deep comparison of the instance properties, which is not valuable at all. |
Seems like the fix is to change |
@matthew-dean Yes, Although @carusology Yeah, the serialization for buffers is huge, and I doubt that the diff is relevant to you. What do you think about @davidlygagnon @TUgonna Am back on this again. In Do you know if that is the situation when y’all see this issue? |
I'm having this problem with not so big snapshot files. In my case I got errors like <--- Last few GCs --->
[65064:0x105800000] 242971 ms: Mark-sweep 1411.7 (1473.4) -> 1411.5 (1442.4) MB, 5512.1 / 0.2 ms last resort GC in old space requested
[65064:0x105800000] 250116 ms: Mark-sweep 1411.5 (1442.4) -> 1411.5 (1442.4) MB, 7144.9 / 0.1 ms last resort GC in old space requested
<--- JS stacktrace --->
==== JS stack trace =========================================
Security context: 0x184239f25879 <JSObject>
1: indexOf(this=0x1842b7c3ec71 <Very long string[424567]>)
2: /* anonymous */(aka /* anonymous */) [/Users/hisa/workspace/eljurista/node_modules/pretty-format/build/plugins/lib/markup.js:43] [bytecode=0x1842aac77119 offset=60](this=0x18425d9822d1 <undefined>,key=0x1842c4ab87a1 <String[5]: relay>)
3: arguments adaptor frame: 3->1
4: map(this=0x1842b7c79869 <JSArray[17]>)
5: /*...
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
1: node::Abort() [/usr/local/Cellar/node@8/8.12.0/bin/node]
2: node::FatalException(v8::Isolate*, v8::Local<v8::Value>, v8::Local<v8::Message>) [/usr/local/Cellar/node@8/8.12.0/bin/node]
3: v8::Utils::ReportOOMFailure(char const*, bool) [/usr/local/Cellar/node@8/8.12.0/bin/node]
4: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [/usr/local/Cellar/node@8/8.12.0/bin/node]
5: v8::internal::Factory::NewRawTwoByteString(int, v8::internal::PretenureFlag) [/usr/local/Cellar/node@8/8.12.0/bin/node]
6: v8::internal::String::SlowFlatten(v8::internal::Handle<v8::internal::ConsString>, v8::internal::PretenureFlag) [/usr/local/Cellar/node@8/8.12.0/bin/node]
7: v8::internal::String::IndexOf(v8::internal::Isolate*, v8::internal::Handle<v8::internal::String>, v8::internal::Handle<v8::internal::String>, int) [/usr/local/Cellar/node@8/8.12.0/bin/node]
8: v8::internal::Runtime_StringIndexOfUnchecked(int, v8::internal::Object**, v8::internal::Isolate*) [/usr/local/Cellar/node@8/8.12.0/bin/node]
9: 0x17f1435042fd
10: 0x17f1435683ba
error Command failed with signal "SIGABRT" it hangs on expect(tree).toMatchSpecificSnapshot(snapshotFilename);
// tree is a mount wrapper from enzyme Is there any progress or workaround for this for snapshot testing? |
I found that my snapshots were huge and were the cause of the out of memory error... luckily I also found |
i detect at
that expect is correct and the expect works in miliseconds expect(arrStatus[0]).toEqual({
property1: expect.any(Object),
property2: expect.any(Object),
stringValue: 'included'
}); but do the same expect, with wrong string which not expect to the object - never ends up and my pc fan running on full throttle expect(arrStatus[0]).toEqual({
property1: expect.any(Object),
property2: expect.any(Object),
stringValue: 'not_included'
}); edit expect(arrStatus[0]).toBe({
property1: expect.any(Object),
property2: expect.any(Object),
stringValue: 'not_included'
}); Got following Errorby stringify the complex Object JSON.stringify(arrStatus[0].property1);
TypeError: Converting circular structure to JSON so i guess the main problem is a infinite loop because we have a circular structure in the complex object. so we need a solution to prevent this:
|
We have an open PR that should hopefully fix this, see #6961. Will land as part of Jest 24 |
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. |
(version v15.1.1)
In this PR, I can't use
expect(a).toBe(b);
on two complex and cyclic objects. It works fine if the test pass but if the test fails I think it tries to print/report the object structure or something. Interestingly enough it works fine on some of the other similar objects.The end result is that jest stalls and doesn't print or proceed with anything else. I thought it might have been an infinite loop but if I run it with the Chrome debugger in Node 6 I can't stop. There's no break point so it seems like the event loop is just paused waiting for new messages that never arrive.
The text was updated successfully, but these errors were encountered: