vitest icon indicating copy to clipboard operation
vitest copied to clipboard

Add name of the test case and test module in `test.onConsoleLog` callbacks

Open AriPerkkio opened this issue 7 months ago • 1 comments

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

AriPerkkio avatar Jun 12 '25 13:06 AriPerkkio

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

sheremet-va avatar Jun 12 '25 20:06 sheremet-va