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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Online mode redirected to emulators #76

Open
melchoir55 opened this issue Sep 25, 2020 · 7 comments
Open

Online mode redirected to emulators #76

melchoir55 opened this issue Sep 25, 2020 · 7 comments

Comments

@melchoir55
Copy link

I am attempting to follow the tutorial provided here:
https://firebase.google.com/docs/functions/unit-testing#online-mode

This code block defines where the firebase services are found on the network, as well as what auth creds to use:

// At the top of test/index.test.js
const test = require('firebase-functions-test')({
  databaseURL: 'https://my-project.firebaseio.com',
  storageBucket: 'my-project.appspot.com',
  projectId: 'my-project',
}, 'path/to/serviceAccountKey.json');

We are trying to write our tests to interact with firebase emulator services. For example, we wish for the test suite to interact with our local emulated version of firestore.

We have been banging our heads trying to get this suite to redirect to local services without success. I would sincerely appreciate any guidance.

@itsravenous
Copy link

The firestore emulator runs at http://localhost:8080, so try:

const test = require('firebase-functions-test')({
  databaseURL: 'http://localhost:8080',
  storageBucket: 'my-project.appspot.com', // Emulator doesn't support storage yet
  projectId: 'my-project',
}, 'path/to/serviceAccountKey.json');

And then I think you want to prefix your test command with FIRESTORE_EMULATOR_HOST=localhost:8080 so that Firebase itself knows to connect to the emulator.

With this setup I have successfully written to the local emulated Firestore from a cloud function.

I am, however, having trouble with my specific use case, which is a function triggered by a Firestore onWrite, writing back to the same document that triggered the function. I'll open a separate issue for this.

@inlined
Copy link
Member

inlined commented Jul 14, 2021

This is a very cool feature request, but is definitely not trivial. We'll leave it on the back burner for now, but I don't know that we'll ever get to it.

@Jaimies
Copy link

Jaimies commented Jul 31, 2021

@inlined I would argue that this feature is pretty vital at least to my project. Because you need the service account key, you can't run your tests in CI without exposing your API key to the CI provider. You would also have to store the key in your repository for the same reason, which may not always be optimal (you may not want to share the key with everyone who has access to the project).

@inlined
Copy link
Member

inlined commented Aug 2, 2021

We're working on support for sensitive secrets. That might solve your needs without being this particular feature request. For better or worse, we're busy with some major things coming down the pipeline and they'll all take precedence over this feature request.

@Jaimies
Copy link

Jaimies commented Aug 3, 2021

@inlined No problem, good luck with those!

@FanchenBao
Copy link

I concur that if online mode can be connected to the emulator, that will be great. But I can see that this is not trivial. For one thing, in online mode, the cloud function is not attached to the emulator. This allows debugging on the function code and produce code coverage, for example. But if the function modifies database using the change.after.ref syntax, we cannot figure out a way to test it. As of now, we have to ditch firebase-functions-test and go with full emulation.

@odbol
Copy link

odbol commented Jan 6, 2022

I'm also trying to write tests of my firebase functions, but it's giving me errors because (I'm assuming) it doesn't have admin credentials in the emulator. Is that what this bug is about? Is there a way to emulate admin credentials in FirebaseFunctionsTest() using the emulator?

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

No branches or pull requests

6 participants