diff --git a/apps/video-http-server/jest.config.js b/apps/video-http-server/jest.config.js index 9c074a7..622a84d 100644 --- a/apps/video-http-server/jest.config.js +++ b/apps/video-http-server/jest.config.js @@ -1,7 +1,8 @@ /** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ module.exports = { preset: 'ts-jest', - setupFilesAfterEnv: ['/setupTests.ts'], + setupFilesAfterEnv: ['/jest/setupTests.ts'], + reporters: ['./jest/JestReporter.js'], testEnvironment: 'node', testMatch: ['**/?(*.)+(spec|test).[t]s?(x)'], } diff --git a/apps/video-http-server/jest/JestReporter.js b/apps/video-http-server/jest/JestReporter.js new file mode 100644 index 0000000..4bbeb76 --- /dev/null +++ b/apps/video-http-server/jest/JestReporter.js @@ -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 diff --git a/apps/video-http-server/setupTests.ts b/apps/video-http-server/jest/setupTests.ts similarity index 100% rename from apps/video-http-server/setupTests.ts rename to apps/video-http-server/jest/setupTests.ts diff --git a/apps/video-http-server/tsconfig.build.json b/apps/video-http-server/tsconfig.build.json index 99c5f99..6ab6d38 100644 --- a/apps/video-http-server/tsconfig.build.json +++ b/apps/video-http-server/tsconfig.build.json @@ -1,4 +1,5 @@ { "extends": "./tsconfig", + "include": ["src/**/*"], "exclude": ["**/*.test.ts"] } diff --git a/apps/video-http-server/tsconfig.json b/apps/video-http-server/tsconfig.json index 9c707d3..186d710 100644 --- a/apps/video-http-server/tsconfig.json +++ b/apps/video-http-server/tsconfig.json @@ -17,5 +17,5 @@ "sourceMap": true, "target": "ES2020" }, - "include": ["src/**/*"] + "include": ["src/**/*", "jest-config/**/*"] }