PageRenderTime 52ms CodeModel.GetById 23ms RepoModel.GetById 1ms 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
Possible License(s): GPL-2.0, LGPL-2.1, MPL-2.0-no-copyleft-exception, BSD-3-Clause
  1. /**
  2. * Module dependencies.
  3. */
  4. var assert = require('assert')
  5. , http = require('http');
  6. var server = http.createServer(function(req, res){
  7. if (req.method === 'GET') {
  8. if (req.url === '/delay') {
  9. setTimeout(function(){
  10. res.writeHead(200, {});
  11. res.end('delayed');
  12. }, 200);
  13. } else {
  14. var body = JSON.stringify({ name: 'tj' });
  15. res.writeHead(200, {
  16. 'Content-Type': 'application/json; charset=utf8',
  17. 'Content-Length': body.length
  18. });
  19. res.end(body);
  20. }
  21. } else {
  22. var body = '';
  23. req.setEncoding('utf8');
  24. req.addListener('data', function(chunk){ body += chunk });
  25. req.addListener('end', function(){
  26. res.writeHead(200, {});
  27. res.end(req.url + ' ' + body);
  28. });
  29. }
  30. });
  31. module.exports = {
  32. 'test assert.response()': function(done){
  33. assert.response(server, {
  34. url: '/',
  35. method: 'GET'
  36. },{
  37. body: '{"name":"tj"}',
  38. status: 200,
  39. headers: {
  40. 'Content-Type': 'application/json; charset=utf8'
  41. }
  42. }, done);
  43. }
  44. };