firebase-tools icon indicating copy to clipboard operation
firebase-tools copied to clipboard

`process.env.FUNCTIONS_EMULATOR` is not defined when using `firebase emulators:exec`

Open sceee opened this issue 3 years ago • 0 comments

[REQUIRED] Environment info

firebase-tools: 11.6.0

Platform: Windows, Ubuntu, Mac

[REQUIRED] Test case

Have a Callable Cloud Function and call

functions.logger.info(`Functions Emulator: ${process.env.FUNCTIONS_EMULATOR}`)

within this cloud function.

[REQUIRED] Steps to reproduce

  1. Run the Cloud Functions emulator using firebase emulators:start => The log from the test case will output Functions Emulator: true.
  2. Have a test case that calls this Callable Cloud Function via firebase-functions-test fft(..). Run the test in emulator using firebase emulators:exec \"npm test\" => The log from the test case will output Functions Emulator: undefined.

[REQUIRED] Expected behavior

process.env.FUNCTIONS_EMULATOR is also "true" if tests testing the functions are executed using firebase emulators:exec.

This is important as that's the only way we can detect whether we are running in the emulator and allows to add some exceptions for tests runs. Currently with this behavior, executions differ between "running" the emulators (via firebase emulators:start) and executing tests directly using firebase emulators:exec ....

[REQUIRED] Actual behavior

See above, when running function tests using firebase emulators:exec, process.env.FUNCTIONS_EMULATOR is not defined.

sceee avatar Aug 12 '22 12:08 sceee