-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
fix circular objects in json reporter. Closes #2433 #2559
Conversation
Nice one. I'm not a big fan of the duplication though. Should this be put in its own reusable util function? |
There's no duplication here? This one reporter is the only spot I'm aware of with this problem. |
IMHO if the version in our |
hmm, yes, it seems canonicalize() is circular-safe, which is what I thought I was pointing you to. oops. but that function is for displaying diffs. |
It would seem a public API to output JSON--while avoiding circular references--would be helpful to reporter implementations. That's tangential to #2433. Looking more closely at the JSON reporter, it already purports to kill circular references. The bug is that it doesn't actually succeed in doing this. The JSON stream reporter works because it doesn't attempt to "stringify" an I think what this PR should do is actually very fine-tuned to this bug. @jeversmann Can you instead modify errorJSON() or clean() to skip objects it's already seen? I don't know what the "best" implementation would look like here, but we should retain as much of the |
I moved the circular object logic into a helper function that's called in The 'gotcha' here is that |
I thought Mocha doesn't accept non- |
The problem in #2433 deals specifically with an object whose prototype chain contains I can modify the test to build the thrown object from an |
Yeah, I'm not too concerned with having a test that focuses on the circular reference thing without worrying about rigging up a "real" |
I am a bot that watches issues for inactivity. |
@boneskull This is still labeled as pr-needs-work, but I think I've addressed the feedback. |
@jeversmann thanks for the heads-up. someone will take a look at this, maybe even me! |
Hey! I've stumbled upon this situation myself and the proposed commits seem to resolve the issue for me. Do you plan on merging this pull request sometime? Is this PR missing anything that prevents it from being mergable? @boneskull - could you address those questions? Thanks! |
continued in #3318. thanks |
original work by @jeversmann; continuation of PR #2559 Signed-off-by: Christopher Hiller <[email protected]>
landed in 741b0bd |
) original work by @jeversmann; continuation of PR mochajs#2559 Signed-off-by: Christopher Hiller <[email protected]>
In #2433, @boneskull recommended using
jsonStringify()
from./lib/utils
, but that function isn't exported by the utils module, and more importantly it isn't actually circular-reference safe.Instead, I took the custom replacer from this StackOverflow post and added it to the reporter's invocation of
JSON.stringify
.The test for this issue is mostly a copy of the 1st json reporter test. It has fewer asserts because there's no way to test for the change to the object that is made by the replacer, but the test does fail without the additional code.