request.test.js
This file
Path
test/request.test.js
299 lines · 8.9 KiB · JavaScript
Last changed by
tests running againTj Holowaychukbefore adoptioncd519e9
History of this fileTake it
The walk stopped after 200 commits: lines older than a766cc7 point at it.
Release 1.0.0Tj Holowaychukbefore adoptiona766cc7
lines 1–5why, one step back12/**3 * Module dependencies.4 */5using should / refactored testsTj Holowaychukbefore adoption643879f
lines 6–8why, one step back6var express = require('express')7 , connect = require('connect')8 , assert = require('assert')tests running againTj Holowaychukbefore adoptioncd519e9
line 9why, one step back9 , should = require('should');Release 1.0.0Tj Holowaychukbefore adoptiona766cc7
lines 10–11why, one step back1011module.exports = {using should / refactored testsTj Holowaychukbefore adoption643879f
lines 12–20why, one step back12 'test #isXMLHttpRequest': function(){13 var app = express.createServer();1415 app.get('/isxhr', function(req, res){16 assert.equal(req.xhr, req.isXMLHttpRequest);17 res.send(req.isXMLHttpRequest18 ? 'yeaaa boy'19 : 'nope');20 });Release 1.0.0Tj Holowaychukbefore adoptiona766cc7
line 21why, one step back21 using should / refactored testsTj Holowaychukbefore adoption643879f
lines 22–24why, one step back22 assert.response(app,23 { url: '/isxhr' },24 { body: 'nope' });Release 1.0.0Tj Holowaychukbefore adoptiona766cc7
line 25why, one step back25 using should / refactored testsTj Holowaychukbefore adoption643879f
lines 26–32why, one step back26 assert.response(app,27 { url: '/isxhr', headers: { 'X-Requested-With': 'XMLHttpRequest' } },28 { body: 'yeaaa boy' });29 },30 31 'test #header()': function(){32 var app = express.createServer();Release 1.0.0Tj Holowaychukbefore adoptiona766cc7
line 33why, one step back33 using should / refactored testsTj Holowaychukbefore adoption643879f
lines 34–38why, one step back34 app.get('/', function(req, res){35 req.header('Host').should.equal('foo.com');36 req.header('host').should.equal('foo.com');37 res.send('wahoo');38 });Release 1.0.0Tj Holowaychukbefore adoptiona766cc7
line 39why, one step back39 using should / refactored testsTj Holowaychukbefore adoption643879f
lines 40–49why, one step back40 assert.response(app,41 { url: '/', headers: { Host: 'foo.com' }},42 { body: 'wahoo' });43 },44 45 'test #accepts()': function(){46 var app = express.createServer();47 48 app.get('/all', function(req, res){49 req.accepts('html').should.be.true;Added more req.accepts() testsTj Holowaychukbefore adoption6624f6b
line 50why, one step back50 req.accepts('.html').should.be.true;using should / refactored testsTj Holowaychukbefore adoption643879f
line 51why, one step back51 req.accepts('json').should.be.true;Added more req.accepts() testsTj Holowaychukbefore adoption6624f6b
line 52why, one step back52 req.accepts('.json').should.be.true;using should / refactored testsTj Holowaychukbefore adoption643879f
lines 53–57why, one step back53 res.send('ok');54 });55 56 app.get('/', function(req, res){57 req.accepts('html').should.be.true;Added failing req.accepts() testTj Holowaychukbefore adoption05bbc65
line 58why, one step back58 req.accepts('.html').should.be.true;using should / refactored testsTj Holowaychukbefore adoption643879f
lines 59–94why, one step back59 req.accepts('text/html').should.be.true;60 req.accepts('text/*').should.be.true;61 req.accepts('json').should.be.true;62 req.accepts('application/json').should.be.true;63 64 req.accepts('xml').should.be.false;65 req.accepts('image/*').should.be.false;66 req.accepts('png').should.be.false;67 req.accepts().should.be.false;68 res.send('ok');69 });70 71 app.get('/type', function(req, res){72 req.accepts('html').should.be.true;73 req.accepts('text/html').should.be.true;74 req.accepts('json').should.be.true;75 req.accepts('application/json').should.be.true;76 77 req.accepts('png').should.be.false;78 req.accepts('image/png').should.be.false;79 res.send('ok'); 80 });81 82 assert.response(app,83 { url: '/all', headers: { Accept: '*/*' }},84 { body: 'ok' });85 assert.response(app,86 { url: '/type', headers: { Accept: 'text/*; application/*' }},87 { body: 'ok' });88 assert.response(app,89 { url: '/', headers: { Accept: 'text/html; application/json; text/*' }},90 { body: 'ok' });91 },92 93 'test #param()': function(){94 var app = express.createServer(Renaming usage of old connect middlewareTj Holowaychukbefore adoption2a7a5ae
line 95why, one step back95 connect.bodyParser()using should / refactored testsTj Holowaychukbefore adoption643879f
lines 96–98why, one step back96 );97 98 app.get('/user/:id?', function(req, res){Added default param support to req.param(name, default)Tj Holowaychukbefore adoption0af9126
line 99why, one step back99 res.send('user ' + req.param('id', 'unknown'));using should / refactored testsTj Holowaychukbefore adoption643879f
lines 100–112why, one step back100 });101 102 app.post('/user', function(req, res){103 res.send('user ' + req.param('id'));104 });105 106 assert.response(app,107 { url: '/user/12' },108 { body: 'user 12' });109 110 assert.response(app,111 { url: '/user?id=5' },112 { body: 'user 5' });Added default param support to req.param(name, default)Tj Holowaychukbefore adoption0af9126
lines 113–116why, one step back113 114 assert.response(app,115 { url: '/user' },116 { body: 'user unknown' });using should / refactored testsTj Holowaychukbefore adoption643879f
lines 117–124why, one step back117 118 assert.response(app,119 { url: '/user', method: 'POST', data: 'id=1', headers: { 'Content-Type': 'application/x-www-form-urlencoded' }},120 { body: 'user 1' });121 },122 123 'test #flash()': function(){124 var app = express.createServer(tests running againTj Holowaychukbefore adoptioncd519e9
lines 125–126why, one step back125 connect.cookieParser()126 , connect.session({ secret: 'something' })using should / refactored testsTj Holowaychukbefore adoption643879f
line 127why, one step back127 );Release 1.0.0Tj Holowaychukbefore adoptiona766cc7
line 128why, one step back128using should / refactored testsTj Holowaychukbefore adoption643879f
lines 129–133why, one step back129 app.flashFormatters = {130 u: function(val){131 return String(val).toUpperCase();132 }133 };Release 1.0.0Tj Holowaychukbefore adoptiona766cc7
line 134why, one step back134using should / refactored testsTj Holowaychukbefore adoption643879f
lines 135–139why, one step back135 app.get('/', function(req, res){136 req.flash('info').should.be.empty;137 req.flash('error').should.be.empty;138 req.flash().should.eql({});139 req.session.flash.should.eql({});Release 1.0.0Tj Holowaychukbefore adoptiona766cc7
line 140why, one step back140using should / refactored testsTj Holowaychukbefore adoption643879f
lines 141–144why, one step back141 req.flash('info', 'one').should.equal(1);142 req.flash('info', 'two').should.equal(2);143 req.flash('info').should.eql(['one', 'two']);144 req.flash('info').should.eql([]);Release 1.0.0Tj Holowaychukbefore adoptiona766cc7
line 145why, one step back145using should / refactored testsTj Holowaychukbefore adoption643879f
lines 146–147why, one step back146 req.flash('info', 'one').should.equal(1);147 req.flash('info').should.eql(['one']);Release 1.0.0Tj Holowaychukbefore adoptiona766cc7
line 148why, one step back148using should / refactored testsTj Holowaychukbefore adoption643879f
lines 149–160why, one step back149 req.flash('info', 'Email _sent_.');150 req.flash('info', '<script>');151 req.flash('info').should.eql(['Email <em>sent</em>.', '<script>']);152 153 req.flash('info', 'Welcome _%s_ to %s', 'TJ', 'something');154 req.flash('info').should.eql(['Welcome <em>TJ</em> to something']);155156 req.flash('error', 'Foo %u', 'bar');157 req.flash('error').should.eql(['Foo BAR']);158159 res.send('ok');160 });Release 1.0.0Tj Holowaychukbefore adoptiona766cc7
line 161why, one step back161 using should / refactored testsTj Holowaychukbefore adoption643879f
lines 162–168why, one step back162 assert.response(app,163 { url: '/' },164 { body: 'ok' });165 },166 167 'test #is()': function(){168 var app = express.createServer();Release 1.0.0Tj Holowaychukbefore adoptiona766cc7
line 169why, one step back169using should / refactored testsTj Holowaychukbefore adoption643879f
lines 170–176why, one step back170 app.is('an image', function(req){171 return 0 == req.headers['content-type'].indexOf('image');172 });173 174 app.is('text', function(req){175 return 0 == req.headers['content-type'].indexOf('text');176 });Release 1.0.0Tj Holowaychukbefore adoptiona766cc7
line 177why, one step back177using should / refactored testsTj Holowaychukbefore adoption643879f
lines 178–200why, one step back178 app.get('/', function(req, res, next){179 if (req.is('html')) return res.send('html');180 res.send('not sure');181 });182 183 app.post('/', function(req, res, next){184 if (req.is('html')) return res.send('/ html');185 if (req.is('json')) return res.send('/ json');186 if (req.is('png')) return res.send('/ png');187 res.send('/ not sure');188 });189 190 app.post('/long', function(req, res, next){191 if (req.is('text/html')) return res.send('/long html');192 if (req.is('application/json')) return res.send('/long json');193 if (req.is('image/png')) return res.send('/long png');194 res.send('/long not sure');195 });196 197 app.put('/custom', function(req, res, next){198 if (req.is('an image')) return res.send('/custom an image');199 if (req.is('text')) return res.send('/custom text');200 });Release 1.0.0Tj Holowaychukbefore adoptiona766cc7
line 201why, one step back201using should / refactored testsTj Holowaychukbefore adoption643879f
lines 202–204why, one step back202 assert.response(app,203 { url: '/' },204 { body: 'not sure' });Release 1.0.0Tj Holowaychukbefore adoptiona766cc7
line 205why, one step back205using should / refactored testsTj Holowaychukbefore adoption643879f
lines 206–217why, one step back206 assert.response(app,207 { url: '/', method: 'POST', headers: { 'Content-Type': 'text/html' }},208 { body: '/ html' });209 assert.response(app,210 { url: '/', method: 'POST', headers: { 'Content-Type': 'application/json; charset=utf-8' }},211 { body: '/ json' });212 assert.response(app,213 { url: '/', method: 'POST', headers: { 'Content-Type': 'image/png' }},214 { body: '/ png' });215 assert.response(app,216 { url: '/', method: 'POST' },217 { body: '/ not sure' });Release 1.0.0Tj Holowaychukbefore adoptiona766cc7
line 218why, one step back218using should / refactored testsTj Holowaychukbefore adoption643879f
lines 219–230why, one step back219 assert.response(app,220 { url: '/long', method: 'POST', headers: { 'Content-Type': 'text/html' }},221 { body: '/long html' });222 assert.response(app,223 { url: '/long', method: 'POST', headers: { 'Content-Type': 'application/json; charset=utf-8' }},224 { body: '/long json' });225 assert.response(app,226 { url: '/long', method: 'POST', headers: { 'Content-Type': 'image/png' }},227 { body: '/long png' });228 assert.response(app,229 { url: '/long', method: 'POST' },230 { body: '/long not sure' });Release 1.0.0Tj Holowaychukbefore adoptiona766cc7
line 231why, one step back231 using should / refactored testsTj Holowaychukbefore adoption643879f
lines 232–247why, one step back232 assert.response(app,233 { url: '/custom', method: 'PUT', headers: { 'Content-Type': 'text/plain' }},234 { body: '/custom text' });235 assert.response(app,236 { url: '/custom', method: 'PUT', headers: { 'Content-Type': 'text/html' }},237 { body: '/custom text' });238 assert.response(app,239 { url: '/custom', method: 'PUT', headers: { 'Content-Type': 'image/jpeg' }},240 { body: '/custom an image' });241 assert.response(app,242 { url: '/custom', method: 'PUT', headers: { 'Content-Type': 'image/png' }},243 { body: '/custom an image' });244 },245 246 'test #is() wildcard': function(){247 var app = express.createServer();Release 1.0.0Tj Holowaychukbefore adoptiona766cc7
line 248why, one step back248using should / refactored testsTj Holowaychukbefore adoption643879f
lines 249–253why, one step back249 app.post('/', function(req, res, next){250 if (req.is('image/*')) return res.send('image');251 if (req.is('*/json')) return res.send('json');252 res.send('not sure');253 });Release 1.0.0Tj Holowaychukbefore adoptiona766cc7
line 254why, one step back254using should / refactored testsTj Holowaychukbefore adoption643879f
lines 255–269why, one step back255 assert.response(app,256 { url: '/', method: 'POST', headers: { 'Content-Type': 'image/png' }},257 { body: 'image' });258 assert.response(app,259 { url: '/', method: 'POST', headers: { 'Content-Type': 'image/jpeg' }},260 { body: 'image' });261 assert.response(app,262 { url: '/', method: 'POST', headers: { 'Content-Type': 'text/plain' }},263 { body: 'not sure' });264 assert.response(app,265 { url: '/', method: 'POST', headers: { 'Content-Type': 'text/json' }},266 { body: 'json' });267 assert.response(app,268 { url: '/', method: 'POST', headers: { 'Content-Type': 'application/json' }},269 { body: 'json' });Added req.header() Referrer / Referer special-caseTj Holowaychukbefore adoptionb65b063
lines 270–297why, one step back270 },271 272 'test #header() referrer': function(){273 var app = express.createServer();274275 app.get('/correct', function(req, res){276 res.send(req.header('Referrer'));277 });278 279 app.get('/incorrect', function(req, res){280 res.send(req.header('Referer'));281 });282283 assert.response(app,284 { url: '/correct', headers: { Referer: 'expressjs.com' }},285 { body: 'expressjs.com' });286287 assert.response(app,288 { url: '/correct', headers: { Referrer: 'expressjs.com' }},289 { body: 'expressjs.com' });290291 assert.response(app,292 { url: '/incorrect', headers: { Referrer: 'expressjs.com' }},293 { body: 'expressjs.com' });294295 assert.response(app,296 { url: '/incorrect', headers: { Referer: 'expressjs.com' }},297 { body: 'expressjs.com' });using should / refactored testsTj Holowaychukbefore adoption643879f
line 298why, one step back298 }Release 1.0.0Tj Holowaychukbefore adoptiona766cc7
line 299why, one step back299};