vitest
vitest copied to clipboard
Add name of the test case and test module in `test.onConsoleLog` callbacks
Clear and concise description of the problem
I want to easily silence console.error's in vitest.config.ts. I know the test files that can cause these errors. Now I'm parsing test filename from stacktrace from log.
Suggested solution
Not yet sure how the arguments should be passed. Maybe a meta: { filename: string, testname?: string }?
import { defineConfig } from 'vitest/config'
export default defineConfig({
test: {
onConsoleLog(log, type, meta) {
if (meta.filename === 'math.test.ts' && meta.testName === 'sum should add 1 + 1') {
return false
}
},
})
Alternative
Additional context
Validations
- [x] Follow our Code of Conduct
- [x] Read the Contributing Guidelines.
- [x] Read the docs.
- [x] Check that there isn't already an issue that request the same feature to avoid creating a duplicate.
Not yet sure how the arguments should be passed
Can't we just provide reported task or undefined if called outside of test run? The log already has an optional taskId