0

I have installed the firebase tools to be able to use the firebase emulator for cloud functions.

Now that I have installed the tools, what I need to do to use the emulator to test a cloud function after I create it locally using vs code?

I just write my code into an index.js file and then run the emulator or there is a special way to proceed?

4
  • 1
    Have you checked run functions locally part of the documentation? It's a single command firebase emulators:start --only functions mostly. Commented Jun 5, 2022 at 16:28
  • ok, but in my code I need to add something to connect with emulator? Commented Jun 5, 2022 at 16:43
  • 1
    The same page explains what additional changes you need to make in your code. In this case, it would be using the connectFunctionsEmulator() function. Commented Jun 5, 2022 at 16:53
  • @Dharmaraj I have node.js code that use require instead of import, not sure if the example can be applied also to node.js Commented Jun 6, 2022 at 18:32

1 Answer 1

1

To test your Cloud Function using the Firebase Emulator Suite and after installing it, you can optionaly make some configurations, but you can also follow these instructions based on this video tutorial as an easy way to start your tests:

  1. firebase init
  2. Select the products you need.
  3. Enter your project ID and other information.
  4. Select Functions emulator.
  5. Select the port to use (it could be the default port 5001 for Cloud Functions).

After setting your Firebase project, now start up your emulator with: firebase emulators:start

There you can view status and logs by clicking at localhost link.

To get details about how to Connect your app to the Cloud Functions Emulator, you can follow this document.

The Emulator Suite is supplemented by other prototype and test tools as Cloud Functions testing tools, which is integrated by:

  1. The Cloud Functions emulator, part of the Emulator Suite.

  2. The Cloud Functions shell, which allows for interactive, iterative functions prototyping and development.

  3. The Firebase Test SDK for Cloud Functions, a Node.js with mocha framework for functions development.

In VS Code, you can easily emulate functions by sending code you want to run to the Firebase CLI, as described at the end of this Doug Stevenson’s post.

This command will run test code from a file redirected through standard input:

$ firebase experimental:functions:shell < tests.js

Sign up to request clarification or add additional context in comments.

2 Comments

Mainly what is described here is for web library not nodejs ?
Yes, at this moment the emulator for Cloud Functions basically works for Web, Android, and Swift, as you can see in this table. Node.js Admin SDK isn’t available at this moment.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.