Disable winston logging when running unit tests?

前端 未结 7 1076
暗喜
暗喜 2021-02-05 03:18

Can Winston logging be selectively disabled when executing unit tests of a node module?

Ideally, I\'d like to have logging for informational and debug purposes when the

7条回答
  •  情话喂你
    2021-02-05 03:43

    Sorry, I know this is a bit of an old question.

    What I do is a bit ugly, but allows me to keep using Jest's --silent option normally. I just set Winston's silent to process.argv.indexOf("--silent") >= 0. For example:

    const logger = new winston.Logger({
      …,
      transports: [
        new winston.transports.Console({
          …,
          silent: process.argv.indexOf("--silent") >= 0,
        }),
      ],
    });
    

提交回复
热议问题