request.test.js
This file
Path
test/request.test.js
271 lines · 8.2 KiB · JavaScript
Last changed by
Added failing req.accepts() testTj Holowaychukbefore adoption05bbc65
History of this fileTake it
The walk stopped after 200 commits: lines older than 426e80d point at it.
Updated jade submoduleTj Holowaychukbefore adoption426e80d
lines 1–5why, one step back12/**3 * Module dependencies.4 */5using should / refactored testsTj Holowaychukbefore adoption643879f
lines 6–10why, one step back6var express = require('express')7 , connect = require('connect')8 , assert = require('assert')9 , should = require('should')10 , MemoryStore = require('connect/middleware/session/memory');Updated jade submoduleTj Holowaychukbefore adoption426e80d
lines 11–15why, one step back1112// Prevent reap timer13var memoryStore = new MemoryStore({ reapInterval: -1 });1415module.exports = {using should / refactored testsTj Holowaychukbefore adoption643879f
lines 16–24why, one step back16 'test #isXMLHttpRequest': function(){17 var app = express.createServer();1819 app.get('/isxhr', function(req, res){20 assert.equal(req.xhr, req.isXMLHttpRequest);21 res.send(req.isXMLHttpRequest22 ? 'yeaaa boy'23 : 'nope');24 });Updated jade submoduleTj Holowaychukbefore adoption426e80d
line 25why, one step back25 using should / refactored testsTj Holowaychukbefore adoption643879f
lines 26–28why, one step back26 assert.response(app,27 { url: '/isxhr' },28 { body: 'nope' });Updated jade submoduleTj Holowaychukbefore adoption426e80d
line 29why, one step back29 using should / refactored testsTj Holowaychukbefore adoption643879f
lines 30–36why, one step back30 assert.response(app,31 { url: '/isxhr', headers: { 'X-Requested-With': 'XMLHttpRequest' } },32 { body: 'yeaaa boy' });33 },34 35 'test #header()': function(){36 var app = express.createServer();Updated jade submoduleTj Holowaychukbefore adoption426e80d
line 37why, one step back37 using should / refactored testsTj Holowaychukbefore adoption643879f
lines 38–42why, one step back38 app.get('/', function(req, res){39 req.header('Host').should.equal('foo.com');40 req.header('host').should.equal('foo.com');41 res.send('wahoo');42 });Updated jade submoduleTj Holowaychukbefore adoption426e80d
line 43why, one step back43 using should / refactored testsTj Holowaychukbefore adoption643879f
lines 44–53why, one step back44 assert.response(app,45 { url: '/', headers: { Host: 'foo.com' }},46 { body: 'wahoo' });47 },48 49 'test #accepts()': function(){50 var app = express.createServer();51 52 app.get('/all', function(req, res){53 req.accepts('html').should.be.true;Added more req.accepts() testsTj Holowaychukbefore adoption6624f6b
line 54why, one step back54 req.accepts('.html').should.be.true;using should / refactored testsTj Holowaychukbefore adoption643879f
line 55why, one step back55 req.accepts('json').should.be.true;Added more req.accepts() testsTj Holowaychukbefore adoption6624f6b
line 56why, one step back56 req.accepts('.json').should.be.true;using should / refactored testsTj Holowaychukbefore adoption643879f
lines 57–61why, one step back57 res.send('ok');58 });59 60 app.get('/', function(req, res){61 req.accepts('html').should.be.true;Added failing req.accepts() testTj Holowaychukbefore adoption05bbc65
line 62why, one step back62 req.accepts('.html').should.be.true;using should / refactored testsTj Holowaychukbefore adoption643879f
lines 63–127why, one step back63 req.accepts('text/html').should.be.true;64 req.accepts('text/*').should.be.true;65 req.accepts('json').should.be.true;66 req.accepts('application/json').should.be.true;67 68 req.accepts('xml').should.be.false;69 req.accepts('image/*').should.be.false;70 req.accepts('png').should.be.false;71 req.accepts().should.be.false;72 res.send('ok');73 });74 75 app.get('/type', function(req, res){76 req.accepts('html').should.be.true;77 req.accepts('text/html').should.be.true;78 req.accepts('json').should.be.true;79 req.accepts('application/json').should.be.true;80 81 req.accepts('png').should.be.false;82 req.accepts('image/png').should.be.false;83 res.send('ok'); 84 });85 86 assert.response(app,87 { url: '/all', headers: { Accept: '*/*' }},88 { body: 'ok' });89 assert.response(app,90 { url: '/type', headers: { Accept: 'text/*; application/*' }},91 { body: 'ok' });92 assert.response(app,93 { url: '/', headers: { Accept: 'text/html; application/json; text/*' }},94 { body: 'ok' });95 },96 97 'test #param()': function(){98 var app = express.createServer(99 connect.bodyDecoder()100 );101 102 app.get('/user/:id?', function(req, res){103 res.send('user ' + req.param('id'));104 });105 106 app.post('/user', function(req, res){107 res.send('user ' + req.param('id'));108 });109 110 assert.response(app,111 { url: '/user/12' },112 { body: 'user 12' });113 114 assert.response(app,115 { url: '/user?id=5' },116 { body: 'user 5' });117 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(125 connect.cookieDecoder(),126 connect.session({ store: memoryStore })127 );Updated jade submoduleTj Holowaychukbefore adoption426e80d
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 };Updated jade submoduleTj Holowaychukbefore adoption426e80d
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({});Updated jade submoduleTj Holowaychukbefore adoption426e80d
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([]);Updated jade submoduleTj Holowaychukbefore adoption426e80d
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']);Updated jade submoduleTj Holowaychukbefore adoption426e80d
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 });Merge branch 'is'Tj Holowaychukbefore adoption5b7d231
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();Merge branch 'is'Tj Holowaychukbefore adoption5b7d231
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 });Merge branch 'is'Tj Holowaychukbefore adoption5b7d231
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 });Merge branch 'is'Tj Holowaychukbefore adoption5b7d231
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' });Merge branch 'is'Tj Holowaychukbefore adoption5b7d231
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' });Merge branch 'is'Tj Holowaychukbefore adoption5b7d231
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' });Merge branch 'is'Tj Holowaychukbefore adoption7a71380
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();Merge branch 'is'Tj Holowaychukbefore adoption7a71380
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 });Merge branch 'is'Tj Holowaychukbefore adoption7a71380
line 254why, one step back254using should / refactored testsTj Holowaychukbefore adoption643879f
lines 255–270why, 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' });270 }Updated jade submoduleTj Holowaychukbefore adoption426e80d
line 271why, one step back271};