Skip to content
Open
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
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,17 @@ Warnings are supressed by default, use `showWarnings` to log them.

Note: this config is also available as an environment variable `JEST_SILENT_REPORTER_SHOW_WARNINGS=true`.

### showConsoleOnFailure: boolean

All logs to console are supressed by default, use `showConsoleOnFailure` to log them for the tests that failed.

```json
{
"reporters": [["jest-silent-reporter", { "showConsoleOnFailure": true }]]
}
```

Note: this config is also available as an environment variable `JEST_SILENT_REPORTER_SHOW_CONSOLE_ON_FAILURE=true`.

### showPaths: boolean

Expand Down
10 changes: 9 additions & 1 deletion SilentReporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ class SilentReporter {
this.showWarnings =
!!process.env.JEST_SILENT_REPORTER_SHOW_WARNINGS ||
!!options.showWarnings;
this.showConsoleOnFailure =
!!process.env.JEST_SILENT_REPORTER_SHOW_CONSOLE_ON_FAILURE ||
!!options.showConsoleOnFailure;
this.showSeed = !!globalConfig.showSeed
}

Expand Down Expand Up @@ -55,12 +58,17 @@ class SilentReporter {
}
if (testResult.failureMessage)
this.stdio.log('\n' + testResult.failureMessage);
if (testResult.console && this.showWarnings) {
if (testResult.console && this.showWarnings && !(hasFailures && this.showConsoleOnFailure)) {
testResult.console
.filter(entry => ['error', 'warn'].includes(entry.type) && entry.message)
.map(entry => entry.message)
.forEach(this.stdio.log);
}
if (testResult.console && hasFailures && this.showConsoleOnFailure) {
testResult.console
.map(entry => entry.message)
.forEach(this.stdio.log);
}
const snapshotStatuses = helpers.getSnapshotStatus(
testResult.snapshot,
didUpdate
Expand Down