问题 运行 带有 firebase 模拟器的 JS 文件:exec

Problem running JS file with firebase emulators: exec

我正在试用新的 Firebase 模拟器 UI announced on May 21, 2020. In the Firebase Docs,我注意到有一个 CLI 命令允许我们 运行一个脚本文件:

firebase emulators:exec scriptpath

Run the script at scriptpath after starting emulators for the Firebase products configured in firebase.json. Emulator processes will automatically stop when the script has finished running.

虽然文档没有提到它应该是什么类型的脚本文件,但我认为它可能是 测试脚本 或可用的 JavaScript 文件 node filename.js 一起独立执行,没有任何错误。这是有道理的,因为我实际上可以 运行 一个初始 JS 文件,该文件将一些测试数据预填充到 Firestore Emulator 以进行进一步测试。

但是由于我之前已经启动了模拟器,所以我必须打开一个新的命令实例 window 到 运行 firebase emulators:exec 命令。不幸的是,我遇到了以下错误:

D:\Firebase\my-project>firebase emulators:exec setup-db.js
i  emulators: Starting emulators: functions, firestore, database, hosting, pubsub
!  hub: emulator hub unable to start on port 4400, starting on 4401 instead.
!  emulators: It seems that you are running multiple instances of the emulator suite for project my-project-id. This may result in unexpected behavior.
i  emulators: Shutting down emulators.
i  hub: Stopping emulator hub
!  functions: Port 5001 is not open on localhost, could not start Functions Emulator.
!  functions: To select a different host/port, specify that host/port in a firebase.json config file:
      {
        // ...
        "emulators": {
          "functions": {
            "host": "HOST",
            "port": "PORT"
          }
        }
      }
i  emulators: Shutting down emulators.

Error: Could not start Functions Emulator, port taken.

记下这一行:

! emulators: It seems that you are running multiple instances of the emulator suite for project my-project-id. This may result in unexpected behavior.

那么,我如何才能 运行 firebase emulators:exec 在模拟器启动后 ,如 Firebase 文档中所述,我可以 运行用于上述目的的 JS 文件?提前致谢!

更新:

如果我 运行 只是 firebase emulators:exec setup-imtp-db.js 而没有事先 运行 宁 firebase emulators:start 命令,我 运行 会出现以下错误:

请注意,setup-imtp-db.js 不包含任何 Cloud Functions 代码,而只是一个独立的 JS 文件,它通过以下方式将来自另一个 JSON 文件的数据填充到 Firestore 中管理软件开发工具包。我正在使用 Node.js 12.14.0firebase-tools 8.4.0.

根据Firebase CLI Github README.md

emulators:exec Start the local Firebase emulators, run a test script, then shut down the emulators.

因此 scriptpath 参数并不真正意味着 运行 一个 JavaScript 文件,该文件在 Firestore 模拟器上预填充数据(并在其模拟器 UI 上显示) 用于 UI 功能测试或集成测试。 emulators:exec 将在执行完测试脚本后立即关闭 模拟器。

正如评论中 @Doug Stevenson 所建议的那样,如果希望模拟器进行适当的错误处理或需要新功能,可以在上发布请求或错误报告Github for firebase-tools