Running Firestore local e.g. for testing

maku_at picture maku_at · Oct 4, 2017 · Viewed 14.7k times · Source

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)

Answer

Brian M. Hunt picture Brian M. Hunt · Nov 8, 2018

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: '[email protected]' }
})

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.