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)
You can run functions locally to test them before deploying to production.
There's now also a Firebase Emulator Suite.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With