-
-
Notifications
You must be signed in to change notification settings - Fork 158
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
LogLevel output doesn't show when running in a test #177
Comments
Hard to say I'm afraid! What happens if you put a I suspect what's happening is that something else in your test stack is patching the console methods, but loglevel is capturing them early on (when What happens if you put |
Thanks much… I’ll give that a whirl when I’m back in the office!
Have a great day!
Jon Seidel, CMC®
… On Aug 26, 2022, at 7:47 AM, Tim Perry ***@***.***> wrote:
Hard to say I'm afraid! What happens if you put a console.log(...) and logger.log(...) calls outside the test, e.g. just after the enableAll() call?
I suspect what's happening is that something else in your test stack is patching the console methods, but loglevel is capturing them early on (when setLevel or enableAll is called) and that's causing issues. We've seen similar issues from React itself in the past (#171 <#171>).
What happens if you put logger.enableAll() inside the test, just before you call logger.debug? If that fix this then this is definitely caused by something patching console.log itself during the tests, and not expecting anybody to still have a reference to the previous value.
—
Reply to this email directly, view it on GitHub <#177 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AAAADZUJTGM5A7FTSOHOTJDV3DKIFANCNFSM57UPNO4Q>.
You are receiving this because you authored the thread.
|
Thanks @pimterry. Tried what you suggested:
And did this for all the console options (log, warn, error, info, debug, trace) Seems as if by the time it got to the test code, the logLevel stuff was all MIA. So... unless you have any more ideas, I guess I'll just have to add console.logs as needed during tests rather than reusing the existing log calls. |
Hard to say! I would suggest debugging inside loglevel's code in your environment (it's very very short, this is a tiny library) and trying to work out why Effectively, all loglevel does is run:
for each log level that's enabled. It's nothing especially complicated, and it should work in any standard JS environment anywhere. My best guess is that Jest is doing something very weird to globals, because it does all sorts of non-standard things like that which break libraries like this in different ways all the time (this is a widespread problem: https://twitter.com/matteocollina/status/1453029660925861901). If you can trace it down though, you might be able to work around it, or at least produce a clear bug the Jest team can fix. |
Thanks, Tim... I'll work on that. |
Well... that's interesting, and looks to be a work-around.
|
And the unexpected nicety is that these show up in-line with other output from the test, as opposed to being separated out at the very start of the test. |
Have you reported this to the Jest team? It seems like Jest is clearly doing its own custom handling of log output, and so I feel like they'll be more help here. |
Good idea; thanks for all your help on this! |
Any progress on this? I'm experiencing this with Jest |
I looked in Jest's issue list and found one solution that seems to work in jestjs/jest#687 It involves mapping the // Jest setupTests.js
import log from 'loglevel';
log.info = console.info;
log.debug = console.debug;
log.trace = console.trace;
log.error = console.error;
log.warn = console.warn; Also, I tried invoking |
First off, thanks for this module -- been using it for some time now and it really works great!
However, when I'm testing a module that has a logger, any output logged by the logger is MIA, while logs created via simple console.log appear just fine.
I'm using:
Loglevel 1.8.0
React TestingLibrary 11.2.6
MacOS BigSur 11.6.8
Here's my logger component:
Here's some sample code; notice that I'm using logger.enableAll() and confirming that the legLevel is as expected (0) in the component under test.
Test module:
Here are relevant snippets from the EntityRibbon component:
And here's the test output showing the problem:
In normal operation, these logs display perfectly fine!
The text was updated successfully, but these errors were encountered: