X-Git-Url: https://git.cworth.org/git?p=obsolete%2Fnotmuch-web;a=blobdiff_plain;f=node_modules%2Fexpress%2Fnode_modules%2Fqs%2Fsupport%2Fexpresso%2Ftest%2Fhttp.test.js;fp=node_modules%2Fexpress%2Fnode_modules%2Fqs%2Fsupport%2Fexpresso%2Ftest%2Fhttp.test.js;h=1f9d249166fc383cb72966f5925becbfdd88aaa4;hp=0000000000000000000000000000000000000000;hb=410c776334299b52b7df74c53dafe761ad51cf0d;hpb=df790f70fe96623e5d2469daedaf7114bde13426 diff --git a/node_modules/express/node_modules/qs/support/expresso/test/http.test.js b/node_modules/express/node_modules/qs/support/expresso/test/http.test.js new file mode 100644 index 0000000..1f9d249 --- /dev/null +++ b/node_modules/express/node_modules/qs/support/expresso/test/http.test.js @@ -0,0 +1,146 @@ + +/** + * Module dependencies. + */ + +var assert = require('assert') + , http = require('http'); + +var server = http.createServer(function(req, res){ + if (req.method === 'GET') { + if (req.url === '/delay') { + setTimeout(function(){ + res.writeHead(200, {}); + res.end('delayed'); + }, 200); + } else { + var body = JSON.stringify({ name: 'tj' }); + res.writeHead(200, { + 'Content-Type': 'application/json; charset=utf8', + 'Content-Length': body.length + }); + res.end(body); + } + } else { + var body = ''; + req.setEncoding('utf8'); + req.on('data', function(chunk){ body += chunk }); + req.on('end', function(){ + res.writeHead(200, {}); + res.end(req.url + ' ' + body); + }); + } +}); + +var delayedServer = http.createServer(function(req, res){ + res.writeHead(200); + res.end('it worked'); +}); + +var oldListen = delayedServer.listen; +delayedServer.listen = function(){ + var args = arguments; + setTimeout(function(){ + oldListen.apply(delayedServer, args); + }, 100); +}; + +module.exports = { + 'test assert.response(req, res, fn)': function(beforeExit){ + var calls = 0; + + assert.response(server, { + url: '/', + method: 'GET' + },{ + body: '{"name":"tj"}', + status: 200, + headers: { + 'Content-Type': 'application/json; charset=utf8' + } + }, function(res){ + ++calls; + assert.ok(res); + }); + + beforeExit(function(){ + assert.equal(1, calls); + }) + }, + + 'test assert.response(req, fn)': function(beforeExit){ + var calls = 0; + + assert.response(server, { + url: '/foo' + }, function(res){ + ++calls; + assert.ok(res.body.indexOf('tj') >= 0, 'Test assert.response() callback'); + }); + + beforeExit(function(){ + assert.equal(1, calls); + }); + }, + + 'test assert.response() delay': function(beforeExit){ + var calls = 0; + + assert.response(server, + { url: '/delay', timeout: 1500 }, + { body: 'delayed' }, + function(){ + ++calls; + }); + + beforeExit(function(){ + assert.equal(1, calls); + }); + }, + + 'test assert.response() regexp': function(beforeExit){ + var calls = 0; + + assert.response(server, + { url: '/foo', method: 'POST', data: 'foobar' }, + { body: /^\/foo foo(bar)?/ }, + function(){ + ++calls; + }); + + beforeExit(function(){ + assert.equal(1, calls); + }); + }, + + 'test assert.response() regexp headers': function(beforeExit){ + var calls = 0; + + assert.response(server, + { url: '/' }, + { body: '{"name":"tj"}', headers: { 'Content-Type': /^application\/json/ } }, + function(){ + ++calls; + }); + + beforeExit(function(){ + assert.equal(1, calls); + }); + }, + + // [!] if this test doesn't pass, an uncaught ECONNREFUSED will display + 'test assert.response() with deferred listen()': function(beforeExit){ + var calls = 0; + + assert.response(delayedServer, + { url: '/' }, + { body: 'it worked' }, + function(){ + ++calls; + }); + + beforeExit(function(){ + assert.equal(1, calls); + }); + } +};