-
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.
chore(video-http-server): fix jest reporter
修复因 jest 使用 stderr 输出警告而导致的 CI 执行失败 microsoft/rushstack#1329
- Loading branch information
1 parent
e76e1db
commit 1508a05
Showing
5 changed files
with
34 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ | ||
module.exports = { | ||
preset: 'ts-jest', | ||
setupFilesAfterEnv: ['<rootDir>/setupTests.ts'], | ||
setupFilesAfterEnv: ['<rootDir>/jest/setupTests.ts'], | ||
reporters: ['./jest/JestReporter.js'], | ||
testEnvironment: 'node', | ||
testMatch: ['**/?(*.)+(spec|test).[t]s?(x)'], | ||
} |
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,30 @@ | ||
// source: https://github.com/microsoft/just/blob/47ecde0d578b223a8abf26eebd0eff02ff331988/packages/just-scripts/src/jest/JestReporter.ts | ||
|
||
// 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 |
File renamed without changes.
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
{ | ||
"extends": "./tsconfig", | ||
"include": ["src/**/*"], | ||
"exclude": ["**/*.test.ts"] | ||
} |
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 |
---|---|---|
|
@@ -17,5 +17,5 @@ | |
"sourceMap": true, | ||
"target": "ES2020" | ||
}, | ||
"include": ["src/**/*"] | ||
"include": ["src/**/*", "jest-config/**/*"] | ||
} |