diff --git a/apps/front-end/jest.config.js b/apps/front-end/jest.config.js index f127687..3a8c1a6 100644 --- a/apps/front-end/jest.config.js +++ b/apps/front-end/jest.config.js @@ -2,6 +2,7 @@ const config = { verbose: true, setupFilesAfterEnv: ['/src/setupTests.ts'], + reporters: ['./src/JestReporter.js'], testMatch: ['**/src/**/*.test.ts?(x)'], transform: { '^.+\\.[jt]sx?$': 'babel-jest', diff --git a/apps/front-end/src/JestReporter.js b/apps/front-end/src/JestReporter.js new file mode 100644 index 0000000..ede71b3 --- /dev/null +++ b/apps/front-end/src/JestReporter.js @@ -0,0 +1,28 @@ +// This doesn't have types for some reason +// eslint-disable-next-line @typescript-eslint/no-var-requires +const { DefaultReporter } = require('@jest/reporters') + +/** + * The purpose of this custom reporter is to prevent Jest from logging to stderr + * when there are no errors. + */ +class JestReporter extends DefaultReporter { + _isLoggingError = false + + log(message) { + if (this._isLoggingError) { + process.stderr.write(message + '\n') + } else { + process.stdout.write(message + '\n') + } + } + + printTestFileFailureMessage(...args) { + this._isLoggingError = true + super.printTestFileFailureMessage(...args) + this._isLoggingError = false + } +} + +// jest needs this format +module.exports = JestReporter