PageRenderTime 38ms CodeModel.GetById 25ms app.highlight 8ms RepoModel.GetById 2ms app.codeStats 0ms

/js/lib/Socket.IO-node/support/expresso/test/serial/http.test.js

http://github.com/onedayitwillmake/RealtimeMultiplayerNodeJs
JavaScript | 48 lines | 41 code | 4 blank | 3 comment | 4 complexity | e6170650a1737ac3fb79250a12af7d3a MD5 | raw file
 1
 2/**
 3 * Module dependencies.
 4 */
 5
 6var assert = require('assert')
 7  , http = require('http');
 8
 9var 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
35module.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};