Disable winston logging when running unit tests?

前端 未结 7 1075
暗喜
暗喜 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:49

    If you are using Jest, you can disable it like so:

    1. Set set up files to be run before jest runs the test. In package.json:

      {
          "jest": {
              "setupFiles": ["/jest-set-up/index.js"]
          }
      }
      
    2. In jest-set-up/index.js:

      import winston from 'winston'
      winston.remove(winston.transports.Console)
      

提交回复
热议问题