Running Firestore local e.g. for testing

前端 未结 7 930
盖世英雄少女心
盖世英雄少女心 2021-02-02 07:36

Is there a way to run firestore locally (e.g. for testing purposes)?

What would the approach to write tests against the DB (except of using mocks)

7条回答
  •  逝去的感伤
    2021-02-02 08:05

    There are two libraries which attempt to facilitate mocking of the firebase sdk.

    1) https://github.com/soumak77/firebase-mock
    2) https://github.com/mikkopaderes/mock-cloud-firestore

    I currently use the first one, since it seems to have a bit more of the SDK implemented.

    They're not perfect, but they're currently sufficient for my needs, and are preferable to the other approaches since they're entirely in-process.

    Note that firebase-mock (#1) does cause a webpack error if used as-is from Webpack/web code. To resolve, you can use option #2 (mock-cloud-firestore), or use the workaround mentioned here (until a fix gets merged): https://github.com/soumak77/firebase-mock/issues/157#issuecomment-545387665

    Other options:

    3) Firestore emulator: needs the google-cloud-sdk, and relies on a separate process
    4) Separate test project: relies on connection to the internet, which also means possible quota limitations/costs
    5) firebase-server: Only supports the realtime-database api, not Firestore

提交回复
热议问题