Replies: 12 comments 5 replies
-
It's been sometime but for anyone facing the same problem, you can set --silent=false when running vitest to get console outputs. |
Beta Was this translation helpful? Give feedback.
-
Is this setting correct? I'm still not getting the console outputs on my terminal from running the test using the extension |
Beta Was this translation helpful? Give feedback.
-
No results here as well. Can someone please help us? |
Beta Was this translation helpful? Give feedback.
-
I just hit this too.. I found |
Beta Was this translation helpful? Give feedback.
-
I found that with the default reporter it swallows any output anyways. Using |
Beta Was this translation helpful? Give feedback.
-
Appears as though you can also use |
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
In my |
Beta Was this translation helpful? Give feedback.
-
Trick for certain situations: if you're just trying to get something printed to stdout, |
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
For anybody stuck using vitest v1.x, you can use |
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
Hi, thanks for the great extension.
One problem I'm facing is if I have a
console.log
statements in my tests, it doesn't get outputted to the terminal, compared to the commandnpx vitest
which does outputconsole.log
statements in terminalMy setting for
vitest.commandLine
isnpx vitest --watch
.Here is the test output I'm getting when running the extension. May I know how to get the
log
statements printed to test output?This is what I get from running
npx vitest
instead, which does print theconsole.log
statementsWhat I found is if I changed the
viteset.commandLine
setting 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
console
log outputs with thenpx vitest --watch
command? Or how to make the extension works properly while still getting theconsole
log statements printed on the terminal?Beta Was this translation helpful? Give feedback.
All reactions