Reputation: 39
I trying to test my google firebase cloud functions on my local computer using firebase emulator:start. However the local instance of the cloud function is not being executed, instead the instance on Google Cloud gets executed.
I followed these steps for setting the emulator up: https://firebase.google.com/docs/functions/local-emulator
$ export GOOGLE_APPLICATION_CREDENTIALS='path/tofile'
$ firebase setup:emulators:firestore
$ firebase init firestore
$ export FIRESTORE_EMULATOR_HOST=localhost:8080
$ firebase emulators:start
Starting emulators: ["functions","firestore","hosting"]
⚠ Your requested "node" version "8" doesn't match your global version "10"
✔ functions: Emulator started at http://localhost:5001
i firestore: Logging to firestore-debug.log
✔ firestore: Emulator started at http://localhost:8080
i firestore: For testing set FIRESTORE_EMULATOR_HOST=localhost:8080
✔ hosting: Emulator started at http://localhost:5000
i hosting: Serving hosting files from: www
✔ hosting: Local server: http://localhost:5000
i functions: Watching "/home/borch/Documents/Ionic/myproject/functions" for Cloud Functions...
i functions: Setting up Cloud Firestore trigger "myGCFunction"
✔ functions: Trigger "myGCFunction" has been acknowledged by the Cloud Firestore emulator.
As you can see the trigger is recognized by the cloud firestore emulator.
But the functions that gets executed every time I call myGCFunction is the one on Google Cloud. I think it should execute the function from my local API running at localhost:8080, correct?
I realize that only the function on the cloud is executed because I checked the firebase function console with new records of that function execution.
I updated firebase-admin and firebase-functions to its latest version:
$ cat functions/package.json | grep firebase-
"firebase-admin": "^8.2.0",
"firebase-functions": "^3.0.2",
Thanks.
Upvotes: 1
Views: 3284
Reputation: 317362
The local emulator is not going to respond to changes in the cloud. You have to actually change the locally emulated database in order to trigger locally emulated functions.
(Imagine if you accidentally started a local emulator that responded to changes against a busy production database - that would not scale well on your local machine, would it? The local environment must be totally isolated from any cloud hosted environment in order to work sanely.)
Upvotes: 1