Created
May 9, 2019 06:38
-
-
Save GeeWee/71db0d9911b4a087e4b2486386168b05 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* eslint import/no-extraneous-dependencies: 0 */ | |
const chalk = require('chalk'); | |
const { getConsoleOutput } = require('jest-util'); | |
const SummaryReporter = require('@jest/reporters/build/summary_reporter') | |
.default; | |
const DefaultReporter = require('@jest/reporters/build/default_reporter') | |
.default; | |
const getResultHeader = require('@jest/reporters/build/get_result_header') | |
.default; | |
const TITLE_BULLET = chalk.bold('\u25cf '); | |
// This Jest reporter does not output any console.log except when the tests are | |
// failing, see: https://github.com/mozilla/addons-frontend/issues/2980. | |
class LogOnFailedTestReporter extends DefaultReporter { | |
printTestFileHeader(testPath, config, result) { | |
this.log(getResultHeader(result, this._globalConfig, config)); | |
const consoleBuffer = result.console; | |
const testFailed = result.numFailingTests > 0; | |
if (testFailed && consoleBuffer && consoleBuffer.length) { | |
// prettier-ignore | |
this.log( | |
` ${TITLE_BULLET}Console\n\n${getConsoleOutput( | |
config.cwd, | |
!!this._globalConfig.verbose, | |
consoleBuffer | |
)}` | |
); | |
} | |
} | |
} | |
module.exports = LogOnFailedTestReporter; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment