Node.js-启动进程(firebase模拟器)并读取其输出
我想在Jest测试之前启动firebase模拟器 执行此操作,但要按程序执行:Node.js-启动进程(firebase模拟器)并读取其输出,node.js,child-process,Node.js,Child Process,我想在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
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模拟器:exec
命令的原因
假设您使用“npm运行测试”来运行Jest脚本,您将使用:
firebase emulators:exec "npm run test"
这将: