request.test.js
This file
Path
test/request.test.js
144 lines · 4.7 KiB · JavaScript
Last changed by
Added more req.flash() testsTj Holowaychukbefore adoption5279ade
History of this fileTake it
The walk stopped after 200 commits: lines older than 41f7355 point at it.
Setting res.render() cache to true in productionTj Holowaychukbefore adoption41f7355
lines 1–5why, one step back12/**3 * Module dependencies.4 */5Merge branch 'params' into connectTj Holowaychukbefore adoption9449c4b
line 6why, one step back6var express = require('express'),Merge branch 'flash' into connectTj Holowaychukbefore adoptionc180923
lines 7–8why, one step back7 connect = require('connect'),8 MemoryStore = require('connect/middleware/session/memory');Setting res.render() cache to true in productionTj Holowaychukbefore adoption41f7355
line 9why, one step back9Merge branch 'flash' into connectTj Holowaychukbefore adoptionc180923
lines 10–12why, one step back10// Prevent reap timer11var memoryStore = new MemoryStore({ reapInterval: -1 });12Setting res.render() cache to true in productionTj Holowaychukbefore adoption41f7355
line 13why, one step back13module.exports = {Test prefixesTj Holowaychukbefore adoption2ec4a8b
line 14why, one step back14 'test #isXMLHttpRequest': function(assert){Setting res.render() cache to true in productionTj Holowaychukbefore adoption41f7355
lines 15–30why, one step back15 var app = express.createServer();16 17 app.get('/isxhr', function(req, res, params){18 assert.equal(req.xhr, req.isXMLHttpRequest);19 res.send(req.isXMLHttpRequest20 ? 'yeaaa boy'21 : 'nope');22 });23 24 assert.response(app,25 { url: '/isxhr' },26 { body: 'nope' });27 28 assert.response(app,29 { url: '/isxhr', headers: { 'X-Requested-With': 'XMLHttpRequest' } },30 { body: 'yeaaa boy' });Added req.header() testsTj Holowaychukbefore adoption7897460
lines 31–32why, one step back31 },32 Test prefixesTj Holowaychukbefore adoption2ec4a8b
line 33why, one step back33 'test #header()': function(assert){Added req.header() testsTj Holowaychukbefore adoption7897460
lines 34–44why, one step back34 var app = express.createServer();35 36 app.get('/', function(req, res){37 assert.equal('foo.com', req.header('Host'));38 assert.equal('foo.com', req.header('host'));39 res.send('wahoo');40 });41 42 assert.response(app,43 { url: '/', headers: { Host: 'foo.com' }},44 { body: 'wahoo' });Merge branch 'params' into connectTj Holowaychukbefore adoption9449c4b
lines 45–46why, one step back45 },46 Test prefixesTj Holowaychukbefore adoption2ec4a8b
line 47why, one step back47 'test #accepts()': function(assert){Added req.accepts()Tj Holowaychukbefore adoptioncf37966
lines 48–66why, one step back48 var app = express.createServer();49 50 app.get('/all', function(req, res){51 assert.strictEqual(true, req.accepts('html'));52 assert.strictEqual(true, req.accepts('json'));53 res.send('ok');54 });55 56 app.get('/', function(req, res){57 assert.strictEqual(true, req.accepts('html'));58 assert.strictEqual(true, req.accepts('text/html'));59 assert.strictEqual(true, req.accepts('text/*'));60 assert.strictEqual(true, req.accepts('json'));61 assert.strictEqual(true, req.accepts('application/json'));62 assert.strictEqual(false, req.accepts('xml'));63 assert.strictEqual(false, req.accepts());64 res.send('ok');65 });66 Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817
lines 67–71why, one step back67 app.get('/type', function(req, res){68 assert.strictEqual(true, req.accepts('html'));69 assert.strictEqual(true, req.accepts('text/html'));70 assert.strictEqual(true, req.accepts('json'));71 assert.strictEqual(true, req.accepts('application/json'));Finished req.accepts()Tj Holowaychukbefore adoptione58f468
lines 72–73why, one step back72 assert.strictEqual(false, req.accepts('png'));73 assert.strictEqual(false, req.accepts('image/png'));Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817
lines 74–76why, one step back74 res.send('ok'); 75 });76 Added req.accepts()Tj Holowaychukbefore adoptioncf37966
lines 77–78why, one step back77 assert.response(app,78 { url: '/all', headers: { Accept: '*/*' }},Added more tests for req.accepts()Tj Holowaychukbefore adoption9750817
lines 79–81why, one step back79 { body: 'ok' });80 assert.response(app,81 { url: '/type', headers: { Accept: 'text/*; application/*' }},Added req.accepts()Tj Holowaychukbefore adoptioncf37966
lines 82–87why, one step back82 { body: 'ok' });83 assert.response(app,84 { url: '/', headers: { Accept: 'text/html; application/json; text/*' }},85 { body: 'ok' });86 },87 Test prefixesTj Holowaychukbefore adoption2ec4a8b
line 88why, one step back88 'test #param()': function(assert){Merge branch 'params' into connectTj Holowaychukbefore adoption9449c4b
lines 89–111why, one step back89 var app = express.createServer(90 connect.bodyDecoder()91 );92 93 app.get('/user/:id?', function(req, res){94 res.send('user ' + req.param('id'));95 });96 97 app.post('/user', function(req, res){98 res.send('user ' + req.param('id'));99 });100 101 assert.response(app,102 { url: '/user/12' },103 { body: 'user 12' });104 105 assert.response(app,106 { url: '/user?id=5' },107 { body: 'user 5' });108 109 assert.response(app,110 { url: '/user', method: 'POST', data: 'id=1', headers: { 'Content-Type': 'application/x-www-form-urlencoded' }},111 { body: 'user 1' });Merge branch 'flash' into connectTj Holowaychukbefore adoptionc180923
lines 112–113why, one step back112 },113 Test prefixesTj Holowaychukbefore adoption2ec4a8b
line 114why, one step back114 'test #flash()': function(assert){Merge branch 'flash' into connectTj Holowaychukbefore adoptionc180923
lines 115–132why, one step back115 var app = express.createServer(116 connect.cookieDecoder(),117 connect.session({ store: memoryStore })118 );119120 app.get('/', function(req, res){121 assert.eql([], req.flash('info'));122 assert.eql([], req.flash('error'));123 assert.eql({}, req.flash());124 assert.eql({}, req.session.flash);125 126 assert.equal(1, req.flash('info', 'one'));127 assert.equal(2, req.flash('info', 'two'));128 assert.eql(['one', 'two'], req.flash('info'));129 assert.eql([], req.flash('info'));130131 assert.equal(1, req.flash('info', 'one'));132 assert.eql({ info: ['one'] }, req.flash());Added more req.flash() testsTj Holowaychukbefore adoption5279ade
lines 133–136why, one step back133 134 req.flash('info', 'Email _sent_.');135 req.flash('info', '<script>');136 assert.eql(['Email <em>sent</em>.', '<script>'], req.flash('info'));Merge branch 'flash' into connectTj Holowaychukbefore adoptionc180923
lines 137–142why, one step back137 res.send('ok');138 });139 140 assert.response(app,141 { url: '/' },142 { body: 'ok' });Setting res.render() cache to true in productionTj Holowaychukbefore adoption41f7355
lines 143–144why, one step back143 }144};