I am using the simple as possible web server straight off of the flatiron website and wanted to experiment testing it with vows. I can get the tests to pass but the test never exits. I assume this is because I the flatiron server never shuts down. How do I shut the server down or there a better way to do simple http tests with another technology?
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);