17

I'm using node with mocha and winston. Is there a way to set it up so it only shows logs for failing tests?

Koen Bok
  • 3,234
  • 3
  • 29
  • 42
  • @Brand's answer is 100% correct. I prefer to be more explicit and use `mocha --reporter min` instead of `mocha -R min`. Just another way to do the same thing. – HussienK Feb 13 '17 at 16:45

3 Answers3

16

If you run with the min reporter you will only get full output on failed tests: mocha -R min or, if you prefer the verbose option, mocha --reporter min.

Louis
  • 146,715
  • 28
  • 274
  • 320
Brand
  • 364
  • 3
  • 7
0

As of writing (in 2022), there's now an npm package that does exactly this:

https://www.npmjs.com/package/mocha-suppress-logs

I like it because I like the output from the default mocha reporter. It keeps all that, but hides console output for succeeding tests.

verespej
  • 710
  • 6
  • 9
-1

Possible to use

if (!expect(next.called).to.be.true) {
        console.log("... further information")
}
DaveX
  • 147
  • 1
  • 4