jest-fail-on-console
jest-fail-on-console copied to clipboard
console shows only up on no other failtures
This is the setup:
failOnConsole({ shouldFailOnError: true, shouldFailOnWarn: true, });
I recognized that the console will only print, if there is no other error or failed jest expect exception. So basically the console statement is not immediately printed when the code execution reaches the code, but later, eventually.
See example below:
test('will neither fail nor print due to console, but shows failing expect only', () => {
console.error('show me please');
expect(true).toBe(false);
});
Is this expected? It would be nice to have a configuration to change this behavior and always and immediately show the console statement.
This is a workaround:
failOnConsole({
shouldFailOnError: true,
shouldFailOnWarn: true,
silenceMessage: (errorMessage, methodName, context) => {
/**
* on local machine we want to display all logs. It must be console.log,
* otherwise it produces infinite loops
*/
if (process.env.CI && process.env.CI !== 'false') {
console.log(errorMessage);
}
return false;
},
});
Thank you for this feature request. I understand the need, would you like to create a PR to implement this as a new option? It should not be too complex.
Implemented in https://github.com/ValentinH/jest-fail-on-console/releases/tag/v3.3.0