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');
.....
.....
.....
CodePudding user response:
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.