How to do integration tests for Firebase HTTP functions with Firestore

你。 提交于 2020-06-28 07:55:39

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!