Spaces:
Sleeping
Sleeping
File size: 1,570 Bytes
05a77ff |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
/*
* simple-test.js: Simple tests for basic streaming and non-streaming HTTP requests with union.
*
* (C) 2011, Charlie Robbins & the Contributors
* MIT LICENSE
*
*/
var assert = require('assert'),
fs = require('fs'),
path = require('path'),
request = require('request'),
vows = require('vows'),
union = require('../lib/index'),
macros = require('./helpers/macros');
var doubleWrite = false,
server;
server = union.createServer({
before: [
function (req, res) {
res.json(200, { 'hello': 'world' });
res.emit('next');
},
function (req, res) {
doubleWrite = true;
res.json(200, { 'hello': 'world' });
res.emit('next');
}
]
});
vows.describe('union/double-write').addBatch({
"When using union": {
"an http server which attempts to write to the response twice": {
topic: function () {
server.listen(9091, this.callback);
},
"a GET request to `/foo`": {
topic: function () {
request({ uri: 'http://localhost:9091/foo' }, this.callback);
},
"it should respond with `{ 'hello': 'world' }`": function (err, res, body) {
macros.assertValidResponse(err, res);
assert.deepEqual(JSON.parse(body), { 'hello': 'world' });
},
"it should not write to the response twice": function () {
assert.isFalse(doubleWrite);
}
}
}
}
}).addBatch({
"When the tests are over": {
"the server should close": function () {
server.close();
}
}
}).export(module);
|