NOTE: THIS ARTICLE IS IN PROGRESS...
Firestore is a next generation NoSQL database part of Google Cloud Platform. While Firestore left beta in January of this year and is positioned to replace Datastore, many supporting features are still in Beta and documentation on how it integrates with other Google Cloud Platform products is scarce. One such combo is running the Emulator in Google Cloud Build. My case for this is to run integration tests as part of a CI/CD pipeline. In this post, I will document how to do it as it took me and a few coworkers many many hours to figure this out.
A couple notes before we begin:
Pre Requisites:
The firestore emulator runs as a separate process. In a separate terminal from your app, start the emulator with the following command:
$ gcloud beta emulators firestore start --host-port=0.0.0.0:9999
If prompted, install the emulator package. If all goes well, you should see something like:
$ gcloud beta emulators firestore start --host-port=0.0.0.0:9999
Executing: /google-cloud-sdk/platform/cloud-firestore-emulator/cloud_firestore_emulator start --host=0.0.0.0 --port=9999
[firestore] API endpoint: http://0.0.0.0:9999
[firestore] If you are using a library that supports the FIRESTORE_EMULATOR_HOST environment variable, run:
[firestore]
[firestore] export FIRESTORE_EMULATOR_HOST=0.0.0.0:9999
[firestore]
[firestore] Dev App Server is now running.
[firestore]
Start your application with the environment variable in place. This tells the firestore client to talk to your emulator rather than the firebase service. Invoke your firebase queries and ensure your application is working. In the emulator terminal, note that requests are indeed being sent to it.
Next we'll write some unit tests to actually run our code locally . Follow this post on how to set up Jest testing to independently run unit and integration tests.
Add a simple test in a file called api.test.js with the contents:
Add a simple test in a file called api.test.integration.js with the contents:
TODO:
TODO:
TODO:
TODO:
References: