I am using
- Node 14
- firebase functions-test: 0.2.3
- firebase-admin: 9.6.0
- firebase-functions: 3.13.2
- firebase tools: 9.10.0
- mocha: 8.3.2,
- ts-node: 9.1.1
if I run firebase emulators:start
then I will expect process.env will have properties like
"FUNCTIONS_EMULATOR": "true",
"FIRESTORE_EMULATOR_HOST": "localhost:8080"
now I need to create testing for my cloud function using mocha, I will test it using Firestore and functions emulator, I give my file name events_cron_job.test.ts
after I run the simulator, I try to console log those values and I got undefined like this
I expect
console.log(process.env.FUNCTIONS_EMULATOR) // will be "true"
console.log(process.env.FIRESTORE_EMULATOR_HOST) // will be "localhost:8080"
I think this is only happen in test environment ( I am using mocha ), I have regular http triggers and it works as expected
before running the emulator, I try to execute this on terminal
export FIRESTORE_EMULATOR_HOST="localhost:8080"
export FUNCTIONS_EMULATOR="true"
and then execute firebase emulators:start , but the result will be the same, I still get undefined for those values
because those values are undefined, then if my laptop is disconnected from the internet, then this testing will not run ( i.e it will only access the data in production server, not the emulator! ), I expect the test will still run even if there is no internet connection since I use emulator.
I run the mocha test using
mocha -r ts-node/register src/tests/cloud_function_tests --recursive --extension .test.ts --timeout 60000 --exit
