-
-
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
XUnit reporter should handle exceptions during diff generation #4068
Conversation
Managed to replicate myself. The fix LGTM. @mochajs/core any other thoughts? |
When this exception is thrown in XUnit reporter, the output is truncated and aborted without any error message. That exception shouldn't be swallowed. Could be related to #980. |
@juergba I'm not sure if I understood entirely. Is this particular fix incorrect? Is there something I should add/modify? |
This issue has two parts. The diff exception and then second the reporter aborting without any message. |
@juergba Uncaught exceptions are intercepted by the runner at this point. Looking at the method in question, I see that the exception is logged, but only at the debug log level. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rgroothuijsen thank you.
I'm not happy mainly with the existing implementation of diff in XUnit
reporter.
Base.generateDiff
: exceptions are not catched and propagate upto theuncaughtException
handler.- condition when to generate diff is much softer in
XUnit
than inBase
. eg. there is no check for identical type ofactual
andexpected
. - I'm unsure wether this PR is IE11 compatible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have an EVENT_TEST_FAIL
handler in Base
which calls stringifyDiffObjs
. Since XUnit
extends Base
, this handler is called also for XUnit
.
So the problem is not the missing stringifyDiffObjs
in XUnit
, but the conditions when to generate a diff, are not identical in Base
and XUnit
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added some change requests to your code:
- we catch an exception while generating diff
- we stringify only in the fail event handler
- we synchronize conditions when diffs should be generated over
Base
,XUnit
and fail event handler.
I haven't tested my proposition, so if you find anything, please go ahead ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those mocking tests are quite complex, so please check my code carefully.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rgroothuijsen thank you!
Could you please rebase, squash with your commit message and edit/update this PR's description?
@juergba Will do. In retrospect, do you think the title still works for this PR? |
@rgroothuijsen No, not really. Maybe "XUnit reporter: fix crash during diff generation" or similar, but the title is upto you. |
Description of the Change
This bugfix addresses a crash in the XUnit reporter, which produced no output because the assertion library used in the ticket provided numerical diff values rather than string values, causing an error during diff generation. To safeguard against unexpected crashes such as these, the same input-checks that the Base reporter uses have been implemented in the XUnit reporter, and exceptions during XUnit diff generation are returned by the reporter.
Applicable issues
Fixes #4022.