Explore testing outputs and warnings from the logger
Please confirm that you have searched existing issues in the repo
Yes, I have searched the existing issues
Any related issues?
No response
What is the area that this feature belongs to?
Code Quality, Testing
Is your feature request related to a problem? Please describe.
This issue was brought up in Pull Request #2053.
Currently, there is no way to implement unit tests for logging outputs from the winston logger; by allowing the current unit testing methods to cover logging outputs (e.g. warnings) as well, we can ensure consistent behavior across different components and increase the robustness of the system as a whole, not just what is visible.
Describe the solution you'd like
The request is to consider the different approaches to allow the winston logger outputs to be detected by our current testing approaches.
Describe alternatives you've considered
Alternatively, as jest is adopted as the testing tool for MarkBind, we can investigate approaches to test winston logger using jest (which seems to already be feasible as can be seen in this StackOverflow discussion.
Additional context
No response
Hi, I’d like to work on this issue, probably using Jest to mock Winston
After having a bit of a think, I'm not sure whether we should be testing the console output itself, or what the Winston logger is called with. Testing the console output itself seems like we're also testing the Winston logger, which seems out of the scope of a unit test. Instead, I think we should just test that the Winston logger has been called with the appropriate logging level and message. So something like
import * as logger from '/packages/core/src/utils/logger'
// mock the warn function of the logger here
expect(logger.warn).toHaveBeenCalledWith(args...);
What do you think about it?
Seems like a sound approach to me, I think its worth investigating along these lines!