Why am i not seeing my console.log
Why am i not seeing my console.log output in tests?
I'm building a cloudflare worker using Hono and using vitest for testing. I have a simple test file but the second 'console.log' isn't showing. Why not? When I remove the call to "request" it does show. (p.s. createExecutionContext/waitOnExecutionContext doesn't make a difference)
4 Replies
Hey! 👋 Could you double check that
request()
isn't throwing by wrapping it with a try
/catch
? Could you try await
ing myapp.request()
too?I simplified it a bit too much 😉 Below is corrected code.
But I think it's an issue with vitest handling of console.log. When I use "vitest --run" it doesn't show either of the console.log results. When I use "vitest --watch" it doesn't show the output either, or sometimes only the first (after repeats). But when I place a "expect(1).toBe(0)" after the second console.log, both outputs are shown. Probably a vitest thingie that it only shows console.log in case of failure or something like that .. weird. (i'm used to jest)
Ah ok, does
--silent=false
help? You could also try --reporter=basic
maybe?sorry for late reply, i figured it out. Added to my vitest.config.ts:
...
fileParallelism: false,
reporters: ['basic'],
...
That fixed it.
Thank you for your help!