sbatson5 / firestore-jest-mock

Jest Helper library for mocking Cloud Firestore
https://www.npmjs.com/package/firestore-jest-mock
178 stars 59 forks source link

feat: support @google-cloud/firestore #72

Closed CorentinDoue closed 3 years ago

CorentinDoue commented 3 years ago

Description

Add support for @google-cloud/firestore mocking. Expose mockGoogleCloudFirestore as mockFirebase.

Related issues

Adresses https://github.com/Upstatement/firestore-jest-mock/issues/71

How to test

  1. Get a project that use @google-cloud/firestore
  2. checkout https://github.com/CorentinDoue/firestore-jest-mock/tree/feat/support-google-cloud-firestore
  3. link firestore-jest-mock to your project
  4. write one test
CorentinDoue commented 3 years ago

Is there no need for the initializeApp call with @google-cloud/firestore? Where does it get your app credentials from?

@google-cloud/firestore use the same interface as the other @google-cloud SDKs. There is no explicit authentication. The SDK will use the GOOGLE_APPLICATION_CREDENTIALS environment variable to locate the credentials and authenticate.

Therefore the classic initialization of the firestore client is only

const firestore = new Firestore({ projectId });

where firestore has the same signature as firebase.firestore()

Would you mind adding a test? It could just be a "sanity" test to make sure you can do a simple query.

I copied the test full-setup.test.js and adapted it to the @google-cloud/firestore signature