Running Firestore local, for example. for testing

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

What will be the approach to writing tests against the database (except for using mocks)

+15
source share
4 answers

Not at the moment, but stay tuned for how we want to provide this.

In the meantime, we suggest using a separate testing project to cover this. A daily free tier for each project also helps.

+15
source

2018 .: , , Firestore, Firebase Summit 2018 @firestore/testing " Firestore".

:

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)

, , , , .

+7

firestore js test.js

var data = {
        value: {createTime: new Date(),
                updateTime: new Date(),
                fields:{

                        name:{stringValue:'new value data'},
                        age:{integerValue:50}
                      }
        },
        oldValue: {createTime: new Date(),  //old create time
                updateTime: new Date(),  //old update time time
                fields:{

                        name:{stringValue:'olvalue data'},
                        age:{integerValue:50}
                      }
        }
      };
testFireStoreEvent(data);

firebase experimental:functions:shell < test.js

UPDATE!!!!

var data = {
    before: {  
          //your before data

    },
    after: {

        //your after data
     }
  };
testFireStoreEvent(data);
+2

Firestore, :

gcloud beta emulators firestore start

FIRESTORE_EMULATOR_HOST FIRESTORE_EMULATOR_HOST (, export FIRESTORE_EMULATOR_HOST=::1:8505).

This requires the Google Cloud SDK and Java 8+ JRE to be installed on your PATH system as well.

0
source

Source: https://habr.com/ru/post/1686873/


All Articles