response.test.js
This file
Path
test/response.test.js
221 lines · 7.4 KiB · JavaScript
Last changed by
Test prefixesTj Holowaychukbefore adoption2ec4a8b
History of this fileTake it
The walk stopped after 200 commits: lines older than 774e25d point at it.
Added `make install-support` and `make uninstall-support`Tj Holowaychukbefore adoption774e25d
lines 1–5why, one step back12/**3 * Module dependencies.4 */5Added buffer support to res.send()Tj Holowaychukbefore adoption14280df
lines 6–7why, one step back6var express = require('express'),7 Buffer = require('buffer').Buffer;Added `make install-support` and `make uninstall-support`Tj Holowaychukbefore adoption774e25d
lines 8–9why, one step back89module.exports = {Test prefixesTj Holowaychukbefore adoption2ec4a8b
line 10why, one step back10 'test #send()': function(assert){Added `make install-support` and `make uninstall-support`Tj Holowaychukbefore adoption774e25d
lines 11–17why, one step back11 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){req.send() headers take precedenceTj Holowaychukbefore adoption0d4b57d
lines 18–19why, one step back18 res.header('X-Foo', 'bar');19 res.send({ foo: 'bar' }, { 'X-Foo': 'baz' }, 201);Added `make install-support` and `make uninstall-support`Tj Holowaychukbefore adoption774e25d
line 20why, one step back20 });res.send() only setting Content-Type when not already presentTj Holowaychukbefore adoptionf0a0966
lines 21–22why, one step back21 22 app.get('/text', function(req, res){Added res.header()Tj Holowaychukbefore adoption838c470
line 23why, one step back23 res.header('X-Foo', 'bar');res.send() only setting Content-Type when not already presentTj Holowaychukbefore adoptionf0a0966
lines 24–26why, one step back24 res.contentType('.txt');25 res.send('wahoo');26 });Allowing status as first or second arg to res.send()Tj Holowaychukbefore adoption395d14a
lines 27–32why, one step back27 28 app.get('/status', function(req, res){29 res.send(404);30 });31 32 app.get('/error', function(req, res){Added res.send() Content-Type precedence testTj Holowaychukbefore adoptionc8baa8f
line 33why, one step back33 res.send('Oh shit!', { 'Content-Type': 'text/plain' }, 500);Allowing status as first or second arg to res.send()Tj Holowaychukbefore adoption395d14a
line 34why, one step back34 });Added buffer support to res.send()Tj Holowaychukbefore adoption14280df
lines 35–38why, one step back35 36 app.get('/buffer', function(req, res){37 res.send(new Buffer('wahoo!'));38 });Added `make install-support` and `make uninstall-support`Tj Holowaychukbefore adoption774e25d
lines 39–41why, one step back3940 assert.response(app,41 { url: '/html' },res.send() only setting Content-Type when not already presentTj Holowaychukbefore adoptionf0a0966
line 42why, one step back42 { body: '<p>test</p>', headers: { 'Content-Language': 'en', 'Content-Type': 'text/html; charset=utf-8' }});Added `make install-support` and `make uninstall-support`Tj Holowaychukbefore adoption774e25d
lines 43–44why, one step back43 assert.response(app,44 { url: '/json' },req.send() headers take precedenceTj Holowaychukbefore adoption0d4b57d
line 45why, one step back45 { body: '{"foo":"bar"}', status: 201, headers: { 'Content-Type': 'application/json', 'X-Foo': 'baz' }});res.send() only setting Content-Type when not already presentTj Holowaychukbefore adoptionf0a0966
lines 46–47why, one step back46 assert.response(app,47 { url: '/text' },Added res.header()Tj Holowaychukbefore adoption838c470
line 48why, one step back48 { body: 'wahoo', headers: { 'Content-Type': 'text/plain; charset=utf-8', 'X-Foo': 'bar' }});Allowing status as first or second arg to res.send()Tj Holowaychukbefore adoption395d14a
lines 49–53why, one step back49 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' },Added res.send() Content-Type precedence testTj Holowaychukbefore adoptionc8baa8f
line 54why, one step back54 { body: 'Oh shit!', status: 500, headers: { 'Content-Type': 'text/plain' }});Added buffer support to res.send()Tj Holowaychukbefore adoption14280df
lines 55–56why, one step back55 assert.response(app,56 { url: '/buffer' },By default a Buffer passed through res.send() is application/octet-streamTj Holowaychukbefore adoption76052b4
line 57why, one step back57 { body: 'wahoo!', headers: { 'Content-Type': 'application/octet-stream' }});Added res.contentType() testsTj Holowaychukbefore adoptionac17a6a
lines 58–59why, one step back58 },59 Test prefixesTj Holowaychukbefore adoption2ec4a8b
line 60why, one step back60 'test #contentType': function(assert){Added res.contentType() testsTj Holowaychukbefore adoptionac17a6a
lines 61–71why, one step back61 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' }});Added res.attachment()Tj Holowaychukbefore adoption8fdf111
lines 72–73why, one step back72 },73 Test prefixesTj Holowaychukbefore adoption2ec4a8b
line 74why, one step back74 'test #attachment': function(assert){Added res.attachment()Tj Holowaychukbefore adoption8fdf111
lines 75–92why, one step back75 var app = express.createServer();76 77 app.get('/style.css', function(req, res){78 res.attachment();79 res.send('some stylezzz');80 });8182 app.get('/*', function(req, res, params){83 res.attachment(params.splat[0]);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' }});Merge branch 'redirect' into connectTj Holowaychukbefore adoption87cfca7
lines 93–94why, one step back93 },94 Test prefixesTj Holowaychukbefore adoption2ec4a8b
line 95why, one step back95 'test #redirect()': function(assert){Merge branch 'redirect' into connectTj Holowaychukbefore adoption87cfca7
lines 96–100why, one step back96 var app = express.createServer(),97 app2 = express.createServer();98 99 app2.set('home', '/blog');100Added app.redirect(key, url)Tj Holowaychukbefore adoptionb75246e
line 101why, one step back101 app2.redirect('google', 'http://google.com');Merge branch 'redirect' into connectTj Holowaychukbefore adoption87cfca7
line 102why, one step back102Added dynamic redirect mappingTj Holowaychukbefore adoption0bb4815
lines 103–108why, one step back103 app2.redirect('blog', function(req, res, params){104 return params.id105 ? '/user/' + params.id + '/blog'106 : null;107 });108 Merge branch 'redirect' into connectTj Holowaychukbefore adoption87cfca7
lines 109–135why, one step back109 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 });Added dynamic redirect mappingTj Holowaychukbefore adoption0bb4815
lines 136–139why, one step back136137 app2.get('/user/:id', function(req, res){138 res.redirect('blog');139 });Merge branch 'redirect' into connectTj Holowaychukbefore adoption87cfca7
lines 140–168why, one step back140 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' }});Added dynamic redirect mappingTj Holowaychukbefore adoption0bb4815
lines 169–171why, one step back169 assert.response(app2,170 { url: '/user/12' },171 { body: '', headers: { Location: '/user/12/blog' }});Merge branch 'sendfile' into connectTj Holowaychukbefore adoptiond12f434
lines 172–173why, one step back172 },173 Test prefixesTj Holowaychukbefore adoption2ec4a8b
line 174why, one step back174 'test #sendfile()': function(assert){Merge branch 'sendfile' into connectTj Holowaychukbefore adoptiond12f434
line 175why, one step back175 var app = express.createServer();Merge branch 'redirect' into connectTj Holowaychukbefore adoption87cfca7
line 176why, one step back176 Merge branch 'sendfile' into connectTj Holowaychukbefore adoptiond12f434
lines 177–193why, one step back177 app.get('/*', function(req, res, params){178 var file = params.splat[0];179 res.sendfile(__dirname + '/fixtures/' + file);180 });181 182 assert.response(app,183 { url: '/user.json' },184 { body: '{"name":"tj"}', status: 200, headers: { 'Content-Type': 'application/json' }});185 assert.response(app,186 { url: '/hello.haml' },187 { body: '%p Hello World', status: 200, headers: { 'Content-Type': 'application/octet-stream' }});188 assert.response(app,189 { url: '/doesNotExist' },190 { body: 'Not Found', status: 404 });191 assert.response(app,192 { url: '/partials' },193 { body: 'Internal Server Error', status: 500 });Added res.download()Tj Holowaychukbefore adoptionda5a480
lines 194–195why, one step back194 },195 Test prefixesTj Holowaychukbefore adoption2ec4a8b
line 196why, one step back196 'test #download()': function(assert){Added res.download()Tj Holowaychukbefore adoptionda5a480
lines 197–219why, one step back197 var app = express.createServer();198 199 app.get('/json', function(req, res, params, next){200 res.download(__dirname + '/fixtures/user.json', 'account.json');201 });202203 app.get('/:file', function(req, res, params, next){204 res.download(__dirname + '/fixtures/' + params.file);205 });206 207 assert.response(app,208 { url: '/user.json' },209 { body: '{"name":"tj"}', status: 200, headers: {210 'Content-Type': 'application/json',211 'Content-Disposition': 'attachment; filename="user.json"'212 }});213214 assert.response(app,215 { url: '/json' },216 { body: '{"name":"tj"}', status: 200, headers: {217 'Content-Type': 'application/json',218 'Content-Disposition': 'attachment; filename="account.json"'219 }});Added `make install-support` and `make uninstall-support`Tj Holowaychukbefore adoption774e25d
lines 220–221why, one step back220 }221};