firebase functions:shell 不模拟调用之间的内存状态

firebase functions:shell does not emulate state of memory between invocations

我正在使用 firebase functions:shell 测试我的 Cloud Functions,发现它似乎无法模拟调用之间的内存状态。

let flag = false;
exports.test = functions.https.onCall(async (data, context) => {
  console.log(flag); // this is still false on second call :-(
  flag = true;
  return true;
});

我知道函数应该是无状态的,但正如文档所说“Cloud Functions 通常会回收先前调用的执行环境。”这在生产中有效。 有人知道是否有办法在本地进行测试吗?

目前没有办法做到这一点。 GitHub 上正在讨论此问题。 You can follow the issue here.