Skip to content

Commit

Permalink
chore(video-http-server): fix jest reporter
Browse files Browse the repository at this point in the history
修复因 jest 使用 stderr 输出警告而导致的 CI 执行失败
microsoft/rushstack#1329
  • Loading branch information
XYShaoKang committed Sep 4, 2021
1 parent e76e1db commit 1508a05
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 2 deletions.
3 changes: 2 additions & 1 deletion apps/video-http-server/jest.config.js
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)'],
}
30 changes: 30 additions & 0 deletions apps/video-http-server/jest/JestReporter.js
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.
1 change: 1 addition & 0 deletions apps/video-http-server/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"extends": "./tsconfig",
"include": ["src/**/*"],
"exclude": ["**/*.test.ts"]
}
2 changes: 1 addition & 1 deletion apps/video-http-server/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
"sourceMap": true,
"target": "ES2020"
},
"include": ["src/**/*"]
"include": ["src/**/*", "jest-config/**/*"]
}

0 comments on commit 1508a05

Please sign in to comment.