setupFramework.ts 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /* global process */
  2. import '@visual-snapshot/jest';
  3. import failOnConsole from 'jest-fail-on-console';
  4. // The `@visual-snapshot/jest` package includes these types, but for some reason
  5. // Google Cloud Build's `tsc` fails to include the types (GHA works as expected).
  6. export {};
  7. declare global {
  8. namespace jest {
  9. // eslint complains that R is unused, but we need to match interface,
  10. // eslint-disable-next-line @typescript-eslint/no-unused-vars
  11. interface Matchers<R> {
  12. toSnapshot(): CustomMatcherResult;
  13. }
  14. }
  15. }
  16. process.on('unhandledRejection', reason => {
  17. // eslint-disable-next-line no-console
  18. console.error(reason);
  19. });
  20. failOnConsole({
  21. shouldFailOnWarn: false,
  22. silenceMessage: errorMessage => {
  23. // Ignore the following warnings
  24. if (
  25. /Warning: componentWill(Mount|ReceiveProps) has been renamed/.test(errorMessage)
  26. ) {
  27. return true;
  28. }
  29. if (/HTMLMediaElement.prototype.play/.test(errorMessage)) {
  30. return true;
  31. }
  32. // This warning was removed in React 18, can be ignored in most cases
  33. // https://github.com/reactwg/react-18/discussions/82
  34. if (
  35. /Warning: Can't perform a React state update on an unmounted component/.test(
  36. errorMessage
  37. )
  38. ) {
  39. return true;
  40. }
  41. return false;
  42. },
  43. });