Tag: 子过程

编写unit testing使用child_process的节点服务

我有一个节点服务,我使用child_process spwan一个孩子,在我的情况下,孩子是一个C ++二进制文件,需要STDIN和streamSTDOUT。 该服务正在按预期工作,现在我正在尝试使用mocha / chai在服务中编写unit testing,并通过伊斯坦布尔运行testing。 我已经为这些stuufs奠定了基础,但只想获得如何为使用child_process的节点服务编写unit testing的示例。 基于这个例子,我可以尝试为我的服务编写unit testing,并在Instanbul上运行它们来生成覆盖率报告。 服务产生这样的孩子, var spawn = require('child_process').spawn, child = spawn(pathToBinary); child.stdin.write('JSON'); child.stdout.on('data', function (data) { //perform operations here });