I'd like to run tests that call multiple Cloud Functions in the emulator that make use of a mocked out external service (getstream.io). That means the mock would have to stay around across function invocations. Is something like this possible?
let mock = new SomethingMock();
exports.resetMock = functions.https.onCall((data, context) => {
mock = new SomethingMock();
});
exports.addActivity = functions.https.onCall(async (data, context) => {
await mock.addActivity(something);
});
exports.getActivities = functions.https.onCall((data, context) => {
// assumes addActivity has been called a few times
return mock.getActivities();
});
This page says gives no guarantees about preservation of global state in production, but says nothing about the emulator: https://firebase.google.com/docs/functions/tips#use_global_variables_to_reuse_objects_in_future_invocations