close
  • 简体中文
  • onConsoleLog

    • 类型: (content: string, type: 'stdout' | 'stderr') => boolean | void
    • 默认值: undefined

    自定义 console 日志的处理函数,这有助于过滤来自第三方库的日志。

    处理函数会接收到日志内容 content 以及它的来源流 type'stdout''stderr'),因此你既能按文本过滤,也能按输出流过滤。如果你返回 false,Rstest 不会将此日志打印到控制台。

    rstest.config.ts
    import { defineConfig } from '@rstest/core';
    
    export default defineConfig({
      onConsoleLog: (content, type) => {
        if (type === 'stderr' && content.includes('deprecated')) {
          return false;
        }
      },
    });
    Note

    disableConsoleIntercepttrue 时,onConsoleLog 将不会生效。

    静默控制台日志

    你可以通过在 onConsoleLog 处理函数中返回 false 来静默控制台日志。

    rstest.config.ts
    import { defineConfig } from '@rstest/core';
    export default defineConfig({
      onConsoleLog: () => false,
    });