testingchild_process.exec导致flakeytesting…为什么?

Flakeytesting

我正在编写一个黄瓜世界模块的unit testing。 该模块似乎正在工作,它作为一个child_process启动快速应用程序,并通过杀死subprocess停止应用程序。

问题是这个模块的摩卡testing是flakey,它每隔一段时间都会通过,而且每隔一段时间都会失败。 我似乎无法弄清楚为什么。

我怎样才能为每一次通过的世界文件写一个testing?

黄瓜世界文件

var zombie = require('zombie'); var cp = require('child_process'); var World = function World(callback) { this.browser = new zombie(); callback(this); }; World.prototype.start = function (callback) { console.log("Starting Express App"); this.app = cp.exec('node ./bin/www'); console.log("Express App Started"); if (callback) callback(); }; World.prototype.stop = function (callback) { this.app.on('close', function () { console.log("Stopped Express App"); if (callback) callback(); }); this.app.kill('SIGHUP'); }; World.prototype.visit = function (url, callback) { this.browser.visit(url, callback); }; module.exports = World; 

世界模块的Flakeytesting

 var assert = require('assert'), http = require('http'), World = require('../features/support/world'); describe("Cucumber World", function () { var world; beforeEach(function(done) { world = new World(function (world) { world.start(done); }); }); it('should start the web app', function (done) { http.get("http://localhost:3000", function (res) { assert.ok(res, "A successful response was made"); assert.equal(res.statusCode, 200, "200 success status received"); world.stop(done); }); }); });