Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running Firestore local e.g. for testing

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)

like image 619
maku_at Avatar asked Oct 04 '17 11:10

maku_at


People also ask

Can I run Firebase locally?

You can run functions locally to test them before deploying to production.


2 Answers

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.

like image 198
Brian M. Hunt Avatar answered Sep 29 '22 22:09

Brian M. Hunt


There is not currently, but stay tuned as it's something we want to provide.

In the meantime we suggest uses a separate testing project to cover this. The daily free tier per project helps with this too.

like image 22
Dan McGrath Avatar answered Sep 29 '22 23:09

Dan McGrath