gpt4 book ai didi

Node.js - 启动进程(firebase 模拟器)并读取其输出

转载 作者:太空宇宙 更新时间:2023-11-03 23:47:59 32 4
gpt4 key购买 nike

我想在 Jest 测试之前启动 firebase 模拟器。

以编程方式执行此操作:

E:\my-projct>firebase emulators:start --only firestore
i emulators: Starting emulators: firestore
i firestore: Serving ALL traffic (including WebChannel) on http://localhost:8080
! firestore: Support for WebChannel on a separate port (8081) is DEPRECATED and will go away soon. Please use port above instead.
i firestore: Emulator logging to firestore-debug.log
+ firestore: Emulator started at http://localhost:8080
i firestore: For testing set FIRESTORE_EMULATOR_HOST=localhost:8080
+ All emulators started, it is now safe to connect.

因此,我需要:

  • 执行命令

  • 等待“所有模拟器已启动”字符串出现。

如何读取输出?

我尝试了以下方法,它打印的只是换行符。

const cp = require('child_process');
const child = cp.exec('firebase emulators:start --only firestore');
child.stdout.addListener('data', data => console.log(data.toString()));

最佳答案

这正是我们创建 firebase emulators:exec 命令的原因。

假设您使用“npm run test”来运行 Jest 脚本,您将使用:

firebase emulators:exec "npm run test"

这将:

  1. 启动模拟器并等待它们准备就绪
  2. 运行脚本(在本例中为npm run test)
  3. 等待脚本退出
  4. 彻底关闭模拟器

关于Node.js - 启动进程(firebase 模拟器)并读取其输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60335186/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com