jest icon indicating copy to clipboard operation
jest copied to clipboard

[Bug]: jest fails with @react-native/polyfills/error-guard.js

Open daviseares opened this issue 3 years ago • 1 comments

Version

28.1.2

Steps to reproduce

jest.config.js

module.exports = {
  preset: 'react-native',
  // setupFilesAfterEnv: ['@testing-library/jest-native/extend-expect'],
  transformIgnorePatterns: [
    '<rootDir>/node_modules/(?!(@react-native|react-native)/)',
    '/node_modules/(?!(react-native|@react-native|@react-navigation/.*|@react-native-async-storage|react-native-gesture-handler)/.*)',
    '/node_modules/(?!(react-native-cookies|@sentry/react-native)/)',
  ],
  setupFiles: [
    './node_modules/react-native-gesture-handler/jestSetup.js',
    '<rootDir>/jest.setup.js',
  ],
  moduleNameMapper: {
    '\\.svg': '<rootDir>/__mocks__/svgMock.js',
  },
  collectCoverage: false,
  coverageDirectory: '__coverage__',
  coveragePathIgnorePatterns: ['/node_modules/', '.*.svg', '.*.png'],
  watchPathIgnorePatterns: ['<rootDir>/node_modules/'],
}

Expected behavior

Expected tests workf fine

Actual behavior

node_modules/@react-native/polyfills/error-guard.js:14
    type ErrorHandler = (error: mixed, isFatal: boolean) => void;
         ^^^^^^^^^^^^

    SyntaxError: Unexpected identifier

      at Runtime.createScriptFromCode (node_modules/jest-runtime/build/index.js:1796:14)
      at Object.<anonymous> (node_modules/react-native/jest/setup.js:16:6)

Additional context

I try all the solutions. I've tying for days and i always got the same problem.

Environment

System:
    OS: macOS 12.4
    CPU: (8) arm64 Apple M1
  Binaries:
    Node: 16.15.0 - /opt/homebrew/opt/node@16/bin/node
    Yarn: 1.22.18 - /opt/homebrew/bin/yarn
    npm: 8.5.5 - /opt/homebrew/opt/node@16/bin/npm
  npmPackages:
    jest: ^28.1.2 => 28.1.2

daviseares avatar Jun 30 '22 04:06 daviseares

I'm facing the same issue, @daviseares have you found a solution?

    SyntaxError: /Users/.../node_modules/@react-native/polyfills/error-guard.js: Missing semicolon. (14:4)

      12 | let _inGuard = 0;
      13 |
    > 14 | type ErrorHandler = (error: mixed, isFatal: boolean) => void;
         |     ^
      15 | type Fn<Args, Return> = (...Args) => Return;
      16 |
      17 | /**

Environment

  System:
    OS: macOS 12.4
    CPU: (10) arm64 Apple M1 Pro
  Binaries:
    Node: 16.14.2 - ~/.nvm/versions/node/v16.14.2/bin/node
    Yarn: 1.22.18 - ~/.nvm/versions/node/v16.14.2/bin/yarn
    npm: 8.5.0 - ~/.nvm/versions/node/v16.14.2/bin/npm
  npmPackages:
    jest: ^28.1.3 => 28.1.3 

edit: This looks like a bug from the react-native package: https://github.com/facebook/react-native/issues/33426

aike19115 avatar Jul 26 '22 08:07 aike19115

Any update on this issue

GittyAjay avatar Aug 27 '22 12:08 GittyAjay

node_modules shouldn't have to be transpiled - unfortunately that seems to be the norm in RN. You probably need to adjust transformIgnorePatterns: https://jestjs.io/docs/configuration#transformignorepatterns-arraystring

SimenB avatar Aug 27 '22 12:08 SimenB

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

github-actions[bot] avatar Sep 27 '22 00:09 github-actions[bot]