-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
修复因 jest 使用 stderr 输出警告而导致的 CI 执行失败 microsoft/rushstack#1329
- Loading branch information
1 parent
64ab4d4
commit fcaa34e
Showing
2 changed files
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |