markbind icon indicating copy to clipboard operation
markbind copied to clipboard

Explore testing outputs and warnings from the logger

Open lhw-1 opened this issue 3 years ago • 3 comments

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

lhw-1 avatar Jan 17 '23 08:01 lhw-1

Hi, I’d like to work on this issue, probably using Jest to mock Winston

luminousleek avatar Mar 07 '24 07:03 luminousleek

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?

luminousleek avatar Mar 13 '24 05:03 luminousleek

Seems like a sound approach to me, I think its worth investigating along these lines!

kaixin-hc avatar Mar 13 '24 05:03 kaixin-hc