]> git.cworth.org Git - obsolete/notmuch-web/blob - node_modules/express/node_modules/qs/support/expresso/test/serial/http.test.js
Install the "express" node module via npm
[obsolete/notmuch-web] / node_modules / express / node_modules / qs / support / expresso / test / serial / http.test.js
1
2 /**
3  * Module dependencies.
4  */
5
6 var assert = require('assert')
7   , http = require('http');
8
9 var server = http.createServer(function(req, res){
10     if (req.method === 'GET') {
11         if (req.url === '/delay') {
12             setTimeout(function(){
13                 res.writeHead(200, {});
14                 res.end('delayed');
15             }, 200);
16         } else {
17             var body = JSON.stringify({ name: 'tj' });
18             res.writeHead(200, {
19                 'Content-Type': 'application/json; charset=utf8',
20                 'Content-Length': body.length
21             });
22             res.end(body);
23         }
24     } else {
25         var body = '';
26         req.setEncoding('utf8');
27         req.addListener('data', function(chunk){ body += chunk });
28         req.addListener('end', function(){
29             res.writeHead(200, {});
30             res.end(req.url + ' ' + body);
31         });
32     }
33 });
34
35 module.exports = {
36     'test assert.response()': function(done){
37         assert.response(server, {
38             url: '/',
39             method: 'GET'
40         },{
41             body: '{"name":"tj"}',
42             status: 200,
43             headers: {
44                 'Content-Type': 'application/json; charset=utf8'
45             }
46         }, done);
47     }
48 };