ValentinH / jest-fail-on-console

Utility to make jest tests fail when console.error() or any other methods are used
MIT License
141 stars 20 forks source link

jest.retryTests and unique key prop error #32

Closed vinodgubbala closed 1 year ago

vinodgubbala commented 1 year ago

I recently upgraded jest from 2.1.1 to 3.0.2. And later found it stopped failing tests for console.errors if CI=true

vinodgubbala commented 1 year ago

I understand the issue. I have a react component which iteration, and the children does not have key. React logs console error if failed to found the key.

And I also have jest.retryTimes configured for flaky tests.

This makes the key error to disappear on second retry. Any idea how to get around this?

ValentinH commented 1 year ago

I don't understand what is not working properly. From your explanation, it seems that this is the normal behaviour of jest.retryTimes. Moreover, this option isn't related to this plugin so what do you expect from us?

vinodgubbala commented 1 year ago

Apologies for the confusion. Initially I though jest-fail-on-console is not working. But later realised it is due to retryTimes. Basically we missed an error in CI due to the combination of both jest-fail-on-console and jest.retryTimes. So wondering now what can be the option.

vinodgubbala commented 1 year ago

I did this as a workaround. In case someone is looking for

jest.retryTimes(isCI ? 2 : 0);
const logsCollection = [];
failOnConsole({
  shouldFailOnError: true,
  shouldFailOnWarn: true,
  shouldFailOnLog: isCI,
  shouldFailOnAssert: isCI,
  shouldFailOnInfo: isCI,
  shouldFailOnDebug: isCI,
  silenceMessage: (message, methodName) => {
    if (isCI) {
      logsCollection.push(message);
    }
    return false;
  }
});

afterAll(() => {
  if (isCI && logsCollection.length) {
    // Fail with one of the errors. Target is to break the CI.
    throw logsCollection[0];
  }
});