Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🔥Tests broken out of the box (v6.3.4) #3391

Closed
1 of 10 tasks
itsravenous opened this issue Apr 3, 2020 · 5 comments
Closed
1 of 10 tasks

🔥Tests broken out of the box (v6.3.4) #3391

itsravenous opened this issue Apr 3, 2020 · 5 comments
Labels
Type: Testing Issues or PRs relating to testing (the library or user code testing)

Comments

@itsravenous
Copy link

itsravenous commented Apr 3, 2020

Issue

I've just followed the quick start setup guide to get a new project going. I went as far as adding my firebase credentials and then - without modifying any files - decided to try out the tests.

Running yarn test produces the following error:

yarn run v1.17.3
$ jest
 FAIL  __tests__/App-test.js
  ● Test suite failed to run

    /Users/itsravenous/dev/critter/TrackReactNative/node_modules/@react-native-firebase/app/lib/index.js:18
    import { getFirebaseRoot } from './internal/registry/namespace';
    ^^^^^^

    SyntaxError: Cannot use import statement outside a module

      10 | import { Platform, StyleSheet, Text, View } from 'react-native';
      11 | 
    > 12 | import firebase from '@react-native-firebase/app';
         | ^
      13 | 
      14 | // TODO(you): import any additional firebase services that you require for your app, e.g for auth:
      15 | //    1) install the npm package: `yarn add @react-native-firebase/auth@alpha` - you do not need to

      at ScriptTransformer._transformAndBuildScript (node_modules/@jest/transform/build/ScriptTransformer.js:537:17)
      at ScriptTransformer.transform (node_modules/@jest/transform/build/ScriptTransformer.js:579:25)
      at Object.<anonymous> (App.js:12:1)

Some searching led me to a StackOverflow question about this error in general, and I modified one of the answers to whitelist react-native and @react-native-firebase firebase modules so they'd be transformed by babel when running jest:

package.json

"jest": {
    "preset": "react-native",
    "transformIgnorePatterns": [
      "node_modules/(?!react-native|@react-native-firebase/(.*))"
    ]
  }

I re-ran the tests and this time saw a different error:

yarn run v1.17.3
$ jest
 FAIL  __tests__/App-test.js
  ● Test suite failed to run

    Invariant Violation: Native module cannot be null.

      at invariant (node_modules/invariant/invariant.js:40:15)
      at new NativeEventEmitter (node_modules/react-native/Libraries/EventEmitter/NativeEventEmitter.js:36:7)
      at RNFBNativeEventEmitter.<anonymous> (node_modules/@react-native-firebase/app/lib/internal/RNFBNativeEventEmitter.js:22:232)
      at new RNFBNativeEventEmitter (node_modules/@react-native-firebase/app/lib/internal/RNFBNativeEventEmitter.js:24:5)
      at Object.<anonymous> (node_modules/@react-native-firebase/app/lib/internal/RNFBNativeEventEmitter.js:48:16)
      at Object.<anonymous> (node_modules/@react-native-firebase/app/lib/internal/registry/nativeModule.js:21:1)

I'm hoping this is simple user error, but I haven't done anything outside of what's in the tutorial 🤷‍♂️ It's worth noting that I don't see these issues when scaffolding a React Native app with npx react-native init AwesomeProject, nor if I scaffold a plain React Native app and then add react-native-firebase as described in the docs


Project Files

Javascript

Click To Expand

package.json:

{
  "name": "MyReactNativeApp",
  "version": "6.3.4",
  "private": true,
  "scripts": {
    "start": "react-native start",
    "run:android": "react-native run-android",
    "run:ios": "react-native run-ios --simulator=\"iPhone X\"",
    "build:apk": "cd android && ./gradlew assembleRelease",
    "test": "jest",
    "prepare": "patch-package"
  },
  "dependencies": {
    "@react-native-firebase/app": "6.3.4",
    "react": "16.9.0",
    "react-native": "0.61.5"
  },
  "devDependencies": {
    "@babel/core": "^7.6.2",
    "@babel/runtime": "^7.6.2",
    "@react-native-community/cli": "^2.9.0",
    "@react-native-community/eslint-config": "^0.0.5",
    "babel-jest": "^24.9.0",
    "eslint": "^6.5.1",
    "jest": "^24.9.0",
    "metro-react-native-babel-preset": "^0.56.0",
    "patch-package": "^6.1.4",
    "react-test-renderer": "16.9.0"
  },
  "jest": {
    "preset": "react-native"
  }
}

firebase.json for react-native-firebase v6:

# N/A

iOS

Click To Expand

ios/Podfile:

  • I'm not using Pods
  • I'm using Pods and my Podfile looks like:
# not relevant - this is a node/jest issue

AppDelegate.m:

// N/A


Android

Click To Expand

Have you converted to AndroidX?

  • my application is an AndroidX application?
  • I am using android/gradle.settings jetifier=true for Android compatibility?
  • I am using the NPM package jetifier for react-native compatibility?

android/build.gradle:

// N/A

android/app/build.gradle:

// N/A

android/settings.gradle:

// N/A

MainApplication.java:

// N/A

AndroidManifest.xml:

<!-- N/A -->


Environment

Click To Expand

react-native info output:

 info Fetching system and libraries information...
System:
    OS: macOS Mojave 10.14.6
    CPU: (4) x64 Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz
    Memory: 440.90 MB / 16.00 GB
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 12.16.1 - ~/.nvm/versions/node/v12.16.1/bin/node
    Yarn: 1.17.3 - /usr/local/bin/yarn
    npm: 6.13.4 - ~/.nvm/versions/node/v12.16.1/bin/npm
  SDKs:
    iOS SDK:
      Platforms: iOS 12.4, macOS 10.14, tvOS 12.4, watchOS 5.3
  IDEs:
    Xcode: 10.3/10G8 - /usr/bin/xcodebuild
  npmPackages:
    @react-native-community/cli: ^2.9.0 => 2.10.0 
    react: 16.9.0 => 16.9.0 
    react-native: 0.61.5 => 0.61.5
  • Platform that you're experiencing the issue on:
    • iOS
    • Android
    • iOS but have not tested behavior on Android
    • Android but have not tested behavior on iOS
    • Both
  • react-native-firebase version you're using that has this issue:
    • e.g. 6.3.4
  • Firebase module(s) you're using that has the issue:
    • e.g. Instance ID
  • Are you using TypeScript?
    • N

@russellwheatley russellwheatley added Type: Testing Issues or PRs relating to testing (the library or user code testing) Version: >= 6 labels Apr 6, 2020
@stale
Copy link

stale bot commented May 4, 2020

Hello 👋, to help manage issues we automatically close stale issues.
This issue has been automatically marked as stale because it has not had activity for quite some time. Has this issue been fixed, or does it still require the community's attention?

This issue will be closed in 15 days if no further activity occurs.
Thank you for your contributions.

@stale stale bot added the Type: Stale Issue has become stale - automatically added by Stale bot label May 4, 2020
@nyenye
Copy link

nyenye commented May 7, 2020

Having the same issue here. Does anyone know anything about it?

@stale stale bot removed the Type: Stale Issue has become stale - automatically added by Stale bot label May 7, 2020
@PierreCapo
Copy link

@nyenye i think this can help you: #3035 (comment)

@nyenye
Copy link

nyenye commented May 14, 2020

@PierreCapo Thanks mate! I did find a similar workaround, but yeah, I'll implement this one, which will be more convenient for testing. Thanks again!

@Salakar
Copy link
Member

Salakar commented May 15, 2020

Closing - lets track on #3035.

@Salakar Salakar closed this as completed May 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Testing Issues or PRs relating to testing (the library or user code testing)
Projects
None yet
Development

No branches or pull requests

5 participants