I'm using vitest in VS Code with the official Vitest test runner plugin.
All works as expected, but any console.log() statements don't seem to appear anywhere.
Not in the VScode test results tab, or the test output tab, not in the Testing panel...
I've also tried importing log directly, same result (no output):
import { log } from "console";
Am I missing a configuration option?
In my case what this the trick was:
vitest run --printConsoleTrace=true --silent=false
You can check it out here https://vitest.dev/guide/cli#printconsoletrace
Actually, I'm facing an identical issue, and although I haven't been able to definitively resolve it, here are a few things that might help:
describe, it('should do something')) are defined as async.
For example: describe('my tested module', () => {...} // INCORRECT
describe('my tested module', async () => {...} // CORRECT
vitests.config.ts), inside the test object in the call to defineConfig(), you are not defining onConsoleLog handler that returns false. This will stop Vitest from outputting console.log() statements to the debug console.
See documentation on Configuring Vitest.Example:
export default defineConfig({
test: {
server: { deps: { inline: ['@fastify/autoload'] } },
testTimeout: 100000,
setupFiles: ['dotenv/config'],
onConsoleLog(log: string, type: 'stdout' | 'stderr'): boolean | void {
return false; // NO console.log() statements will be printed!
},
},
});
console.log() statements being printed to the console, while debugging them does not. I am not sure why that is.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With