Running Firestore local e.g. for testing

前端 未结 7 919
盖世英雄少女心
盖世英雄少女心 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:20

    Update 2020:

    There's now also a Firebase Emulator Suite.

    Update Nov 2018:

    Local emulation, at least for the purpose of testing Firestore rules, was demoed at Firebase Summit 2018 using @firestore/testing and documented under Test your Cloud Firestore Security Rules.

    It looks like it's along the lines of:

    const firebase = require(`@firebase/testing`)
    const app = firebase.initializeTestApp({
      projectId: 'my-project',
      auth: { uid: '123', email: 'name@domain.com' }
    })
    
    const attempt = app.firestore()
      .collection('colId').doc('docId').get()
    firebase.assertFails(attempt)
    firebase.assertSucceeds(attempt)
    

    It seems early-on, as it's not been noted in the release-notes, but I'm sure it's coming along.

提交回复
热议问题