Skip to content
Myr

response.test.js

This file

Path

test/response.test.js

230 lines · 7.7 KiB · JavaScript

Last changed by

Added callback support to res.download()Tj Holowaychukbefore adoption6bfa759

History of this file

Take it

The walk stopped after 200 commits: lines older than 5fcf971 point at it.

Fixed reload views exampleTj Holowaychukbefore adoption5fcf971

lines 1–59why, one step back
1
2/**3 * Module dependencies.4 */56var express = require('express'),7 Buffer = require('buffer').Buffer;89module.exports = {10 'test #send()': function(assert){11 var app = express.createServer();1213 app.get('/html', function(req, res){14 res.send('<p>test</p>', { 'Content-Language': 'en' });15 });16 17 app.get('/json', function(req, res){18 res.header('X-Foo', 'bar');19 res.send({ foo: 'bar' }, { 'X-Foo': 'baz' }, 201);20 });21 22 app.get('/text', function(req, res){23 res.header('X-Foo', 'bar');24 res.contentType('.txt');25 res.send('wahoo');26 });27 28 app.get('/status', function(req, res){29 res.send(404);30 });31 32 app.get('/error', function(req, res){33 res.send('Oh shit!', { 'Content-Type': 'text/plain' }, 500);34 });35 36 app.get('/buffer', function(req, res){37 res.send(new Buffer('wahoo!'));38 });3940 assert.response(app,41 { url: '/html' },42 { body: '<p>test</p>', headers: { 'Content-Language': 'en', 'Content-Type': 'text/html; charset=utf-8' }});43 assert.response(app,44 { url: '/json' },45 { body: '{"foo":"bar"}', status: 201, headers: { 'Content-Type': 'application/json', 'X-Foo': 'baz' }});46 assert.response(app,47 { url: '/text' },48 { body: 'wahoo', headers: { 'Content-Type': 'text/plain; charset=utf-8', 'X-Foo': 'bar' }});49 assert.response(app,50 { url: '/status' },51 { body: 'Not Found', status: 404, headers: { 'Content-Type': 'text/plain; charset=utf-8' }});52 assert.response(app,53 { url: '/error' },54 { body: 'Oh shit!', status: 500, headers: { 'Content-Type': 'text/plain' }});55 assert.response(app,56 { url: '/buffer' },57 { body: 'wahoo!', headers: { 'Content-Type': 'application/octet-stream' }});58 },59

Fixed test labelsTj Holowaychukbefore adoption2844b1a

line 60why, one step back
60 'test #contentType()': function(assert){

Fixed reload views exampleTj Holowaychukbefore adoption5fcf971

lines 61–73why, one step back
61 var app = express.createServer();
62 63 app.get('/html', function(req, res){64 res.contentType('index.html');65 res.writeHead(200, res.headers);66 res.end('<p>yay</p>');67 });68 69 assert.response(app,70 { url: '/html' },71 { body: '<p>yay</p>', headers: { 'Content-Type': 'text/html; charset=utf-8' }});72 },73

Fixed test labelsTj Holowaychukbefore adoption2844b1a

line 74why, one step back
74 'test #attachment()': function(assert){

Fixed reload views exampleTj Holowaychukbefore adoption5fcf971

lines 75–81why, one step back
75 var app = express.createServer();
76 77 app.get('/style.css', function(req, res){78 res.attachment();79 res.send('some stylezzz');80 });81

Route callback signature changedTj Holowaychukbefore adoption75661a2

lines 82–83why, one step back
82 app.get('/*', function(req, res){
83 res.attachment(req.params[0]);

Fixed reload views exampleTj Holowaychukbefore adoption5fcf971

lines 84–102why, one step back
84 res.send('whatever');
85 });86 87 assert.response(app,88 { url: '/javascripts/jquery.js' },89 { body: 'whatever', headers: { 'Content-Disposition': 'attachment; filename="jquery.js"' }});90 assert.response(app,91 { url: '/style.css' },92 { body: 'some stylezzz', headers: { 'Content-Disposition': 'attachment' }});93 },94 95 'test #redirect()': function(assert){96 var app = express.createServer(),97 app2 = express.createServer();98 99 app2.set('home', '/blog');100101 app2.redirect('google', 'http://google.com');102

Route callback signature changedTj Holowaychukbefore adoption75661a2

lines 103–105why, one step back
103 app2.redirect('blog', function(req, res){
104 return req.params.id105 ? '/user/' + req.params.id + '/blog'

Fixed reload views exampleTj Holowaychukbefore adoption5fcf971

lines 106–175why, one step back
106 : null;
107 });108 109 app.get('/', function(req, res){110 res.redirect('http://google.com', 301);111 });112 113 app.get('/back', function(req, res){114 res.redirect('back');115 });116 117 app.get('/home', function(req, res){118 res.redirect('home');119 });120 121 app2.get('/', function(req, res){122 res.redirect('http://google.com', 301);123 });124 125 app2.get('/back', function(req, res){126 res.redirect('back');127 });128 129 app2.get('/home', function(req, res){130 res.redirect('home');131 });132 133 app2.get('/google', function(req, res){134 res.redirect('google');135 });136137 app2.get('/user/:id', function(req, res){138 res.redirect('blog');139 });140 141 assert.response(app,142 { url: '/' },143 { body: '', status: 301, headers: { Location: 'http://google.com' }});144 assert.response(app,145 { url: '/back' },146 { body: '', status: 302, headers: { Location: '/' }});147 assert.response(app,148 { url: '/back', headers: { Referer: '/foo' }},149 { body: '', status: 302, headers: { Location: '/foo' }});150 assert.response(app,151 { url: '/back', headers: { Referrer: '/foo' }},152 { body: '', status: 302, headers: { Location: '/foo' }});153 assert.response(app,154 { url: '/home' },155 { body: '', status: 302, headers: { Location: '/' }});156157 assert.response(app2,158 { url: '/' },159 { body: '', status: 301, headers: { Location: 'http://google.com' }});160 assert.response(app2,161 { url: '/back' },162 { body: '', status: 302, headers: { Location: '/blog' }});163 assert.response(app2,164 { url: '/home' },165 { body: '', status: 302, headers: { Location: '/blog' }});166 assert.response(app2,167 { url: '/google' },168 { body: '', headers: { Location: 'http://google.com' }});169 assert.response(app2,170 { url: '/user/12' },171 { body: '', headers: { Location: '/user/12/blog' }});172 },173 174 'test #sendfile()': function(assert){175 var app = express.createServer();

Fixed res.sendfile() error handling, defer via next()Tj Holowaychukbefore adoption8308e50

lines 176–177why, one step back
176
177 app.get('/*', function(req, res, next){

Added callback support for res.sendfile()Tj Holowaychukbefore adoption25909c0

lines 178–181why, one step back
178 var file = req.params[0],
179 filePath = __dirname + '/fixtures/' + file;180 res.sendfile(filePath, function(err, path){181 assert.equal(path, filePath);

Fixed res.sendfile() error handling, defer via next()Tj Holowaychukbefore adoption8308e50

line 182why, one step back
182 if (err) next(err);

Added callback support for res.sendfile()Tj Holowaychukbefore adoption25909c0

line 183why, one step back
183 });

Fixed reload views exampleTj Holowaychukbefore adoption5fcf971

lines 184–185why, one step back
184 });
185

Fixed res.sendfile() error handling, defer via next()Tj Holowaychukbefore adoption8308e50

lines 186–187why, one step back
186 app.use(express.errorHandler());
187

Fixed reload views exampleTj Holowaychukbefore adoption5fcf971

lines 188–195why, one step back
188 assert.response(app,
189 { url: '/user.json' },190 { body: '{"name":"tj"}', status: 200, headers: { 'Content-Type': 'application/json' }});191 assert.response(app,192 { url: '/hello.haml' },193 { body: '%p Hello World', status: 200, headers: { 'Content-Type': 'application/octet-stream' }});194 assert.response(app,195 { url: '/doesNotExist' },

Fixed res.sendfile() error handling, defer via next()Tj Holowaychukbefore adoption8308e50

line 196why, one step back
196 { body: 'Internal Server Error', status: 500 });

Fixed reload views exampleTj Holowaychukbefore adoption5fcf971

lines 197–204why, one step back
197 assert.response(app,
198 { url: '/partials' },199 { body: 'Internal Server Error', status: 500 });200 },201 202 'test #download()': function(assert){203 var app = express.createServer();204

Route callback signature changedTj Holowaychukbefore adoption75661a2

line 205why, one step back
205 app.get('/json', function(req, res, next){

Added callback support to res.download()Tj Holowaychukbefore adoption6bfa759

lines 206–209why, one step back
206 var filePath = __dirname + '/fixtures/user.json';
207 res.download(filePath, 'account.json', function(err, path){208 assert.equal(filePath, path);209 });

Fixed reload views exampleTj Holowaychukbefore adoption5fcf971

lines 210–211why, one step back
210 });
211

Fixed res.download() testTj Holowaychukbefore adoption7af7851

lines 212–213why, one step back
212 app.get('/*', function(req, res, next){
213 res.download(__dirname + '/fixtures/' + req.params[0]);

Fixed reload views exampleTj Holowaychukbefore adoption5fcf971

lines 214–230why, one step back
214 });
215 216 assert.response(app,217 { url: '/user.json' },218 { body: '{"name":"tj"}', status: 200, headers: {219 'Content-Type': 'application/json',220 'Content-Disposition': 'attachment; filename="user.json"'221 }});222223 assert.response(app,224 { url: '/json' },225 { body: '{"name":"tj"}', status: 200, headers: {226 'Content-Type': 'application/json',227 'Content-Disposition': 'attachment; filename="account.json"'228 }});229 }230};