【发布时间】:2012-12-31 23:34:18
【问题描述】:
我正在使用flatiron 网站上的尽可能简单的网络服务器,并想用誓言来测试它。我可以让测试通过,但测试永远不会退出。我认为这是因为我的熨斗服务器从不关闭。如何关闭服务器或有更好的方法使用另一种技术进行简单的 http 测试?
server.js
var flatiron = require('flatiron'),
app = flatiron.app;
app.use(flatiron.plugins.http);
app.router.get('/', function () {
this.res.writeHead(200, { 'Content-Type': 'text/plain' });
this.res.end('Hello world!\n');
});
app.start(8000);
server-test.js
var request = require('request'),
vows = require('vows'),
assert = require('assert');
vows.describe('Hello World').addBatch({
"A GET to /": {
topic: function () {
server = require('../server');
request({
uri: 'http://localhost:8000',
method: 'GET'
}, this.callback)
},
"should respond with 200": function (error, response, body) {
assert.equal("Hello world!\n", body);
},
teardown: function (topic) {
// *********************************
// Do something to shutdown flatiron
// *********************************
}
}
}).export(module);
【问题讨论】:
标签: vows flatiron.js