简体   繁体   中英

Where does the actual cloud function unit test { firebase-functions-test } run when ran using a test framework?

I would like to know, where does the cloud function unit test run, when ran using a test runner (say mocha or jest )?

npm run test

FYI, I am not running inside any of the firebase emulators

When I run using mocha , it is able to create write to the firestore (I am sure jest will do the same), but I can't see the function names in the logs, which means, the function ran locally inside test runner and wrote to firestore db.

Does that mean the https callable cloud functions can't be called from firebase backend using test runner? I have tried both ways: that is directly calling the functions and wrapping using wrap() method provided by firebase-functions-test library. both times the function ran locally.

direct call:

.....
.....
.....
funcName.run({foo:"bar"}, { auth: { uid: "ABC" } });
.....
.....
.....

using wrap:

.....
.....
.....
const projectConfig = {
  projectId: 'my-project',
  databaseURL: 'https://my-project.firebaseio.com'
};
const test = require('firebase-functions-test')(projectConfig, './service-account-key.json');
wrapped = test.wrap(funcName);
expect(
        wrapped(
            { foo: "bar" },
            { auth: { uid: "ABC" } }
        )
).to.contain('foobar');
.....
.....
.....

Does that mean the https callable cloud functions can't be called from firebase backend using test runner?

The firebase-functions-test framework is designed to run everything locally, so you get predictable and reliable execution without a dependency on some external network connection. It will not run anything remotely.

If you want to run a callable function that's been deployed somewhere, you can write code to invoke it directly using any normal HTTP client library, and onCall protocol information provided in the documentation .

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