base project
This commit is contained in:
37
node_modules/union/test/after-test.js
generated
vendored
Normal file
37
node_modules/union/test/after-test.js
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
var assert = require('assert'),
|
||||
vows = require('vows'),
|
||||
request = require('request'),
|
||||
union = require('../');
|
||||
|
||||
function stream_callback(cb) {
|
||||
return function () {
|
||||
var stream = new union.ResponseStream();
|
||||
|
||||
stream.once("pipe", function (req) {
|
||||
return cb ? cb(null,req) : undefined;
|
||||
});
|
||||
|
||||
return stream;
|
||||
};
|
||||
}
|
||||
|
||||
vows.describe('union/after').addBatch({
|
||||
'When using `union`': {
|
||||
'a union server with after middleware': {
|
||||
topic: function () {
|
||||
var self = this;
|
||||
|
||||
union.createServer({
|
||||
after: [ stream_callback(), stream_callback(self.callback) ]
|
||||
}).listen(9000, function () {
|
||||
request.get('http://localhost:9000');
|
||||
});
|
||||
},
|
||||
'should preserve the request until the last call': function (req) {
|
||||
assert.equal(req.req.httpVersion, '1.1');
|
||||
assert.equal(req.req.url, '/');
|
||||
assert.equal(req.req.method, 'GET');
|
||||
}
|
||||
}
|
||||
}
|
||||
}).export(module);
|
50
node_modules/union/test/body-parser-test.js
generated
vendored
Normal file
50
node_modules/union/test/body-parser-test.js
generated
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* 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'),
|
||||
connect = require('connect'),
|
||||
request = require('request'),
|
||||
vows = require('vows'),
|
||||
union = require('../');
|
||||
|
||||
vows.describe('union/body-parser').addBatch({
|
||||
"When using union with connect body parsing via urlencoded() or json()": {
|
||||
topic: function () {
|
||||
union.createServer({
|
||||
buffer: false,
|
||||
before: [
|
||||
connect.urlencoded(),
|
||||
connect.json(),
|
||||
function (req, res) {
|
||||
res.end(JSON.stringify(req.body, true, 2));
|
||||
}
|
||||
]
|
||||
}).listen(8082, this.callback);
|
||||
},
|
||||
"a request to /": {
|
||||
topic: function () {
|
||||
request.post({
|
||||
uri: 'http://localhost:8082/',
|
||||
headers: {
|
||||
'content-type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({ a: "foo", b: "bar" })
|
||||
}, this.callback);
|
||||
},
|
||||
"should respond with a body-decoded object": function (err, res, body) {
|
||||
assert.isNull(err);
|
||||
assert.equal(res.statusCode, 200);
|
||||
assert.deepEqual(
|
||||
JSON.parse(body),
|
||||
{ a: 'foo', b: 'bar' }
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}).export(module);
|
||||
|
62
node_modules/union/test/double-write-test.js
generated
vendored
Normal file
62
node_modules/union/test/double-write-test.js
generated
vendored
Normal file
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* 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);
|
||||
|
44
node_modules/union/test/ecstatic-test.js
generated
vendored
Normal file
44
node_modules/union/test/ecstatic-test.js
generated
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 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'),
|
||||
ecstatic = require('ecstatic')(__dirname + '/fixtures/static'),
|
||||
request = require('request'),
|
||||
vows = require('vows'),
|
||||
union = require('../');
|
||||
|
||||
vows.describe('union/ecstatic').addBatch({
|
||||
"When using union with ecstatic": {
|
||||
topic: function () {
|
||||
union.createServer({
|
||||
before: [
|
||||
ecstatic
|
||||
]
|
||||
}).listen(18082, this.callback);
|
||||
},
|
||||
"a request to /some-file.txt": {
|
||||
topic: function () {
|
||||
request({ uri: 'http://localhost:18082/some-file.txt' }, this.callback);
|
||||
},
|
||||
"should respond with `hello world`": function (err, res, body) {
|
||||
assert.isNull(err);
|
||||
assert.equal(body, 'hello world\n');
|
||||
}
|
||||
},
|
||||
"a request to /404.txt (which does not exist)": {
|
||||
topic: function () {
|
||||
request({ uri: 'http://localhost:18082/404.txt' }, this.callback);
|
||||
},
|
||||
"should respond with 404 status code": function (err, res, body) {
|
||||
assert.isNull(err);
|
||||
assert.equal(res.statusCode, 404);
|
||||
}
|
||||
}
|
||||
}
|
||||
}).export(module);
|
||||
|
0
node_modules/union/test/fixtures/index.js
generated
vendored
Normal file
0
node_modules/union/test/fixtures/index.js
generated
vendored
Normal file
1
node_modules/union/test/fixtures/static/some-file.txt
generated
vendored
Normal file
1
node_modules/union/test/fixtures/static/some-file.txt
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
hello world
|
36
node_modules/union/test/header-test.js
generated
vendored
Normal file
36
node_modules/union/test/header-test.js
generated
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
// var assert = require('assert'),
|
||||
// request = require('request'),
|
||||
// vows = require('vows'),
|
||||
// union = require('../');
|
||||
|
||||
// vows.describe('union/header').addBatch({
|
||||
// 'When using `union`': {
|
||||
// 'with a server that responds with a header': {
|
||||
// topic: function () {
|
||||
// var callback = this.callback;
|
||||
// var server = union.createServer({
|
||||
// before: [
|
||||
// function (req, res) {
|
||||
// res.on('header', function () {
|
||||
// callback(null, res);
|
||||
// });
|
||||
// res.writeHead(200, { 'content-type': 'text' });
|
||||
// res.end();
|
||||
// }
|
||||
// ]
|
||||
// });
|
||||
// server.listen(9092, function () {
|
||||
// request('http://localhost:9092/');
|
||||
// });
|
||||
// },
|
||||
// 'it should have proper `headerSent` set': function (err, res) {
|
||||
// assert.isNull(err);
|
||||
// assert.isTrue(res.headerSent);
|
||||
// },
|
||||
// 'it should have proper `_emittedHeader` set': function (err, res) {
|
||||
// assert.isNull(err);
|
||||
// assert.isTrue(res._emittedHeader);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }).export(module);
|
0
node_modules/union/test/helpers/index.js
generated
vendored
Normal file
0
node_modules/union/test/helpers/index.js
generated
vendored
Normal file
17
node_modules/union/test/helpers/macros.js
generated
vendored
Normal file
17
node_modules/union/test/helpers/macros.js
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* macros.js: Simple test macros
|
||||
*
|
||||
* (C) 2011, Charlie Robbins & the Contributors
|
||||
* MIT LICENSE
|
||||
*
|
||||
*/
|
||||
|
||||
var assert = require('assert');
|
||||
|
||||
var macros = exports;
|
||||
|
||||
macros.assertValidResponse = function (err, res) {
|
||||
assert.isTrue(!err);
|
||||
assert.equal(res.statusCode, 200);
|
||||
};
|
||||
|
45
node_modules/union/test/prop-test.js
generated
vendored
Normal file
45
node_modules/union/test/prop-test.js
generated
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
var assert = require('assert'),
|
||||
request = require('request'),
|
||||
vows = require('vows'),
|
||||
union = require('../');
|
||||
|
||||
vows.describe('union/properties').addBatch({
|
||||
'When using `union`': {
|
||||
'with a server that responds to requests': {
|
||||
topic: function () {
|
||||
var callback = this.callback;
|
||||
var server = union.createServer({
|
||||
before: [
|
||||
function (req, res) {
|
||||
callback(null, req, res);
|
||||
|
||||
res.writeHead(200, { 'content-type': 'text' });
|
||||
res.end();
|
||||
}
|
||||
]
|
||||
});
|
||||
server.listen(9092, function () {
|
||||
request('http://localhost:9092/');
|
||||
});
|
||||
},
|
||||
'the `req` should have a proper `httpVersion` set': function (err, req) {
|
||||
assert.isNull(err);
|
||||
assert.equal(req.httpVersion, '1.1');
|
||||
},
|
||||
'the `req` should have a proper `httpVersionMajor` set': function (err, req) {
|
||||
assert.isNull(err);
|
||||
assert.equal(req.httpVersionMajor, 1);
|
||||
},
|
||||
'the `req` should have a proper `httpVersionMinor` set': function (err, req) {
|
||||
assert.isNull(err);
|
||||
assert.equal(req.httpVersionMinor, 1);
|
||||
},
|
||||
'the `req` should have proper `socket` reference set': function (err, req) {
|
||||
var net = require('net');
|
||||
|
||||
assert.isNull(err);
|
||||
assert.isTrue(req.socket instanceof net.Socket);
|
||||
}
|
||||
}
|
||||
}
|
||||
}).export(module);
|
97
node_modules/union/test/simple-test.js
generated
vendored
Normal file
97
node_modules/union/test/simple-test.js
generated
vendored
Normal file
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* 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'),
|
||||
spawn = require('child_process').spawn,
|
||||
request = require('request'),
|
||||
vows = require('vows'),
|
||||
macros = require('./helpers/macros');
|
||||
|
||||
var examplesDir = path.join(__dirname, '..', 'examples', 'simple'),
|
||||
simpleScript = path.join(examplesDir, 'simple.js'),
|
||||
pkg = JSON.parse(fs.readFileSync(path.join(__dirname, '..', 'package.json'), 'utf8')),
|
||||
fooURI = 'http://localhost:9090/foo',
|
||||
server;
|
||||
|
||||
vows.describe('union/simple').addBatch({
|
||||
"When using union": {
|
||||
"a simple http server": {
|
||||
topic: function () {
|
||||
server = spawn(process.argv[0], [simpleScript]);
|
||||
server.stdout.on('data', this.callback.bind(this, null));
|
||||
},
|
||||
"a GET request to `/foo`": {
|
||||
topic: function () {
|
||||
request({ uri: fooURI }, this.callback);
|
||||
},
|
||||
"it should respond with `hello world`": function (err, res, body) {
|
||||
macros.assertValidResponse(err, res);
|
||||
assert.equal(body, 'hello world\n');
|
||||
},
|
||||
"it should respond with 'x-powered-by': 'union <version>'": function (err, res, body) {
|
||||
assert.isNull(err);
|
||||
assert.equal(res.headers['x-powered-by'], 'union ' + pkg.version);
|
||||
}
|
||||
},
|
||||
"a POST request to `/foo`": {
|
||||
topic: function () {
|
||||
request.post({ uri: fooURI }, this.callback);
|
||||
},
|
||||
"it should respond with `wrote to a stream!`": function (err, res, body) {
|
||||
macros.assertValidResponse(err, res);
|
||||
assert.equal(body, 'wrote to a stream!');
|
||||
}
|
||||
},
|
||||
"a GET request to `/redirect`": {
|
||||
topic: function () {
|
||||
request.get({
|
||||
url: 'http://localhost:9090/redirect',
|
||||
followRedirect: false
|
||||
}, this.callback);
|
||||
},
|
||||
"it should redirect to `http://www.google.com`": function (err, res, body) {
|
||||
assert.equal(res.statusCode, 302);
|
||||
assert.equal(res.headers.location, "http://www.google.com");
|
||||
}
|
||||
},
|
||||
"a GET request to `/custom_redirect`": {
|
||||
topic: function () {
|
||||
request.get({
|
||||
url: 'http://localhost:9090/custom_redirect',
|
||||
followRedirect: false
|
||||
}, this.callback);
|
||||
},
|
||||
"it should redirect to `/foo`": function (err, res, body) {
|
||||
assert.equal(res.statusCode, 301);
|
||||
assert.equal(res.headers.location, "http://localhost:9090/foo");
|
||||
}
|
||||
},
|
||||
"a GET request to `/async`": {
|
||||
topic: function () {
|
||||
request.get({
|
||||
url: 'http://localhost:9090/async',
|
||||
timeout: 500
|
||||
}, this.callback);
|
||||
},
|
||||
"it should not timeout": function (err, res, body) {
|
||||
assert.ifError(err);
|
||||
assert.equal(res.statusCode, 200);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}).addBatch({
|
||||
"When the tests are over": {
|
||||
"the server should close": function () {
|
||||
server.kill();
|
||||
}
|
||||
}
|
||||
}).export(module);
|
||||
|
31
node_modules/union/test/status-code-test.js
generated
vendored
Normal file
31
node_modules/union/test/status-code-test.js
generated
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
var assert = require('assert'),
|
||||
request = require('request'),
|
||||
vows = require('vows'),
|
||||
union = require('../');
|
||||
|
||||
vows.describe('union/status-code').addBatch({
|
||||
'When using `union`': {
|
||||
'with a server setting `res.statusCode`': {
|
||||
topic: function () {
|
||||
var server = union.createServer({
|
||||
before: [
|
||||
function (req, res) {
|
||||
res.statusCode = 404;
|
||||
res.end();
|
||||
}
|
||||
]
|
||||
});
|
||||
server.listen(9091, this.callback);
|
||||
},
|
||||
'and sending a request': {
|
||||
topic: function () {
|
||||
request('http://localhost:9091/', this.callback);
|
||||
},
|
||||
'it should have proper `statusCode` set': function (err, res, body) {
|
||||
assert.isTrue(!err);
|
||||
assert.equal(res.statusCode, 404);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}).export(module);
|
68
node_modules/union/test/streaming-test.js
generated
vendored
Normal file
68
node_modules/union/test/streaming-test.js
generated
vendored
Normal file
@@ -0,0 +1,68 @@
|
||||
var assert = require('assert'),
|
||||
fs = require('fs'),
|
||||
path = require('path'),
|
||||
request = require('request'),
|
||||
vows = require('vows'),
|
||||
union = require('../');
|
||||
|
||||
vows.describe('union/streaming').addBatch({
|
||||
'When using `union`': {
|
||||
'a simple union server': {
|
||||
topic: function () {
|
||||
var self = this;
|
||||
|
||||
union.createServer({
|
||||
buffer: false,
|
||||
before: [
|
||||
function (req, res, next) {
|
||||
var chunks = '';
|
||||
|
||||
req.on('data', function (chunk) {
|
||||
chunks += chunk;
|
||||
});
|
||||
|
||||
req.on('end', function () {
|
||||
self.callback(null, chunks);
|
||||
});
|
||||
}
|
||||
]
|
||||
}).listen(9000, function () {
|
||||
request.post('http://localhost:9000').write('hello world');
|
||||
});
|
||||
},
|
||||
'should receive complete POST data': function (chunks) {
|
||||
assert.equal(chunks, 'hello world');
|
||||
}
|
||||
},
|
||||
"a simple pipe to a file": {
|
||||
topic: function () {
|
||||
var self = this;
|
||||
|
||||
union.createServer({
|
||||
before: [
|
||||
function (req, res, next) {
|
||||
var filename = path.join(__dirname, 'fixtures', 'pipe-write-test.txt'),
|
||||
writeStream = fs.createWriteStream(filename);
|
||||
|
||||
req.pipe(writeStream);
|
||||
writeStream.on('close', function () {
|
||||
res.writeHead(200);
|
||||
fs.createReadStream(filename).pipe(res);
|
||||
});
|
||||
}
|
||||
]
|
||||
}).listen(9044, function () {
|
||||
request({
|
||||
method: 'POST',
|
||||
uri: 'http://localhost:9044',
|
||||
body: 'hello world'
|
||||
}, self.callback);
|
||||
});
|
||||
},
|
||||
'should receive complete POST data': function (err, res, body) {
|
||||
assert.equal(body, 'hello world');
|
||||
}
|
||||
}
|
||||
}
|
||||
}).export(module);
|
||||
|
Reference in New Issue
Block a user