Skip to content

Instantly share code, notes, and snippets.

@pongo
Last active February 5, 2021 08:25
Show Gist options
  • Save pongo/4bd62bbf4649a9ae0e3f2591cf6fc756 to your computer and use it in GitHub Desktop.
Save pongo/4bd62bbf4649a9ae0e3f2591cf6fc756 to your computer and use it in GitHub Desktop.
Hide console logging for passing tests and show it for failures (#4156)

Use this configuration option to add custom reporters to Jest

reporters: [
  '<rootDir>/tests/reporter.js',
],
// https://github.com/facebook/jest/issues/4156#issuecomment-757376195
const { DefaultReporter } = require('@jest/reporters')
class Reporter extends DefaultReporter
{
constructor()
{
super(...arguments)
}
printTestFileHeader(_testPath, config, result)
{
const console = result.console
if(result.numFailingTests === 0 && !result.testExecError)
{
result.console = null
}
super.printTestFileHeader(...arguments)
result.console = console
}
}
module.exports = Reporter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment