Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ module.exports = {
// Replaces the following formats with an empty module.
'^.+\\.(scss|css|svg|woff|woff2|mp4|webm)$': '<rootDir>/tests/emptyModule',
},
reporters: ['<rootDir>/tests/jest-reporters/fingers-crossed.js'],
setupTestFrameworkScriptFile: '<rootDir>/tests/setup.js',
testPathIgnorePatterns: [
'<rootDir>/node_modules/',
Expand Down
33 changes: 33 additions & 0 deletions tests/jest-reporters/fingers-crossed.js
Original file line number Diff line number Diff line change
@@ -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;