我想在 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"
这会:
- 启动模拟器并等待它们准备好
- 运行您的脚本(
npm run test
在这种情况下)
- 等待脚本退出
- 干净地关闭模拟器
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)