Skip to content

setting for runing test with firebase emulator.#281

Open
abejarano wants to merge 1 commit intowovalle:masterfrom
abejarano:feature/run-test-with-firebase-emulator
Open

setting for runing test with firebase emulator.#281
abejarano wants to merge 1 commit intowovalle:masterfrom
abejarano:feature/run-test-with-firebase-emulator

Conversation

@abejarano
Copy link
Copy Markdown

No description provided.

Copy link
Copy Markdown
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
Copy Markdown

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
Copy Markdown
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.

3 participants