Remove logging the origin line in Jest

前端 未结 3 808
说谎
说谎 2020-12-06 13:29

Jest has this feature to log the line that outputs to console methods.

In some cases, this can become annoying:

  console.log _modules/l         


        
3条回答
  •  被撕碎了的回忆
    2020-12-06 14:04

    With Jest 24.3.0 or higher, you can do this in pure TypeScript by adding the following to a Jest setup file configured in setupFilesAfterEnv:

    import { CustomConsole, LogType, LogMessage } from '@jest/console';
    
    function simpleFormatter(type: LogType, message: LogMessage): string {
        const TITLE_INDENT = '    ';
        const CONSOLE_INDENT = TITLE_INDENT + '  ';
    
        return message
            .split(/\n/)
            .map(line => CONSOLE_INDENT + line)
            .join('\n');
    }
    
    global.console = new CustomConsole(process.stdout, process.stderr, simpleFormatter);
    

提交回复
热议问题