Open
Description
openedon Nov 8, 2024
Version
29.7.0
Steps to reproduce
I have followed the below document to create my own custom reporter,
https://jestjs.io/docs/configuration#custom-reporters
class CustomReporter {
constructor(globalConfig, reporterOptions, reporterContext) {
this._globalConfig = globalConfig;
this._options = reporterOptions;
this._context = reporterContext;
}
// Optionally, reporters can force Jest to exit with non zero code by returning
// an `Error` from `getLastError()` method.
getLastError() {
console.log('this._shouldFail', this._shouldFail);
if (this._shouldFail) {
return new Error('Custom error reported!');
}
}
}
Expected behavior
when test fails., it should print out this._shouldFail true
, and also should throw non 0 exit code
Actual behavior
console logged this._shouldFail undefined
., and no error was thrown
Additional context
my jest.config.js
as below
module.exports = {
preset: 'ts-jest',
collectCoverage: true,
collectCoverageFrom: [
'src/**/*.js',
'src/**/*.ts',
'src/**/*.tsx',
],
transform: {
'^.+\\.(ts|tsx)?$': 'ts-jest',
'^.+\\.(js|jsx)$': 'babel-jest',
},
testMatch: ['**/_test_/**/*.test.js?(x)'],
coverageReporters: ['json-summary'],
reporters: ['default', '<rootDir>/scripts/customTestReporter.js'],
};
Environment
System:
OS: macOS 14.7
CPU: (8) arm64 Apple M3
Binaries:
Node: 18.14.0 - ~/.nvm/versions/node/v18.14.0/bin/node
Yarn: 1.22.22 - ~/.nvm/versions/node/v18.14.0/bin/yarn
npm: 9.3.1 - ~/.nvm/versions/node/v18.14.0/bin/npm
npmPackages:
jest: ^29.7.0 => 29.7.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment