【问题标题】:Check if Firebase Emulator is connected from Node scripts检查 Firebase Emulator 是否从 Node 脚本连接
【发布时间】:2022-06-28 09:39:00
【问题描述】:

我正在为我的 Firebase 函数编写单元测试,我想从我的脚本中自动连接函数、身份验证、存储等模拟器,而无需指定我是在本地环境还是开发环境中进行测试。

我有什么方法可以编写脚本来查看 Firebase Emulator 是否从外部节点脚本在我的本地计算机上运行?

例如,有没有一种方法可以让我从节点脚本查看在特定本地端口上运行的进程?

我尝试过使用

import { exec } from "child_process";


const checkEmulator = exec("lsof -i:5000");

(我使用的是 MacOS)

然后使用输出来确定 Firebase Functions Emulator 是否在端口 5000 上运行,但 exec 函数的输出对我来说没有任何意义。

有没有更有效的方法来检查模拟器是否在您的本地机器上运行?

感谢您的帮助!

【问题讨论】:

    标签: firebase google-cloud-functions firebase-tools


    【解决方案1】:

    您可以使用类似 curl 的 HTTP Get 请求:

    curl localhost:4400/emulators

    这将打印出一个 JSON 对象,列出所有正在运行的模拟器。示例:

    {
      "hub":{
        "name": "hub",
        "host": "localhost",
        "port": 4400
      },
      "functions": {
        "name": "functions",
        "host": "localhost",
        "port": 5001
      }
      "firestore": {
        "name": "firestore",
        "host": "localhost",
        "port": 8080
      }
    }
    

    取自https://firebase.google.com/docs/emulator-suite/install_and_configure

    或者,psaux 可以列出活动进程。每个模拟器都是一个不同的进程,从.../.cache/firebase/emulators运行。

    https://www.npmjs.com/package/psaux

    【讨论】:

      猜你喜欢
      • 2019-10-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多