问题
Trying to write integrations tests for HTTPS function (implemented as an express app) that use Firestore as DB
Since its an integration test, I don't want to mock the Firestore DB in this case, however, since they perform network calls, they take time to execute
Is there a Firestore local emulator to use in this scenario? There is an option to config Firestore in offline mode, maybe that's the way? Didn't find any documentation in Firebase on this use case
AskFirebase
回答1:
You have to setup a Firestore emulator locally (assuming you already have firebase-cli
installed):
$ firebase setup:emulators:firestore
Then run the emulator:
$ firebase serve --only firestore
With the emulator running, you can run your test suites.
In order to write tests you can use the @firebase/testing
package. For more information, check the official documentation here.
There is also an official quickstart repository on GitHub, which shows how to test Firestore locally, both using JavaScript and Typescript. You can find it here.
来源:https://stackoverflow.com/questions/53759042/how-to-do-integration-tests-for-firebase-http-functions-with-firestore