-
Notifications
You must be signed in to change notification settings - Fork 133
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
Test logger calls in tests for NodeProcessor #2463
Test logger calls in tests for NodeProcessor #2463
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #2463 +/- ##
==========================================
+ Coverage 48.90% 48.97% +0.06%
==========================================
Files 124 124
Lines 5247 5254 +7
Branches 1112 1112
==========================================
+ Hits 2566 2573 +7
- Misses 2373 2376 +3
+ Partials 308 305 -3 ☔ View full report in Codecov by Sentry. |
@luminousleek Thanks for the great work! I have a few ideas:
to reset the logger to a clean state after every test. Might not be very useful for now but I think it is safer to do so, because issues might arise in the future (eg. checking mock.calls.length) Please feel free to add your comments! |
Yeah I think this is a good idea, will probably do it in another PR. Thanks for the link.
Yup I agree, the length issue didn't occur to me until you mentioned it. Thanks for commenting on this PR! |
Great point about the clearing mocks! I think that is particularly important to note as bugs that arise from not clearing mocks may be harder to spot when it happens. Great catch! |
Hi @luminousleek thank you very much! This looks like excellent and detailed work.
|
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.
LGTM!
Added the Edit: after looking at some code on StackOverflow regarding this, it seems that they put the |
Good catch! I agree with the use of Assume test 1 and test 2 are in two separate files and are run sequentially, In In In the case of using |
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.
LGTM! Good catch of the use of beforeEach
!
What is the purpose of this pull request?
Partially addresses #2099
Related to #2053
Overview of changes:
Anything you'd like to highlight/discuss:
Mocking vs Spying
I chose to mock the logger instead of spy on it so as to decouple the logger from this test. If I had spied on the logger, the actual implementation of the logger would have been used, which may also consume (slightly) more resources. Also, errors from
winston
might also interfere with the test (even though that's very unlikely).One side-effect of mocking the logger is that the logger output will not be printed in the console, as seen in the screenshot below (left is spied, right is mocked).
If the logger output is still needed to be printed in the console, then a mock implementation of the
warn
method could look something like thisand would result in this being printed to the console
which does look pretty clunky. Do let me know which approach you prefer.
Inconsistent naming in
NodeProcessor.data.ts
The naming conventions of the test inputs in
NodeProcessor.data.ts
are inconsistent. Many of the elements there have a test to check if the slots do override the attributes of the elements, but they are named in two separate ways:PROCESS_[ELEMENT]_ATTRIBUTES_NO_OVERRIDE
PROCESS_[ELEMENT]_[ATTRIBUTE]_SLOT_TAKES_PRIORITY
I think that's why the author of #2053 wrote another constant called
PROCESS_PANEL_HEADER_SLOT_TAKES_PRIORITY
when the constantPROCESS_PANEL_ATTRIBUTES_NO_OVERRIDE
tests for the exact same thing. That's why I have anexpect
statement after each of these two tests, because in both times the logger is called with the same input.A PR could be done to make the naming convention consistent, as well as to remove the unnecessary test.
Logger warnings still inconsistent
With the merging of #2053, Panels, Dropdowns, Modals and Popovers print warnings to the console if there are slots overriding the element attributes. However, other elements such as Quizzes and QOptions do not print warnings when this happens. This is because in the code of
MdAttributeRenderer.ts
, not every attribute is checked to see if there is an overriding slot, so the logger will not warn if the unchecked attributes are overridden.A simple (though untested) fix could be to have a new method as follows
and replace all the
processAttributeWIthoutOverride
methods with this.Testing instructions:
Proposed commit message: (wrap lines at 72 characters)
Checklist: ☑️
Reviewer checklist:
Indicate the SEMVER impact of the PR:
At the end of the review, please label the PR with the appropriate label:
r.Major
,r.Minor
,r.Patch
.Breaking change release note preparation (if applicable):