-
Notifications
You must be signed in to change notification settings - Fork 400
/
fingers-crossed.js
33 lines (28 loc) · 1.07 KB
/
fingers-crossed.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/* eslint import/no-extraneous-dependencies: 0 */
const chalk = require('chalk');
const { getConsoleOutput } = require('@jest/console');
const DefaultReporter =
require('@jest/reporters/build/DefaultReporter').default;
const getResultHeader =
require('@jest/reporters/build/getResultHeader').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;