You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Create .env file with variable defined OR set via cli when deploying with firebase-tools
FOO="bar"
The above works when deployed.
Now when attempting to write a unit test for the above function, there is no mechanism for loading configuration parameters. The older (no longer recommended method) for defining configuration via functions.config can be mocked as described here.
Expected behavior
firebase-functions-test provides a mechanism for loading "parameterized config" into a test environment similar to mockConfig()
Actual behavior
firebase-functions-test DOES NOT provide any mechanism for loading "parameterized config" into a test environment similar to mockConfig()
The text was updated successfully, but these errors were encountered:
You can simply use a library like dotenv to load your environment config now. As long as the properties are set in process.env, your parameterized config will pick it up.
@wneild 's solution seems to actually be a pretty good workaround until firebase-functions-test support a similar function as mockConfig() for parametrized config.
If someone else is looking for this, I ended up with this:
import*asfftfrom'firebase-functions-test'constprojectConfig={projectId: 'my-project-id',storageBucket: 'my-project-id.appspot.com',}exportconsttestFunctions=fft(projectConfig)// First load .env.localdotenv.config({path: path.resolve(process.cwd(),'.env.local'),})// Then load .env if there are other variables defined. This does not overwrite variables already defined in .env.localdotenv.config({path: path.resolve(process.cwd(),'.env'),})
This makes the parametrized config like defineBoolean('MY_CUSTOM_ENV_VAR') work in tested functions.
How can we make this work with onInit? My module's onInit function, which I'm using as documented here to make parameterized config work, doesn't get called when I run tests.
Version info
firebase-functions-test:
3.0.0
firebase-functions:
4.2.1
firebase-admin:
11.5.0
Steps to reproduce
.env
file with variable defined OR set via cli when deploying with firebase-toolsThe above works when deployed.
Expected behavior
firebase-functions-test
provides a mechanism for loading "parameterized config" into a test environment similar tomockConfig()
Actual behavior
firebase-functions-test
DOES NOT provide any mechanism for loading "parameterized config" into a test environment similar tomockConfig()
The text was updated successfully, but these errors were encountered: