From 7a1592e3f34b542b1380842e217e4969e2830561 Mon Sep 17 00:00:00 2001 From: William Durand Date: Tue, 7 Aug 2018 23:40:35 +0200 Subject: [PATCH 1/2] Add custom reporter to reduce the test output --- jest.config.js | 1 + tests/fingers-crossed-reporter.js | 33 +++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 tests/fingers-crossed-reporter.js diff --git a/jest.config.js b/jest.config.js index d8919b232ef..7739b2ff4d7 100644 --- a/jest.config.js +++ b/jest.config.js @@ -15,6 +15,7 @@ module.exports = { // Replaces the following formats with an empty module. '^.+\\.(scss|css|svg|woff|woff2|mp4|webm)$': '/tests/emptyModule', }, + reporters: ['/tests/fingers-crossed-reporter.js'], setupTestFrameworkScriptFile: '/tests/setup.js', testPathIgnorePatterns: [ '/node_modules/', diff --git a/tests/fingers-crossed-reporter.js b/tests/fingers-crossed-reporter.js new file mode 100644 index 00000000000..4408b5bfa26 --- /dev/null +++ b/tests/fingers-crossed-reporter.js @@ -0,0 +1,33 @@ +/* eslint import/no-extraneous-dependencies: 0 */ +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; From ea33d5edd7e1ec805226789f159404014e69ef0f Mon Sep 17 00:00:00 2001 From: William Durand Date: Wed, 8 Aug 2018 18:00:07 +0200 Subject: [PATCH 2/2] move file to tests/jest-reporters/ --- jest.config.js | 2 +- .../fingers-crossed.js} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename tests/{fingers-crossed-reporter.js => jest-reporters/fingers-crossed.js} (100%) diff --git a/jest.config.js b/jest.config.js index 7739b2ff4d7..9d6b9b80a4c 100644 --- a/jest.config.js +++ b/jest.config.js @@ -15,7 +15,7 @@ module.exports = { // Replaces the following formats with an empty module. '^.+\\.(scss|css|svg|woff|woff2|mp4|webm)$': '/tests/emptyModule', }, - reporters: ['/tests/fingers-crossed-reporter.js'], + reporters: ['/tests/jest-reporters/fingers-crossed.js'], setupTestFrameworkScriptFile: '/tests/setup.js', testPathIgnorePatterns: [ '/node_modules/', diff --git a/tests/fingers-crossed-reporter.js b/tests/jest-reporters/fingers-crossed.js similarity index 100% rename from tests/fingers-crossed-reporter.js rename to tests/jest-reporters/fingers-crossed.js