Skip to content

Commit

Permalink
Hide console output when tests pass
Browse files Browse the repository at this point in the history
Implementation is due to jestjs/jest#4156

This is to get around travis-ci/travis-ci#4704
but is also much neater.
  • Loading branch information
bfirsh committed Sep 7, 2018
1 parent 4623e81 commit a7e3d78
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
4 changes: 3 additions & 1 deletion jest.config.js
@@ -1 +1,3 @@
module.exports = {};
module.exports = {
reporters: ["<rootDir>/tests/jest-reporter.js"]
};
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -32,6 +32,7 @@
"@storybook/html": "^4.0.0-alpha.11",
"babel-core": "^6.26.3",
"babel-runtime": "^6.26.0",
"chalk": "^2.4.1",
"jest": "^23.5.0",
"node-sass": "^4.9.3",
"parcel-bundler": "^1.9.7",
Expand Down
34 changes: 34 additions & 0 deletions tests/jest-reporter.js
@@ -0,0 +1,34 @@
/* eslint import/no-extraneous-dependencies: 0 */
// https://github.com/mozilla/addons-frontend/commit/6bbf218dc3c3872cbe25654cb63ed0dfd367cf00
const chalk = require("chalk");
const { getConsoleOutput } = require("jest-util");
const DefaultReporter = require("jest-cli/build/reporters/default_reporter")
.default;
const getResultHeader = require("jest-cli/build/reporters/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 FingersCrossedReporter 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 = FingersCrossedReporter;

0 comments on commit a7e3d78

Please sign in to comment.