jest-fail-on-console icon indicating copy to clipboard operation
jest-fail-on-console copied to clipboard

console shows only up on no other failtures

Open daacrx opened this issue 1 year ago • 1 comments

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;
  },
});

daacrx avatar Dec 11 '23 12:12 daacrx

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.

ValentinH avatar Dec 12 '23 00:12 ValentinH

Implemented in https://github.com/ValentinH/jest-fail-on-console/releases/tag/v3.3.0

ValentinH avatar May 13 '24 12:05 ValentinH