Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

setting for runing test with firebase emulator. #281

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

abejarano
Copy link

No description provided.

Copy link
Owner

@wovalle wovalle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Abejarano. Thanks for the pull request!

I understand the value of having the ability to test with the emulator but I think that executing integration tests with a real database is the best case scenario. I would love the idea to have both scenarios though.

  • How do you fire of the emulator in the first place? Can you add the script in the package.json?
  • Can you update your pull request to accept an env var such as RUN_IN_EMULATOR that would conditionally replace the firestore initialization to support the emulator?

@donnyroufs
Copy link

I did not get it to work with the latest version of firebase yet but with version 8 you can simply do this:

firebase.initializeApp({
    credential: credential.cert(serviceAccount as ServiceAccount),
    databaseURL: `https://${serviceAccount.project_id}.firebaseio.com`,
    projectId: serviceAccount.project_id,
  })

  const db = firebase.firestore()

  db.useEmulator('localhost', 8080)

  fireorm.initialize(db as any, {
    validateModels: true,
    validatorOptions: {
      whitelist: true,
    },
  })

Had to type db as any because of

Argument of type 'firebase.default.firestore.Firestore' is not assignable to parameter of type 'FirebaseFirestore.Firestore'.
Type 'Firestore' is missing the following properties from type 'Firestore': getAll, recursiveDelete, listCollections, bulkWriter, bundlets(2345)

Being able to use emulators for tests and local development is great, so it would definitely be cool if we could get it to work for both v8 (types) and v9 (completely? not sure how to get it to work yet)

@abejarano
Copy link
Author

The code you send works with version 9.1.3 however I will do what @wovalle

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants