我正在试用新的Firebase模拟器UI 于2020年5月21日宣布。在[消]防火文档中,我注意到有一个CLI命令允许我们运行脚本文件
firebase emulators:exec scriptpath在为在scriptpath中配置的Firebase产品启动模拟器之后,在firebase.json上运行脚本。当脚本完成运行时,模拟器进程将自动停止。
虽然文档没有提到它应该是什么样的脚本文件,但我认为它可以是一个测试脚本,也可以是一个可行的JavaScript文件,可以在node filename.js中独立执行,不会出现任何错误。这是有意义的,因为我实际上可以运行一个初始的JS文件,该文件预先将一些测试数据填充到Fi还原仿真程序以供进一步测试。
但是由于我以前已经启动了模拟器,所以我必须打开一个新的命令窗口实例来运行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 Docs中提到的firebase emulators:exec 之后,我如何运行,是否可以为此目的运行JS文件呢?提前感谢!
更新:
如果我只运行firebase emulators:exec setup-imtp-db.js而不运行firebase emulators:start命令,则会遇到以下错误:

请注意,setup-imtp-db.js不包含任何云函数代码,而是一个独立的JS文件,它通过Admin将来自另一个JSON文件的数据填充到Firestore中。我正在使用Node.js 12.14.0和firebase-tools 8.4.0。
发布于 2020-05-24 01:58:53
emulators:exec启动本地Firebase模拟器,运行测试脚本,然后关闭仿真程序。
因此,scriptpath参数实际上并不意味着要运行一个JavaScript文件,该文件为UI功能测试或集成测试的目的预先填充Fi还原模拟器上的数据(并显示在其仿真程序UI上)。emulators:exec将在完成测试脚本后立即关闭模拟器。
正如@Doug 在评论中所建议的那样,如果需要从模拟器中进行适当的错误处理,或者需要一个新特性,则可以在用于防火的Github -工具上发布请求或bug报告。
https://stackoverflow.com/questions/61972931
复制相似问题