简体   繁体   中英

How to test cloud function using firebase emulator

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM