Repository navigation
Replies: 20 comments 9 replies
|
It's been sometime but for anyone facing the same problem, you can set --silent=false when running vitest to get console outputs. |
|
No results here as well. Can someone please help us? |
|
I just hit this too.. I found |
|
I found that with the default reporter it swallows any output anyways. Using |
|
Appears as though you can also use |
|
Vitest provides a configuration method called /// <reference types="vitest" />
import { defineConfig, mergeConfig } from 'vitest/config';
import viteConfig from './vite.config';
export default mergeConfig(
viteConfig({ command: 'build', mode: 'TEST' }),
defineConfig({
test: {
coverage: {
exclude: ['src/api'],
include: ['src'],
},
environment: 'jsdom',
globals: true,
setupFiles: './setupTests.ts',
onConsoleLog(log: string, type: 'stdout' | 'stderr'): false | void {
console.log('log in test: ', log);
if (log === 'message from third party library' && type === 'stdout') {
return false;
}
},
},
}),
);Quick note: If you have spied on console.log for testing any scenarios in your test case, then the spy will swallow the logs and no log in your test case will be printed to terminal. |
|
In my |
|
Trick for certain situations: if you're just trying to get something printed to stdout, |
|
Appreciate all of the work arounds, but I think it would be an important (maybe necessary) feature of a test runner to be able to just log output without having to mess with config. |
|
For anybody stuck using vitest v1.x, you can use |
|
There are several answers here - none of which seem to be working for me. Is there a definitive way to enable console.log() printing? As a previous poster mentioned, this feels like an essential thing to allow. |
|
The above solutions does not work with console.info |
|
|
|
for me it did also not work until I changed |
|
|
|
If you're wanting the logging to appear in the JetBrains tools such as WebStorm try a It's the |
|
none of the differents solutions described here has worked for me (I'm on vitest 4, if matters) |
|
Use loggers like pino or winston instead. Then it should work. However, this should also work If not try other console like warn, debug or error instead of log |
|
The vitest option So, try (if you are using npm): If you are using pnpm: Or in your package.json: |

Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Hi, thanks for the great extension.
One problem I'm facing is if I have a
console.logstatements in my tests, it doesn't get outputted to the terminal, compared to the commandnpx vitestwhich does outputconsole.logstatements in terminalMy setting for
vitest.commandLineisnpx vitest --watch.Here is the test output I'm getting when running the extension. May I know how to get the
logstatements printed to test output?This is what I get from running

npx vitestinstead, which does print theconsole.logstatementsWhat I found is if I changed the
viteset.commandLinesetting tonpx vitest --instead, it will show the console log output, however the extension will hang on the test and never finished as the command "Wait for file changes" forever.So is it possible to get the
consolelog outputs with thenpx vitest --watchcommand? Or how to make the extension works properly while still getting theconsolelog statements printed on the terminal?All reactions