Repository: facebook/react
File: scripts/jest/shouldIgnoreConsoleError.js (JavaScript)

Code before:
        // This looks like an error addendum from ReactFiberErrorLogger.
        // Ignore it too.
        return true;
      }
      if (
        format.indexOf('ReactDOM.render is no longer supported in React 18') !==
          -1 ||
        format.indexOf(
          'ReactDOM.hydrate is no longer supported in React 18'
        ) !== -1
      ) {
        // We haven't finished migrating our tests to use createRoot.
        return true;
      }
    } else if (
      format != null &&
      typeof format.message === 'string' &&
      typeof format.stack === 'string' &&
      args.length === 0
    ) {
      if (format.stack.indexOf('Error: Uncaught [') === 0) {
        // This looks like an uncaught error from invokeGuardedCallback() wrapper
        // in development that is reported by jest-environment-jsdom. Ignore because it's noisy.
        return true;
      }
    }
  } else {
    if (
      format != null &&
      typeof format.message === 'string' &&
      typeof format.stack === 'string' &&
      args.length === 0
    ) {
      // In production, ReactFiberErrorLogger logs error objects directly.
      // They are noisy too so we'll try to ignore them.
      return true;
    }
  }
  // Looks legit
  return false;
};


Review comment (refactor):
There is still one error that is duplicated in console.error and `onRecoverableError`, so it's fine to ignore. There's a comment on that error to remove it: https://github.com/facebook/react/blob/763612647ceb66d95f728af896ca5e18a8181db8/packages/react-dom-bindings/src/client/ReactFiberConfigDOM.js#L1682

Code after:
        // in development that is reported by jsdom. Ignore because it's noisy.
        return true;
      }
      if (format.indexOf('The above error occurred') === 0) {
        // This looks like an error addendum from ReactFiberErrorLogger.
        // Ignore it too.
        return true;
      }
      if (
        format.indexOf('ReactDOM.render is no longer supported in React 18') !==
          -1 ||
        format.indexOf(
          'ReactDOM.hydrate is no longer supported in React 18'
        ) !== -1
      ) {
        // We haven't finished migrating our tests to use createRoot.
        return true;
      }
      if (
        TODO_ignoreHydrationErrors &&
        format.indexOf(
          'An error occurred during hydration. The server HTML was replaced with client content in'
        ) !== -1
      ) {
        // This also gets logged by onRecoverableError, so we can ignore it.
        return true;
      }
    } else if (
      format != null &&
      typeof format.message === 'string' &&
      typeof format.stack === 'string' &&
      args.length === 0
    ) {
      if (format.stack.indexOf('Error: Uncaught [') === 0) {
        // This looks like an uncaught error from invokeGuardedCallback() wrapper
        // in development that is reported by jest-environment-jsdom. Ignore because it's noisy.
        return true;
      }
    }
  } else {
    if (
      format != null &&
      typeof format.message === 'string' &&
      typeof format.stack === 'string' &&
      args.length === 0
    ) {
      // In production, ReactFiberErrorLogger logs error objects directly.
      // They are noisy too so we'll try to ignore them.
      return true;
    }
  }