firebase / quickstart-nodejs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Where is the Cloud Functions emulator?

geeksilva97 opened this issue · comments

I came to here from https://firebase.googleblog.com/2019/05/whats-new-Google-IO-2019.html
In this article Francis tell about Cloud Functions emulator. But I can't find it.

@geeksilva97 thanks for asking! Right now you can read about it here:
https://firebase.google.com/docs/functions/local-emulator

We know we need many more docs/samples and we are working on those now!

This link is very useful. Thank you!

I'm missing a good documentation description for what is the purpose of firestore emulator and how do I test those scenarios locally instead of manipulating data externally.

It seems to be completelly different from Rachel Myers's demonstration.

@thereis the Firestore emulator is useful for two main things:

  • Writing security rules unit tests using the @firebase/testing Node.js library
  • Directly connecting your Android or iOS app to the emulator (web coming soon) similar to Rachel Myers demo.

If you have Cloud Functions that respond to Cloud Firestore triggers, those can be emulated as well.

If you want to connect your mobile apps, here's how:

Android

    // 10.0.2.2 is the special IP address for an Android Emulator
    // to access 'localhost' of the host computer
    FirebaseFirestoreSettings settings =
        new FirebaseFirestoreSettings.Builder()
                .setHost("10.0.2.2:8080")
                .setSslEnabled(false)
                .build();

    firestore.setFirestoreSettings(settings);

iOS (Swift)

let settings = Firestore.firestore().settings
settings.host = "localhost:8080"
settings.isSSLEnabled = false
Firestore.firestore().settings = settings

Make sure the emulator is running on the right port before starting your app. I hope that makes sense!

Thanks for the quick answer, now it makes sense for me :)

I have some questions that are confusing me about the emulator. Is it possible to save data inside the local firestore emulator or his functionality is only to create responses based on loaded rules?

Because I want to do some integration tests locally without reaching the production environment. It is mindblowing me because I want to test my functions without using firebase-functions-test, since it is very hard to comprehend and turn the code to "human readable".

@thereis it emulates the whole service, so yes it's a local substitute for the backend. However it does not implement persistence so when you shut it down all data is erased.

We published a lot of new docs since this issue was last updated so I am going to close it. For future questions please open a new issue. Thanks all!