microsoft / appcenter-sdk-react-native

Development repository for the App Center SDK for React Native

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Importing appcenter-crashes in a file causes the test to crash

MarkusAbtion opened this issue · comments

Description

We have a utility file that imports the appcenter-crashes package.
When we run the tests for it, it immediately throws the following error:

 FAIL  src/utils/appcenter.test.tsx
  ● Test suite failed to run

    Invariant Violation: `new NativeEventEmitter()` requires a non-null argument.

      1 | import React from "react"
    > 2 | import Crashes from "appcenter-crashes"
        | ^
      3 |
      4 | import { ReactNativeError } from "~/components/ErrorBoundary"
      5 |

      at invariant (node_modules/invariant/invariant.js:40:15)
      at new NativeEventEmitter (node_modules/react-native/Libraries/EventEmitter/NativeEventEmitter.js:44:7)
      at Object.<anonymous> (node_modules/appcenter-crashes/Crashes.js:8:29)
      at Object.<anonymous> (src/utils/appcenter.utils.tsx:2:1)

Repro Steps

Please list the steps used to reproduce your issue.

  1. Import appcenter-crashes in a .tsx-file.
  2. Run jest on a test importing the file.

Details

  1. Which version of the App Center SDK are you using?
    • 4.3.0
  2. Which OS version did you experience the issue on?
    • Whatever jest is using
  3. What device version did you see this error on? Were you using an emulator or a physical device?
    • Whatever jest is using
  4. What third party libraries are you using?
    • "jest": "^26.6.3"
  5. Run the following command and paste the output below: react-native info
System:
    OS: macOS 10.15.6
    CPU: (12) x64 Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz
    Memory: 1.57 GB / 16.00 GB
    Shell: 5.7.1 - /bin/zsh
  Binaries:
    Node: 14.18.0 - ~/.asdf/installs/nodejs/lts/bin/node
    Yarn: 1.22.15 - /usr/local/bin/yarn
    npm: 6.14.15 - ~/.asdf/plugins/nodejs/shims/npm
    Watchman: 2021.10.04.00 - /usr/local/bin/watchman
  Managers:
    CocoaPods: 1.11.2 - /usr/local/bin/pod
  SDKs:
    iOS SDK:
      Platforms: iOS 14.4, DriverKit 20.2, macOS 11.1, tvOS 14.3, watchOS 7.2
    Android SDK:
      API Levels: 23, 25, 27, 28, 30
      Build Tools: 27.0.3, 28.0.3, 30.0.2
      System Images: android-27 | Google Play Intel x86 Atom, android-28 | Intel x86 Atom_64
      Android NDK: Not Found
  IDEs:
    Android Studio: Not Found
    Xcode: 12.4/12D4e - /usr/bin/xcodebuild
  Languages:
    Java: 1.8.0_201 - /usr/bin/javac
  npmPackages:
    @react-native-community/cli: Not Found
    react: 17.0.2 => 17.0.2 
    react-native: 0.66.0 => 0.66.0 
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found
  1. If you're developing for React Native iOS, run the following command and paste the output below: pod --version
  • 1.11.2
  1. Please enable verbose logging for your app using [MSAppCenter setLogLevel: MSLogLevelVerbose]; before your call to [AppCenterReactNative register]; (or any other SDK registration). For Android, use AppCenter.setLogLevel(android.util.Log.VERBOSE); before your SoLoader.init call (you will need to import com.microsoft.appcenter.AppCenter;). Include the logs here:
  • I'm not sure what to do here.

Hi! Thanks for getting in touch with us!
Did you try to add these lines for the Ject in your package.json?

"setupFiles": [
   "<rootDir>/node_modules/appcenter/test/AppCenterMock.js",
   "<rootDir>/node_modules/appcenter-analytics/test/AppCenterAnalyticsMock.js",
   "<rootDir>/node_modules/appcenter-crashes/test/AppCenterCrashesMock.js",
]

Thank you, @AnastasiaKubova. That worked 🚀
I think this might be missing from the React Native 0.60+ guide - at least I can't recall seeing it

Glad to hear that your issue was resolved! We will double-check it and update the docs.
Thanks for using App Center.