using should / refactored tests
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Tj Holowaychuk · committed by Tj Holowaychuk · parent ce2a18f · Browse files · 9 files·+1631 added−1595 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
9 files+1631 added−1595 removed
- tests:+1627 added−1595 removed
- other:+4 added−0 removed
Provenance
- Commit
643879f- Tree
f841aa1- Author
Tj Holowaychuk <tj@vision-media.ca>- Committer
Tj Holowaychuk <tj@vision-media.ca>- Parent
ce2a18f
9 files changed+1631 added−1595 removed
modified:support/expressonot shown
Its text is not shown, modified.
added:support/shouldnot shown
Its text is not shown, added.
modified:test/express.test.js+381 added-374 removed
1 2-var express = require('express'),3- connect = require('connect');2+/**3+ * Module dependencies.4+ */5 6+var express = require('express')7+ , connect = require('connect')8+ , assert = require('assert')9+ , should = require('should');10+11 module.exports = {6- 'test inheritance': function(assert){7- var server = express.createServer();8- assert.ok(server instanceof connect.Server, 'Test serverlication inheritance');9- },12+ 'test inheritance': function(){13+ var server = express.createServer();14+ server.should.be.an.instanceof(connect.Server);15+ },16+ 17+ 'test connect middleware autoloaders': function(){18+ express.errorHandler.should.equal(connect.errorHandler);19+ },20+ 21+ 'test basic server': function(){22+ var server = express.createServer();23+24+ server.get('/', function(req, res){25+ server.set('env').should.equal('test');26+ res.writeHead(200, {});27+ res.end('wahoo');28+ });29+30+ server.put('/user/:id', function(req, res){31+ res.writeHead(200, {});32+ res.end('updated user ' + req.params.id)33+ });34+35+ server.del('/something', function(req, res){36+ res.send('Destroyed');37+ });38+39+ server.delete('/something/else', function(req, res){40+ res.send('Destroyed');41+ });42 11- 'test connect middleware autoloaders': function(assert){12- assert.equal(express.errorHandler, connect.errorHandler);13- },43+ server.all('/staff/:id', function(req, res, next){44+ req.staff = { id: req.params.id };45+ next();46+ });47+48+ server.get('/staff/:id', function(req, res){49+ res.send('GET Staff ' + req.staff.id);50+ });51 15- 'test basic server': function(assert){16- var server = express.createServer();52+ server.post('/staff/:id', function(req, res){53+ res.send('POST Staff ' + req.staff.id);54+ });55+ 56+ server.all('*', function(req, res){57+ res.send('requested ' + req.url);58+ });59 18- server.get('/', function(req, res){19- assert.equal('test', server.set('env'), 'env setting was not set properly');20- res.writeHead(200, {});21- res.end('wahoo');22- });60+ assert.response(server,61+ { url: '/' },62+ { body: 'wahoo' });63+ 64+ assert.response(server,65+ { url: '/user/12', method: 'PUT' },66+ { body: 'updated user 12' });67 24- server.put('/user/:id', function(req, res){25- res.writeHead(200, {});26- res.end('updated user ' + req.params.id)27- });68+ assert.response(server,69+ { url: '/something', method: 'DELETE' },70+ { body: 'Destroyed' });71 29- server.del('/something', function(req, res){30- res.send('Destroyed');31- });72+ assert.response(server,73+ { url: '/something/else', method: 'DELETE' },74+ { body: 'Destroyed' });75 33- server.delete('/something/else', function(req, res){34- res.send('Destroyed');35- });36- 37- server.all('/staff/:id', function(req, res, next){38- req.staff = { id: req.params.id };39- next();40- });76+ assert.response(server,77+ { url: '/staff/12' },78+ { body: 'GET Staff 12' });79+ 80+ assert.response(server,81+ { url: '/staff/12', method: 'POST' },82+ { body: 'POST Staff 12' });83+ 84+ assert.response(server,85+ { url: '/foo/bar/baz', method: 'DELETE' },86+ { body: 'requested /foo/bar/baz' });87+ },88+ 89+ 'test constructor middleware': function(beforeExit){90+ var calls = [];91 42- server.get('/staff/:id', function(req, res){43- res.send('GET Staff ' + req.staff.id);44- });45- 46- server.post('/staff/:id', function(req, res){47- res.send('POST Staff ' + req.staff.id);48- });49- 50- server.all('*', function(req, res){51- res.send('requested ' + req.url);52- });92+ function one(req, res, next){93+ calls.push('one');94+ next();95+ }96 54- assert.response(server,55- { url: '/' },56- { body: 'wahoo' });57- 58- assert.response(server,59- { url: '/user/12', method: 'PUT' },60- { body: 'updated user 12' });97+ function two(req, res, next){98+ calls.push('two');99+ next();100+ }101 62- assert.response(server,63- { url: '/something', method: 'DELETE' },64- { body: 'Destroyed' });65-66- assert.response(server,67- { url: '/something/else', method: 'DELETE' },68- { body: 'Destroyed' });102+ var app = express.createServer(one, two);103+ app.get('/', function(req, res){104+ res.writeHead(200, {});105+ res.end('foo bar');106+ });107+ 108+ assert.response(app,109+ { url: '/' },110+ { body: 'foo bar' });111+ 112+ beforeExit(function(){113+ calls.should.eql(['one', 'two']);114+ });115+ },116 70- assert.response(server,71- { url: '/staff/12' },72- { body: 'GET Staff 12' });73- 74- assert.response(server,75- { url: '/staff/12', method: 'POST' },76- { body: 'POST Staff 12' });77- 78- assert.response(server,79- { url: '/foo/bar/baz', method: 'DELETE' },80- { body: 'requested /foo/bar/baz' });81- },117+ 'test #error()': function(){118+ // Passing down middleware stack119+ var app = express.createServer();120 83- 'test constructor middleware': function(assert, beforeExit){84- var calls = [];85- function one(req, res, next){86- calls.push('one');87- next();88- }89- function two(req, res, next){90- calls.push('two');91- next();92- }93- var app = express.createServer(one, two);94- app.get('/', function(req, res){95- res.writeHead(200, {});96- res.end('foo bar');97- });98- 99- assert.response(app,100- { url: '/' },101- { body: 'foo bar' });102- 103- beforeExit(function(){104- assert.eql(['one', 'two'], calls);105- });106- },121+ app.get('/', function(req, res, next){122+ next(new Error('broken'));123+ });124 108- 'test #error()': function(assert){109- // Passing down middleware stack110- var app = express.createServer();111- 112- app.get('/', function(req, res, next){113- next(new Error('broken'));114- });115- 116- app.use('/', connect.errorHandler());117- 118- assert.response(app,119- { url: '/' },120- { body: 'Internal Server Error' });125+ app.use('/', connect.errorHandler());126+ 127+ assert.response(app,128+ { url: '/' },129+ { body: 'Internal Server Error' });130 122- // Custom handler123- var app = express.createServer();124- 125- app.error(function(err, req, res){126- res.send('Shit: ' + err.message, 500);127- });131+ // Custom handler132+ var app = express.createServer();133+ 134+ app.error(function(err, req, res){135+ res.send('Shit: ' + err.message, 500);136+ });137 129- app.get('/', function(req, res, next){130- next(new Error('broken'));131- });132- 133- assert.response(app,134- { url: '/' },135- { body: 'Shit: broken', status: 500 });136- 137- // Multiple error()s138- var app = express.createServer();139- 140- app.error(function(err, req, res, next){141- if (err.message === 'broken') {142- next(err);143- } else {144- res.send(500);145- }146- });147- 148- app.error(function(err, req, res, next){149- res.send(err.message, 500);150- });138+ app.get('/', function(req, res, next){139+ next(new Error('broken'));140+ });141+ 142+ assert.response(app,143+ { url: '/' },144+ { body: 'Shit: broken', status: 500 });145+ 146+ // Multiple error()s147+ var app = express.createServer();148+ 149+ app.error(function(err, req, res, next){150+ if (err.message === 'broken') {151+ next(err);152+ } else {153+ res.send(500);154+ }155+ });156+ 157+ app.error(function(err, req, res, next){158+ res.send(err.message, 500);159+ });160 152- app.get('/', function(req, res, next){153- throw new Error('broken');154- });155- app.get('/foo', function(req, res, next){156- throw new Error('oh noes');157- });158- 159- assert.response(app,160- { url: '/' },161- { body: 'broken', status: 500 });162- assert.response(app,163- { url: '/foo' },164- { body: 'Internal Server Error' });165- },161+ app.get('/', function(req, res, next){162+ throw new Error('broken');163+ });164+ app.get('/foo', function(req, res, next){165+ throw new Error('oh noes');166+ });167 167- 'test next()': function(assert){168- var app = express.createServer();169- 170- app.get('/user.:format?', function(req, res, next){171- switch (req.params.format) {172- case 'json':173- res.writeHead(200, {});174- res.end('some json');175- break;176- default:177- next();178- }179- });180- 181- app.get('/user', function(req, res){182- res.writeHead(200, {});183- res.end('no json :)');184- });185- 186- assert.response(app,187- { url: '/user.json' },188- { body: 'some json' });189- 190- assert.response(app,191- { url: '/user' },192- { body: 'no json :)' });193- },168+ assert.response(app,169+ { url: '/' },170+ { body: 'broken', status: 500 });171+ assert.response(app,172+ { url: '/foo' },173+ { body: 'Internal Server Error' });174+ },175+ 176+ 'test next()': function(){177+ var app = express.createServer();178 179+ app.get('/user.:format?', function(req, res, next){180+ switch (req.params.format) {181+ case 'json':182+ res.writeHead(200, {});183+ res.end('some json');184+ break;185+ default:186+ next();187+ }188+ });189+ 190+ app.get('/user', function(req, res){191+ res.writeHead(200, {});192+ res.end('no json :)');193+ });194+ 195+ assert.response(app,196+ { url: '/user.json' },197+ { body: 'some json' });198+ 199+ assert.response(app,200+ { url: '/user' },201+ { body: 'no json :)' });202+ },203+ 195- 'test #use()': function(assert){196- var app = express.createServer();204+ 'test #use()': function(){205+ var app = express.createServer();206 198- app.get('/users', function(req, res, next){199- next(new Error('fail!!'));200- });201- app.use('/', connect.errorHandler({ showMessage: true }));202- 203- assert.response(app,204- { url: '/users' },205- { body: 'Error: fail!!' });206- },207+ app.get('/users', function(req, res, next){208+ next(new Error('fail!!'));209+ });210+ app.use('/', connect.errorHandler({ showMessage: true }));211+ 212+ assert.response(app,213+ { url: '/users' },214+ { body: 'Error: fail!!' });215+ },216+ 217+ 'test #configure()': function(beforeExit){218+ var calls = [];219+ process.env.NODE_ENV = 'development';220+ var server = express.createServer();221 208- 'test #configure()': function(assert, beforeExit){209- var calls = [];210- process.env.NODE_ENV = 'development';211- var server = express.createServer();212- 213- // Config blocks214- var ret = server.configure(function(){215- assert.equal(this, server, 'Test context of configure() is the server');216- calls.push('any');217- }).configure('development', function(){218- calls.push('dev');219- }).configure('production', function(){220- calls.push('production');221- });222+ // Config blocks223+ var ret = server.configure(function(){224+ assert.equal(this, server, 'Test context of configure() is the server');225+ calls.push('any');226+ }).configure('development', function(){227+ calls.push('dev');228+ }).configure('production', function(){229+ calls.push('production');230+ });231 223- assert.equal(ret, server, 'Test #configure() returns server for chaining');232+ should.equal(ret, server, 'Test #configure() returns server for chaining');233 225- assert.response(server,226- { url: '/' },227- { body: 'Cannot GET /' });234+ assert.response(server,235+ { url: '/' },236+ { body: 'Cannot GET /' });237 229- beforeExit(function(){230- assert.eql(['any', 'dev'], calls);231- });232- },238+ beforeExit(function(){239+ calls.should.eql(['any', 'dev']);240+ });241+ },242+ 243+ 'test #configure() immediate call': function(){244+ var app = express.createServer();245+246+ app.configure(function(){247+ app.use(connect.bodyDecoder());248+ });249 234- 'test #configure() immediate call': function(assert){235- var app = express.createServer();250+ app.post('/', function(req, res){251+ res.send(req.param('name') || 'nope');252+ });253 237- app.configure(function(){238- app.use(connect.bodyDecoder());239- });240- 241- app.post('/', function(req, res){242- res.send(req.param('name') || 'nope');243- });254+ assert.response(app,255+ { url: '/', method: 'POST', data: 'name=tj', headers: { 'Content-Type': 'application/x-www-form-urlencoded' }},256+ { body: 'tj' });257+ },258 245- assert.response(app,246- { url: '/', method: 'POST', data: 'name=tj', headers: { 'Content-Type': 'application/x-www-form-urlencoded' }},247- { body: 'tj' });248- },259+ 'test #configure() precedence': function(){260+ var app = express.createServer();261 250- 'test #configure() precedence': function(assert){251- var app = express.createServer();262+ app.configure(function(){263+ app.use(function(req, res, next){264+ res.writeHead(200, {});265+ res.write('first');266+ next();267+ });268+ app.use(app.router);269+ app.use(function(req, res, next){270+ res.end('last');271+ });272+ });273 253- app.configure(function(){254- app.use(function(req, res, next){255- res.writeHead(200, {});256- res.write('first');257- next();258- });259- app.use(app.router);260- app.use(function(req, res, next){261- res.end('last');262- });263- });264- 265- app.get('/', function(req, res, next){266- res.write(' route ');267- next();268- });274+ app.get('/', function(req, res, next){275+ res.write(' route ');276+ next();277+ });278+279+ assert.response(app,280+ { url: '/' },281+ { body: 'first route last' });282+ },283+ 284+ 'test #set()': function(){285+ var app = express.createServer();286+ var ret = app.set('title', 'My App').set('something', 'else');287+ ret.should.equal(app);288+ app.set('title').should.equal('My App');289+ app.set('something').should.equal('else');290+ },291+ 292+ 'test #enable()': function(){293+ var app = express.createServer();294+ var ret = app.enable('some feature');295+ ret.should.equal(app);296+ app.set('some feature').should.equal(true);297+ },298+ 299+ 'test #disable()': function(){300+ var app = express.createServer();301+ var ret = app.disable('some feature');302+ ret.should.equal(app);303+ app.set('some feature').should.equal(false);304+ },305+ 306+ 'test middleware precedence': function(){307+ var app = express.createServer();308 270- assert.response(app,271- { url: '/' },272- { body: 'first route last' });273- },309+ app.use(connect.bodyDecoder());310+311+ assert.equal(2, app.stack.length);312 275- 'test #set()': function(assert){276- var app = express.createServer();277- var ret = app.set('title', 'My App').set('something', 'else');278- assert.equal(app, ret, 'Test #set() returns server for chaining');279- assert.equal('My App', app.set('title'));280- assert.equal('else', app.set('something'));281- },313+ app.post('/', function(req, res){314+ res.send(JSON.stringify(req.body || ''));315+ });316+ app.get('/', function(){317+318+ });319+ assert.equal(3, app.stack.length);320+321+ assert.response(app,322+ { url: '/', method: 'POST', data: 'name=tj', headers: { 'Content-Type': 'application/x-www-form-urlencoded' }},323+ { body: '{"name":"tj"}' });324+ },325+ 326+ 'test mounting': function(){327+ var called328+ , app = express.createServer()329+ , blog = express.createServer()330+ , map = express.createServer();331+332+ map.set('home', '/map');333 283- 'test #enable()': function(assert){284- var app = express.createServer();285- var ret = app.enable('some feature');286- assert.equal(app, ret, 'Test #enable() returns server for chaining');287- assert.strictEqual(true, app.set('some feature'));288- },334+ map.mounted(function(parent){335+ called = true;336+ assert.equal(this, map, 'mounted() is not in context of the child app');337+ assert.equal(app, parent, 'mounted() was not called with parent app');338+ });339 290- 'test #disable()': function(assert){291- var app = express.createServer();292- var ret = app.disable('some feature');293- assert.equal(app, ret, 'Test #disable() returns server for chaining');294- assert.strictEqual(false, app.set('some feature'));295- },296- 297- 'test middleware precedence': function(assert){298- var app = express.createServer();299- 300- app.use(connect.bodyDecoder());340+ app.use('/blog', blog);341+ app.use('/contact', map);342+ blog.route.should.equal('/blog');343+ map.route.should.equal('/contact');344+ should.equal(true, called);345 302- assert.equal(2, app.stack.length);303- 304- app.post('/', function(req, res){305- res.send(JSON.stringify(req.body || ''));306- });307- app.get('/', function(){308- 309- });310- assert.equal(3, app.stack.length);311-312- assert.response(app,313- { url: '/', method: 'POST', data: 'name=tj', headers: { 'Content-Type': 'application/x-www-form-urlencoded' }},314- { body: '{"name":"tj"}' });315- },346+ app.set("test", "parent setting");347+ blog.set('test').should.equal('parent setting');348 317- 'test mounting': function(assert){318- var called,319- app = express.createServer(),320- blog = express.createServer(),321- map = express.createServer();349+ app.get('/', function(req, res){350+ app.set('home').should.equal('/');351+ blog.set('home').should.equal('/blog');352+ map.set('home').should.equal('/contact/map');353+ res.send('main app');354+ });355 323- map.set('home', '/map');324- 325- map.mounted(function(parent){326- called = true;327- assert.equal(this, map, 'mounted() is not in context of the child app');328- assert.equal(app, parent, 'mounted() was not called with parent app');329- });330- 331- app.use('/blog', blog);332- app.use('/contact', map);333- assert.equal('/blog', blog.route);334- assert.equal('/contact', map.route);335- assert.ok(called, 'mounted() hook failed');336-337- app.set("test", "parent setting");338- assert.equal(blog.set("test"), "parent setting", "settings did not inherit from parent app")339- blog.set("test", "overridden");340- assert.equal(blog.set("test"), "overridden", "mounted app setting did not override parent app")341- 342- app.get('/', function(req, res){343- assert.equal('/', app.set('home'), "home did not default to /");344- assert.equal('/blog', blog.set('home'), "home did not default to Server#route when mounted");345- assert.equal('/contact/map', map.set('home'), 'home did not prepend route on Server#use()');346- res.send('main app');347- });348-349- blog.get('/', function(req, res){350- res.send('blog index');351- });356+ blog.get('/', function(req, res){357+ res.send('blog index');358+ });352- 353- blog.get('/post/:id', function(req, res){354- res.send('blog post ' + req.params.id);355- });356- 357- assert.response(app,358- { url: '/' },359- { body: 'main app' });360- assert.response(app,361- { url: '/blog' },362- { body: 'blog index' });363- assert.response(app,364- { url: '/blog/post/12' },365- { body: 'blog post 12' });366- assert.response(blog,367- { url: '/' },368- { body: 'blog index' });369- },359 360+ blog.get('/post/:id', function(req, res){361+ res.send('blog post ' + req.params.id);362+ });363+ 364+ assert.response(app,365+ { url: '/' },366+ { body: 'main app' });367+ assert.response(app,368+ { url: '/blog' },369+ { body: 'blog index' });370+ assert.response(app,371+ { url: '/blog/post/12' },372+ { body: 'blog post 12' });373+ assert.response(blog,374+ { url: '/' },375+ { body: 'blog index' });376+ },377+ 371- 'test route middleware': function(assert){372- var app = express.createServer();378+ 'test route middleware': function(){379+ var app = express.createServer();380 374- function allow(role) {375- return function(req, res, next) {376- // this is totally not real, dont use this :)377- // for tests only378- if (req.headers['x-role'] == role) {379- next();380- } else {381- res.send(401);382- }383- }381+ function allow(role) {382+ return function(req, res, next) {383+ // this is totally not real, dont use this :)384+ // for tests only385+ if (req.headers['x-role'] == role) {386+ next();387+ } else {388+ res.send(401);389 }385- 386- function restrictAge(age) {387- return function(req, res, next){388- if (req.headers['x-age'] >= age) {389- next();390- } else {391- res.send(403);392- }393- }390+ }391+ }392+ 393+ function restrictAge(age) {394+ return function(req, res, next){395+ if (req.headers['x-age'] >= age) {396+ next();397+ } else {398+ res.send(403);399 }400+ }401+ }402 396- app.get('/xxx', allow('member'), restrictAge(18), function(req, res){397- res.send(200);398- });403+ app.get('/xxx', allow('member'), restrictAge(18), function(req, res){404+ res.send(200);405+ });406 400- app.get('/booze', [allow('member')], restrictAge(18), function(req, res){401- res.send(200);402- });407+ app.get('/booze', [allow('member')], restrictAge(18), function(req, res){408+ res.send(200);409+ });410 404- app.get('/tobi', [allow('member')], [[restrictAge(18)]], function(req, res){405- res.send(200);406- });411+ app.get('/tobi', [allow('member')], [[restrictAge(18)]], function(req, res){412+ res.send(200);413+ });414 408- ['xxx', 'booze', 'tobi'].forEach(function(thing){409- assert.response(app,410- { url: '/' + thing },411- { body: 'Unauthorized', status: 401 });412- assert.response(app,413- { url: '/' + thing, headers: { 'X-Role': 'member' }},414- { body: 'Forbidden', status: 403 });415- assert.response(app,416- { url: '/' + thing, headers: { 'X-Role': 'member', 'X-Age': 18 }},417- { body: 'OK', status: 200 });418- });419- }415+ ['xxx', 'booze', 'tobi'].forEach(function(thing){416+ assert.response(app,417+ { url: '/' + thing },418+ { body: 'Unauthorized', status: 401 });419+ assert.response(app,420+ { url: '/' + thing, headers: { 'X-Role': 'member' }},421+ { body: 'Forbidden', status: 403 });422+ assert.response(app,423+ { url: '/' + thing, headers: { 'X-Role': 'member', 'X-Age': 18 }},424+ { body: 'OK', status: 200 });425+ });426+ }427 };modified:test/request.test.js+239 added-233 removed
1 unmodified line2 /**3 * Module dependencies.4 */5 6-var express = require('express'),7- connect = require('connect'),8- MemoryStore = require('connect/middleware/session/memory');6+var express = require('express')7+ , connect = require('connect')8+ , assert = require('assert')9+ , should = require('should')10+ , MemoryStore = require('connect/middleware/session/memory');11 12 // Prevent reap timer13 var memoryStore = new MemoryStore({ reapInterval: -1 });14 15 module.exports = {14- 'test #isXMLHttpRequest': function(assert){15- var app = express.createServer();16- 17- app.get('/isxhr', function(req, res){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' });31- },16+ 'test #isXMLHttpRequest': function(){17+ var app = express.createServer();18+19+ app.get('/isxhr', function(req, res){20+ assert.equal(req.xhr, req.isXMLHttpRequest);21+ res.send(req.isXMLHttpRequest22+ ? 'yeaaa boy'23+ : 'nope');24+ });25 33- 'test #header()': function(assert){34- 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' });26+ assert.response(app,27+ { url: '/isxhr' },28+ { body: 'nope' });45- },29 47- 'test #accepts()': function(assert){48- 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- 67- 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'));72- assert.strictEqual(false, req.accepts('png'));73- assert.strictEqual(false, req.accepts('image/png'));74- res.send('ok'); 75- });76- 77- assert.response(app,78- { url: '/all', headers: { Accept: '*/*' }},79- { body: 'ok' });80- assert.response(app,81- { url: '/type', headers: { Accept: 'text/*; application/*' }},82- { body: 'ok' });83- assert.response(app,84- { url: '/', headers: { Accept: 'text/html; application/json; text/*' }},85- { body: 'ok' });86- },30+ 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();37 88- 'test #param()': function(assert){89- 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' });112- },38+ 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+ });43 44+ 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;54+ req.accepts('json').should.be.true;55+ res.send('ok');56+ });57+ 58+ app.get('/', function(req, res){59+ req.accepts('html').should.be.true;60+ req.accepts('text/html').should.be.true;61+ req.accepts('text/*').should.be.true;62+ req.accepts('json').should.be.true;63+ req.accepts('application/json').should.be.true;64+ 65+ req.accepts('xml').should.be.false;66+ req.accepts('image/*').should.be.false;67+ req.accepts('png').should.be.false;68+ req.accepts().should.be.false;69+ res.send('ok');70+ });71+ 72+ app.get('/type', function(req, res){73+ req.accepts('html').should.be.true;74+ req.accepts('text/html').should.be.true;75+ req.accepts('json').should.be.true;76+ req.accepts('application/json').should.be.true;77+ 78+ req.accepts('png').should.be.false;79+ req.accepts('image/png').should.be.false;80+ res.send('ok'); 81+ });82+ 83+ assert.response(app,84+ { url: '/all', headers: { Accept: '*/*' }},85+ { body: 'ok' });86+ assert.response(app,87+ { url: '/type', headers: { Accept: 'text/*; application/*' }},88+ { body: 'ok' });89+ assert.response(app,90+ { url: '/', headers: { Accept: 'text/html; application/json; text/*' }},91+ { body: 'ok' });92+ },93+ 94+ 'test #param()': function(){95+ var app = express.createServer(96+ connect.bodyDecoder()97+ );98+ 99+ app.get('/user/:id?', function(req, res){100+ res.send('user ' + req.param('id'));101+ });102+ 103+ app.post('/user', function(req, res){104+ res.send('user ' + req.param('id'));105+ });106+ 107+ assert.response(app,108+ { url: '/user/12' },109+ { body: 'user 12' });110+ 111+ assert.response(app,112+ { url: '/user?id=5' },113+ { body: 'user 5' });114+ 115+ assert.response(app,116+ { url: '/user', method: 'POST', data: 'id=1', headers: { 'Content-Type': 'application/x-www-form-urlencoded' }},117+ { body: 'user 1' });118+ },119+ 114- 'test #flash()': function(assert){115- var app = express.createServer(116- connect.cookieDecoder(),117- connect.session({ store: memoryStore })118- );120+ 'test #flash()': function(){121+ var app = express.createServer(122+ connect.cookieDecoder(),123+ connect.session({ store: memoryStore })124+ );125 120- app.flashFormatters = {121- u: function(val){122- return String(val).toUpperCase();123- }124- };126+ app.flashFormatters = {127+ u: function(val){128+ return String(val).toUpperCase();129+ }130+ };131 126- app.get('/', function(req, res){127- assert.eql([], req.flash('info'));128- assert.eql([], req.flash('error'));129- assert.eql({}, req.flash());130- assert.eql({}, req.session.flash);131- 132- assert.equal(1, req.flash('info', 'one'));133- assert.equal(2, req.flash('info', 'two'));134- assert.eql(['one', 'two'], req.flash('info'));135- assert.eql([], req.flash('info'));132+ app.get('/', function(req, res){133+ req.flash('info').should.be.empty;134+ req.flash('error').should.be.empty;135+ req.flash().should.eql({});136+ req.session.flash.should.eql({});137 137- assert.equal(1, req.flash('info', 'one'));138- assert.eql({ info: ['one'] }, req.flash());139- 140- req.flash('info', 'Email _sent_.');141- req.flash('info', '<script>');142- assert.eql(['Email <em>sent</em>.', '<script>'], req.flash('info'));143- 144- req.flash('info', 'Welcome _%s_ to %s', 'TJ', 'something');145- assert.eql(['Welcome <em>TJ</em> to something'], req.flash('info'));138+ req.flash('info', 'one').should.equal(1);139+ req.flash('info', 'two').should.equal(2);140+ req.flash('info').should.eql(['one', 'two']);141+ req.flash('info').should.eql([]);142 147- req.flash('info', 'Foo %u', 'bar');148- assert.eql(['Foo BAR'], req.flash('info'));143+ req.flash('info', 'one').should.equal(1);144+ req.flash('info').should.eql(['one']);145 150- res.send('ok');151- });152- 153- assert.response(app,154- { url: '/' },155- { body: 'ok' });156- },146+ req.flash('info', 'Email _sent_.');147+ req.flash('info', '<script>');148+ req.flash('info').should.eql(['Email <em>sent</em>.', '<script>']);149+ 150+ req.flash('info', 'Welcome _%s_ to %s', 'TJ', 'something');151+ req.flash('info').should.eql(['Welcome <em>TJ</em> to something']);152+153+ req.flash('error', 'Foo %u', 'bar');154+ req.flash('error').should.eql(['Foo BAR']);155+156+ res.send('ok');157+ });158 159+ assert.response(app,160+ { url: '/' },161+ { body: 'ok' });162+ },163+ 158- 'test #is()': function(assert){159- var app = express.createServer();164+ 'test #is()': function(){165+ var app = express.createServer();166 161- app.is('an image', function(req){162- return 0 == req.headers['content-type'].indexOf('image');163- });164- 165- app.is('text', function(req){166- return 0 == req.headers['content-type'].indexOf('text');167- });167+ app.is('an image', function(req){168+ return 0 == req.headers['content-type'].indexOf('image');169+ });170+ 171+ app.is('text', function(req){172+ return 0 == req.headers['content-type'].indexOf('text');173+ });174 169- app.get('/', function(req, res, next){170- if (req.is('html')) return res.send('html');171- res.send('not sure');172- });173- 174- app.post('/', function(req, res, next){175- if (req.is('html')) return res.send('/ html');176- if (req.is('json')) return res.send('/ json');177- if (req.is('png')) return res.send('/ png');178- res.send('/ not sure');179- });180- 181- app.post('/long', function(req, res, next){182- if (req.is('text/html')) return res.send('/long html');183- if (req.is('application/json')) return res.send('/long json');184- if (req.is('image/png')) return res.send('/long png');185- res.send('/long not sure');186- });187- 188- app.put('/custom', function(req, res, next){189- if (req.is('an image')) return res.send('/custom an image');190- if (req.is('text')) return res.send('/custom text');191- });175+ app.get('/', function(req, res, next){176+ if (req.is('html')) return res.send('html');177+ res.send('not sure');178+ });179+ 180+ app.post('/', function(req, res, next){181+ if (req.is('html')) return res.send('/ html');182+ if (req.is('json')) return res.send('/ json');183+ if (req.is('png')) return res.send('/ png');184+ res.send('/ not sure');185+ });186+ 187+ app.post('/long', function(req, res, next){188+ if (req.is('text/html')) return res.send('/long html');189+ if (req.is('application/json')) return res.send('/long json');190+ if (req.is('image/png')) return res.send('/long png');191+ res.send('/long not sure');192+ });193+ 194+ app.put('/custom', function(req, res, next){195+ if (req.is('an image')) return res.send('/custom an image');196+ if (req.is('text')) return res.send('/custom text');197+ });198 193- assert.response(app,194- { url: '/' },195- { body: 'not sure' });199+ assert.response(app,200+ { url: '/' },201+ { body: 'not sure' });202 197- assert.response(app,198- { url: '/', method: 'POST', headers: { 'Content-Type': 'text/html' }},199- { body: '/ html' });200- assert.response(app,201- { url: '/', method: 'POST', headers: { 'Content-Type': 'application/json; charset=utf-8' }},202- { body: '/ json' });203- assert.response(app,204- { url: '/', method: 'POST', headers: { 'Content-Type': 'image/png' }},205- { body: '/ png' });206- assert.response(app,207- { url: '/', method: 'POST' },208- { body: '/ not sure' });203+ assert.response(app,204+ { url: '/', method: 'POST', headers: { 'Content-Type': 'text/html' }},205+ { body: '/ html' });206+ assert.response(app,207+ { url: '/', method: 'POST', headers: { 'Content-Type': 'application/json; charset=utf-8' }},208+ { body: '/ json' });209+ assert.response(app,210+ { url: '/', method: 'POST', headers: { 'Content-Type': 'image/png' }},211+ { body: '/ png' });212+ assert.response(app,213+ { url: '/', method: 'POST' },214+ { body: '/ not sure' });215 210- assert.response(app,211- { url: '/long', method: 'POST', headers: { 'Content-Type': 'text/html' }},212- { body: '/long html' });213- assert.response(app,214- { url: '/long', method: 'POST', headers: { 'Content-Type': 'application/json; charset=utf-8' }},215- { body: '/long json' });216- assert.response(app,217- { url: '/long', method: 'POST', headers: { 'Content-Type': 'image/png' }},218- { body: '/long png' });219- assert.response(app,220- { url: '/long', method: 'POST' },221- { body: '/long not sure' });222- 223- assert.response(app,224- { url: '/custom', method: 'PUT', headers: { 'Content-Type': 'text/plain' }},225- { body: '/custom text' });226- assert.response(app,227- { url: '/custom', method: 'PUT', headers: { 'Content-Type': 'text/html' }},228- { body: '/custom text' });229- assert.response(app,230- { url: '/custom', method: 'PUT', headers: { 'Content-Type': 'image/jpeg' }},231- { body: '/custom an image' });232- assert.response(app,233- { url: '/custom', method: 'PUT', headers: { 'Content-Type': 'image/png' }},234- { body: '/custom an image' });235- },216+ assert.response(app,217+ { url: '/long', method: 'POST', headers: { 'Content-Type': 'text/html' }},218+ { body: '/long html' });219+ assert.response(app,220+ { url: '/long', method: 'POST', headers: { 'Content-Type': 'application/json; charset=utf-8' }},221+ { body: '/long json' });222+ assert.response(app,223+ { url: '/long', method: 'POST', headers: { 'Content-Type': 'image/png' }},224+ { body: '/long png' });225+ assert.response(app,226+ { url: '/long', method: 'POST' },227+ { body: '/long not sure' });228 229+ assert.response(app,230+ { url: '/custom', method: 'PUT', headers: { 'Content-Type': 'text/plain' }},231+ { body: '/custom text' });232+ assert.response(app,233+ { url: '/custom', method: 'PUT', headers: { 'Content-Type': 'text/html' }},234+ { body: '/custom text' });235+ assert.response(app,236+ { url: '/custom', method: 'PUT', headers: { 'Content-Type': 'image/jpeg' }},237+ { body: '/custom an image' });238+ assert.response(app,239+ { url: '/custom', method: 'PUT', headers: { 'Content-Type': 'image/png' }},240+ { body: '/custom an image' });241+ },242+ 237- 'test #is() wildcard': function(assert){238- var app = express.createServer();243+ 'test #is() wildcard': function(){244+ var app = express.createServer();245 240- app.post('/', function(req, res, next){241- if (req.is('image/*')) return res.send('image');242- if (req.is('*/json')) return res.send('json');243- res.send('not sure');244- });246+ app.post('/', function(req, res, next){247+ if (req.is('image/*')) return res.send('image');248+ if (req.is('*/json')) return res.send('json');249+ res.send('not sure');250+ });251 246- assert.response(app,247- { url: '/', method: 'POST', headers: { 'Content-Type': 'image/png' }},248- { body: 'image' });249- assert.response(app,250- { url: '/', method: 'POST', headers: { 'Content-Type': 'image/jpeg' }},251- { body: 'image' });252- assert.response(app,253- { url: '/', method: 'POST', headers: { 'Content-Type': 'text/plain' }},254- { body: 'not sure' });255- assert.response(app,256- { url: '/', method: 'POST', headers: { 'Content-Type': 'text/json' }},257- { body: 'json' });258- assert.response(app,259- { url: '/', method: 'POST', headers: { 'Content-Type': 'application/json' }},260- { body: 'json' });261- }252+ assert.response(app,253+ { url: '/', method: 'POST', headers: { 'Content-Type': 'image/png' }},254+ { body: 'image' });255+ assert.response(app,256+ { url: '/', method: 'POST', headers: { 'Content-Type': 'image/jpeg' }},257+ { body: 'image' });258+ assert.response(app,259+ { url: '/', method: 'POST', headers: { 'Content-Type': 'text/plain' }},260+ { body: 'not sure' });261+ assert.response(app,262+ { url: '/', method: 'POST', headers: { 'Content-Type': 'text/json' }},263+ { body: 'json' });264+ assert.response(app,265+ { url: '/', method: 'POST', headers: { 'Content-Type': 'application/json' }},266+ { body: 'json' });267+ }268 };modified:test/response.test.js+365 added-365 removed
1 unmodified line2 /**3 * Module dependencies.4 */5 6-var express = require('express'),7- Buffer = require('buffer').Buffer;6+var express = require('express')7+ , Buffer = require('buffer').Buffer8+ , assert = require('assert')9+ , should = require('should');10 11 module.exports = {10- 'test #send()': function(assert){11- var app = express.createServer();12+ 'test #send()': function(){13+ var app = express.createServer();14 13- 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('/jsonp', function(req, res){23- app.enable('jsonp callback');24- res.header('X-Foo', 'bar');25- res.send({ foo: 'bar' }, { 'X-Foo': 'baz' }, 201);26- app.disable('jsonp callback');27- });28- 29- app.get('/text', function(req, res){30- res.header('X-Foo', 'bar');31- res.contentType('.txt');32- res.send('wahoo');33- });34- 35- app.get('/status', function(req, res){36- res.send(404);37- });38- 39- app.get('/error', function(req, res){40- res.send('Oh shit!', { 'Content-Type': 'text/plain' }, 500);41- });42- 43- app.get('/buffer', function(req, res){44- res.send(new Buffer('wahoo!'));45- });46- 47- app.get('/noargs', function(req, res, next){48- res.send();49- });15+ app.get('/html', function(req, res){16+ res.send('<p>test</p>', { 'Content-Language': 'en' });17+ });18+ 19+ app.get('/json', function(req, res){20+ res.header('X-Foo', 'bar');21+ res.send({ foo: 'bar' }, { 'X-Foo': 'baz' }, 201);22+ });23+ 24+ app.get('/jsonp', function(req, res){25+ app.enable('jsonp callback');26+ res.header('X-Foo', 'bar');27+ res.send({ foo: 'bar' }, { 'X-Foo': 'baz' }, 201);28+ app.disable('jsonp callback');29+ });30+ 31+ app.get('/text', function(req, res){32+ res.header('X-Foo', 'bar');33+ res.contentType('.txt');34+ res.send('wahoo');35+ });36+ 37+ app.get('/status', function(req, res){38+ res.send(404);39+ });40+ 41+ app.get('/error', function(req, res){42+ res.send('Oh shit!', { 'Content-Type': 'text/plain' }, 500);43+ });44+ 45+ app.get('/buffer', function(req, res){46+ res.send(new Buffer('wahoo!'));47+ });48+ 49+ app.get('/noargs', function(req, res, next){50+ res.send();51+ });52 51- assert.response(app,52- { url: '/html' },53- { body: '<p>test</p>', headers: { 'Content-Language': 'en', 'Content-Type': 'text/html; charset=utf-8' }});54- assert.response(app,55- { url: '/json' },56- { body: '{"foo":"bar"}', status: 201, headers: { 'Content-Type': 'application/json', 'X-Foo': 'baz' }});53+ assert.response(app,54+ { url: '/html' },55+ { body: '<p>test</p>', headers: { 'Content-Language': 'en', 'Content-Type': 'text/html; charset=utf-8' }});56+ assert.response(app,57+ { url: '/json' },58+ { body: '{"foo":"bar"}', status: 201, headers: { 'Content-Type': 'application/json', 'X-Foo': 'baz' }});59 58- assert.response(app,59- { url: '/jsonp?callback=test' },60- { body: 'test({"foo":"bar"});', status: 201, headers: { 'Content-Type': 'text/javascript', 'X-Foo': 'baz' }});60+ assert.response(app,61+ { url: '/jsonp?callback=test' },62+ { body: 'test({"foo":"bar"});', status: 201, headers: { 'Content-Type': 'text/javascript', 'X-Foo': 'baz' }});63 62- assert.response(app,63- { url: '/jsonp?callback=baz' },64- { body: 'baz({"foo":"bar"});', status: 201, headers: { 'Content-Type': 'text/javascript', 'X-Foo': 'baz' }});64+ assert.response(app,65+ { url: '/jsonp?callback=baz' },66+ { body: 'baz({"foo":"bar"});', status: 201, headers: { 'Content-Type': 'text/javascript', 'X-Foo': 'baz' }});67 66- assert.response(app,67- { url: '/json?callback=test' },68- { body: '{"foo":"bar"}', status: 201, headers: { 'Content-Type': 'application/json', 'X-Foo': 'baz' }});68+ assert.response(app,69+ { url: '/json?callback=test' },70+ { body: '{"foo":"bar"}', status: 201, headers: { 'Content-Type': 'application/json', 'X-Foo': 'baz' }});71 70- assert.response(app,71- { url: '/text' },72- { body: 'wahoo', headers: { 'Content-Type': 'text/plain; charset=utf-8', 'X-Foo': 'bar' }});73- assert.response(app,74- { url: '/status' },75- { body: 'Not Found', status: 404, headers: { 'Content-Type': 'text/plain; charset=utf-8' }});76- assert.response(app,77- { url: '/error' },78- { body: 'Oh shit!', status: 500, headers: { 'Content-Type': 'text/plain' }});79- assert.response(app,80- { url: '/buffer' },81- { body: 'wahoo!', headers: { 'Content-Type': 'application/octet-stream' }});82- assert.response(app,83- { url: '/noargs' },84- { status: 204 }, function(res){85- assert.equal(undefined, res.headers['content-type']);86- assert.equal(undefined, res.headers['content-length']);87- });88- },72+ assert.response(app,73+ { url: '/text' },74+ { body: 'wahoo', headers: { 'Content-Type': 'text/plain; charset=utf-8', 'X-Foo': 'bar' }});75+ assert.response(app,76+ { url: '/status' },77+ { body: 'Not Found', status: 404, headers: { 'Content-Type': 'text/plain; charset=utf-8' }});78+ assert.response(app,79+ { url: '/error' },80+ { body: 'Oh shit!', status: 500, headers: { 'Content-Type': 'text/plain' }});81+ assert.response(app,82+ { url: '/buffer' },83+ { body: 'wahoo!', headers: { 'Content-Type': 'application/octet-stream' }});84+ assert.response(app,85+ { url: '/noargs' },86+ { status: 204 }, function(res){87+ assert.equal(undefined, res.headers['content-type']);88+ assert.equal(undefined, res.headers['content-length']);89+ });90+ },91+ 92+ 'test #contentType()': function(){93+ var app = express.createServer();94 90- 'test #contentType()': function(assert){91- var app = express.createServer();92- 93- app.get('/html', function(req, res){94- res.contentType('index.html');95- res.writeHead(200, res.headers);96- res.end('<p>yay</p>');97- });95+ app.get('/html', function(req, res){96+ res.contentType('index.html');97+ res.writeHead(200, res.headers);98+ res.end('<p>yay</p>');99+ });98- 99- assert.response(app,100- { url: '/html' },101- { body: '<p>yay</p>', headers: { 'Content-Type': 'text/html; charset=utf-8' }});102- },100 101+ assert.response(app,102+ { url: '/html' },103+ { body: '<p>yay</p>', headers: { 'Content-Type': 'text/html; charset=utf-8' }});104+ },105+ 104- 'test #attachment()': function(assert){105- var app = express.createServer();106- 107- app.get('/style.css', function(req, res){108- res.attachment();109- res.send('some stylezzz');110- });106+ 'test #attachment()': function(){107+ var app = express.createServer();108+ 109+ app.get('/style.css', function(req, res){110+ res.attachment();111+ res.send('some stylezzz');112+ });113 112- app.get('/*', function(req, res){113- res.attachment(req.params[0]);114- res.send('whatever');115- });116- 117- assert.response(app,118- { url: '/javascripts/jquery.js' },119- { body: 'whatever', headers: { 'Content-Disposition': 'attachment; filename="jquery.js"' }});120- assert.response(app,121- { url: '/style.css' },122- { body: 'some stylezzz', headers: { 'Content-Disposition': 'attachment' }});123- },114+ app.get('/*', function(req, res){115+ res.attachment(req.params[0]);116+ res.send('whatever');117+ });118 119+ assert.response(app,120+ { url: '/javascripts/jquery.js' },121+ { body: 'whatever', headers: { 'Content-Disposition': 'attachment; filename="jquery.js"' }});122+ assert.response(app,123+ { url: '/style.css' },124+ { body: 'some stylezzz', headers: { 'Content-Disposition': 'attachment' }});125+ },126+ 125- 'test #redirect()': function(assert){126- var app = express.createServer(),127- app2 = express.createServer();128- 129- app2.set('home', '/blog');127+ 'test #redirect()': function(){128+ var app = express.createServer()129+ , app2 = express.createServer();130+ 131+ app2.set('home', '/blog');132 131- app2.redirect('google', 'http://google.com');133+ app2.redirect('google', 'http://google.com');134 133- app2.redirect('blog', function(req, res){134- return req.params.id135- ? '/user/' + req.params.id + '/blog'136- : null;137- });138- 139- app.get('/', function(req, res){140- res.redirect('http://google.com', 301);141- });142- 143- app.get('/back', function(req, res){144- res.redirect('back');145- });146- 147- app.get('/home', function(req, res){148- res.redirect('home');149- });150- 151- app.get('/html', function(req, res){152- res.redirect('http://google.com');153- });154- 155- app2.get('/', function(req, res){156- res.redirect('http://google.com', 301);157- });158- 159- app2.get('/back', function(req, res){160- res.redirect('back');161- });162- 163- app2.get('/home', function(req, res){164- res.redirect('home');165- });166- 167- app2.get('/google', function(req, res){168- res.redirect('google');169- });135+ app2.redirect('blog', function(req, res){136+ return req.params.id137+ ? '/user/' + req.params.id + '/blog'138+ : null;139+ });140+ 141+ app.get('/', function(req, res){142+ res.redirect('http://google.com', 301);143+ });144+ 145+ app.get('/back', function(req, res){146+ res.redirect('back');147+ });148+ 149+ app.get('/home', function(req, res){150+ res.redirect('home');151+ });152+ 153+ app.get('/html', function(req, res){154+ res.redirect('http://google.com');155+ });156+ 157+ app2.get('/', function(req, res){158+ res.redirect('http://google.com', 301);159+ });160+ 161+ app2.get('/back', function(req, res){162+ res.redirect('back');163+ });164+ 165+ app2.get('/home', function(req, res){166+ res.redirect('home');167+ });168+ 169+ app2.get('/google', function(req, res){170+ res.redirect('google');171+ });172 171- app2.get('/user/:id', function(req, res){172- res.header('X-Foo', 'bar');173- res.redirect('blog');174- });173+ app2.get('/user/:id', function(req, res){174+ res.header('X-Foo', 'bar');175+ res.redirect('blog');176+ });177 178 177- assert.response(app,178- { url: '/html', headers: { Accept: 'text/html,text/plain' }},179- { body: '<p>Moved Temporarily. Redirecting to <a href="http://google.com">http://google.com</a></p>' });180- assert.response(app,181- { url: '/', headers: { Accept: 'text/plain' }},182- { body: 'Moved Permanently. Redirecting to http://google.com', status: 301, headers: { Location: 'http://google.com' }});183- assert.response(app,184- { url: '/back', headers: { Accept: 'text/plain' }},185- { body: 'Moved Temporarily. Redirecting to /', status: 302, headers: { Location: '/', 'Content-Type': 'text/plain' }});186- assert.response(app,187- { url: '/back', headers: { Referer: '/foo', Accept: 'text/plain' }},188- { body: 'Moved Temporarily. Redirecting to /foo', status: 302, headers: { Location: '/foo' }});189- assert.response(app,190- { url: '/back', headers: { Referrer: '/foo', Accept: 'text/plain' }},191- { body: 'Moved Temporarily. Redirecting to /foo', status: 302, headers: { Location: '/foo' }});192- assert.response(app,193- { url: '/home', headers: { Accept: 'text/plain' } },194- { body: 'Moved Temporarily. Redirecting to /', status: 302, headers: { Location: '/' }});179+ assert.response(app,180+ { url: '/html', headers: { Accept: 'text/html,text/plain' }},181+ { body: '<p>Moved Temporarily. Redirecting to <a href="http://google.com">http://google.com</a></p>' });182+ assert.response(app,183+ { url: '/', headers: { Accept: 'text/plain' }},184+ { body: 'Moved Permanently. Redirecting to http://google.com', status: 301, headers: { Location: 'http://google.com' }});185+ assert.response(app,186+ { url: '/back', headers: { Accept: 'text/plain' }},187+ { body: 'Moved Temporarily. Redirecting to /', status: 302, headers: { Location: '/', 'Content-Type': 'text/plain' }});188+ assert.response(app,189+ { url: '/back', headers: { Referer: '/foo', Accept: 'text/plain' }},190+ { body: 'Moved Temporarily. Redirecting to /foo', status: 302, headers: { Location: '/foo' }});191+ assert.response(app,192+ { url: '/back', headers: { Referrer: '/foo', Accept: 'text/plain' }},193+ { body: 'Moved Temporarily. Redirecting to /foo', status: 302, headers: { Location: '/foo' }});194+ assert.response(app,195+ { url: '/home', headers: { Accept: 'text/plain' } },196+ { body: 'Moved Temporarily. Redirecting to /', status: 302, headers: { Location: '/' }});197 196- assert.response(app2,197- { url: '/', headers: { Accept: 'text/plain' }},198- { body: 'Moved Permanently. Redirecting to http://google.com', status: 301, headers: { Location: 'http://google.com' }});199- assert.response(app2,200- { url: '/back', headers: { Accept: 'text/plain' }},201- { body: 'Moved Temporarily. Redirecting to /blog', status: 302, headers: { Location: '/blog' }});202- assert.response(app2,203- { url: '/home', headers: { Accept: 'text/plain' }},204- { body: 'Moved Temporarily. Redirecting to /blog', status: 302, headers: { Location: '/blog' }});205- assert.response(app2,206- { url: '/google', headers: { Accept: 'text/plain' }},207- { body: 'Moved Temporarily. Redirecting to http://google.com', status: 302, headers: { Location: 'http://google.com' }});208- assert.response(app2,209- { url: '/user/12', headers: { Accept: 'text/plain' }},210- { body: 'Moved Temporarily. Redirecting to /user/12/blog', status: 302, headers: { Location: '/user/12/blog', 'X-Foo': 'bar' }});211- },198+ assert.response(app2,199+ { url: '/', headers: { Accept: 'text/plain' }},200+ { body: 'Moved Permanently. Redirecting to http://google.com', status: 301, headers: { Location: 'http://google.com' }});201+ assert.response(app2,202+ { url: '/back', headers: { Accept: 'text/plain' }},203+ { body: 'Moved Temporarily. Redirecting to /blog', status: 302, headers: { Location: '/blog' }});204+ assert.response(app2,205+ { url: '/home', headers: { Accept: 'text/plain' }},206+ { body: 'Moved Temporarily. Redirecting to /blog', status: 302, headers: { Location: '/blog' }});207+ assert.response(app2,208+ { url: '/google', headers: { Accept: 'text/plain' }},209+ { body: 'Moved Temporarily. Redirecting to http://google.com', status: 302, headers: { Location: 'http://google.com' }});210+ assert.response(app2,211+ { url: '/user/12', headers: { Accept: 'text/plain' }},212+ { body: 'Moved Temporarily. Redirecting to /user/12/blog', status: 302, headers: { Location: '/user/12/blog', 'X-Foo': 'bar' }});213+ },214+ 215+ 'test #sendfile()': function(){216+ var app = express.createServer();217+218+ app.set('stream threshold', 2 * 1024)219+220+ app.get('/*', function(req, res, next){221+ var file = req.params[0]222+ , filePath = __dirname + '/fixtures/' + file;223+ res.sendfile(filePath, function(err, path){224+ assert.equal(path, filePath);225+ if (err) next(err);226+ });227+ });228 213- 'test #sendfile()': function(assert){214- var app = express.createServer();229+ app.use(express.errorHandler());230 231+ assert.response(app,232+ { url: '/../express.test.js' },233+ { body: 'Forbidden', status: 403 });234+ assert.response(app,235+ { url: '/user.json' },236+ { body: '{"name":"tj"}', status: 200, headers: { 'Content-Type': 'application/json' }});237+ assert.response(app,238+ { url: '/hello.haml' },239+ { body: '%p Hello World', status: 200, headers: { 'Content-Type': 'application/octet-stream' }});240+ assert.response(app,241+ { url: '/doesNotExist' },242+ { body: 'Internal Server Error', status: 500 });243+ assert.response(app,244+ { url: '/partials' },245+ { body: 'Internal Server Error', status: 500 });246+ assert.response(app,247+ { url: '/large.json' },248+ { status: 200, headers: { 'Content-Type': 'application/json' }});249+ },250+ 251+ 'test #sendfile() Accept-Ranges': function(){252+ var app = express.createServer();253+ 216- app.set('stream threshold', 2 * 1024)254+ app.set('stream threshold', 1024);255+ 256+ app.get('/*', function(req, res, next){257+ var file = req.params[0]258+ , path = __dirname + '/fixtures/' + file;259+ res.sendfile(path);260+ });261+ 262+ assert.response(app,263+ { url: '/large.json' },264+ { headers: { 'Accept-Ranges': 'bytes' }});265+ },266+ 267+ 'test #sendfile() Range': function(){268+ var app = express.createServer();269+ 270+ app.set('stream threshold', 1024);271+ 272+ app.get('/*', function(req, res, next){273+ var file = req.params[0]274+ , path = __dirname + '/fixtures/' + file;275+ res.sendfile(path);276+ });277 218- app.get('/*', function(req, res, next){219- var file = req.params[0],220- filePath = __dirname + '/fixtures/' + file;221- res.sendfile(filePath, function(err, path){222- assert.equal(path, filePath);223- if (err) next(err);224- });225- });226- 227- app.use(express.errorHandler());278+ assert.response(app,279+ { url: '/large.json', headers: { 'Range': 'bytes=0-499' }},280+ { headers: {281+ 'Content-Type': 'application/json',282+ 'Content-Range': 'bytes 0-499/2535'283+ }, status: 206 });284+ },285 229- assert.response(app,230- { url: '/../express.test.js' },231- { body: 'Forbidden', status: 403 });232- assert.response(app,233- { url: '/user.json' },234- { body: '{"name":"tj"}', status: 200, headers: { 'Content-Type': 'application/json' }});235- assert.response(app,236- { url: '/hello.haml' },237- { body: '%p Hello World', status: 200, headers: { 'Content-Type': 'application/octet-stream' }});238- assert.response(app,239- { url: '/doesNotExist' },240- { body: 'Internal Server Error', status: 500 });241- assert.response(app,242- { url: '/partials' },243- { body: 'Internal Server Error', status: 500 });244- assert.response(app,245- { url: '/large.json' },246- { status: 200, headers: { 'Content-Type': 'application/json' }});247- },286+ 'test #sendfile() Range invalid syntax': function(){287+ var app = express.createServer();288 249- 'test #sendfile() Accept-Ranges': function(assert){250- var app = express.createServer();251- 252- app.set('stream threshold', 1024);289+ app.set('stream threshold', 1024);253- 254- app.get('/*', function(req, res, next){255- var file = req.params[0],256- path = __dirname + '/fixtures/' + file;257- res.sendfile(path);258- });259- 260- assert.response(app,261- { url: '/large.json' },262- { headers: { 'Accept-Ranges': 'bytes' }});263- },290 265- 'test #sendfile() Range': function(assert){266- var app = express.createServer();267- 268- app.set('stream threshold', 1024);269- 270- app.get('/*', function(req, res, next){271- var file = req.params[0],272- path = __dirname + '/fixtures/' + file;273- res.sendfile(path);274- });291+ app.get('/*', function(req, res, next){292+ var file = req.params[0]293+ , path = __dirname + '/fixtures/' + file;294+ res.sendfile(path);295+ });296 276- assert.response(app,277- { url: '/large.json', headers: { 'Range': 'bytes=0-499' }},278- { headers: {279- 'Content-Type': 'application/json',280- 'Content-Range': 'bytes 0-499/2535'281- }, status: 206 });282- },297+ assert.response(app,298+ { url: '/large.json', headers: { 'Range': 'basdytes=asdf' }},299+ { headers: {300+ 'Content-Type': 'application/json'301+ }, status: 200 });302+ },303 284- 'test #sendfile() Range invalid syntax': function(assert){285- var app = express.createServer();286- 287- app.set('stream threshold', 1024);288- 289- app.get('/*', function(req, res, next){290- var file = req.params[0],291- path = __dirname + '/fixtures/' + file;292- res.sendfile(path);293- });304+ 'test #sendfile() Range invalid range': function(){305+ var app = express.createServer();306+ 307+ app.set('stream threshold', 1024);308+ 309+ app.get('/*', function(req, res, next){310+ var file = req.params[0]311+ , path = __dirname + '/fixtures/' + file;312+ res.sendfile(path);313+ });314 295- assert.response(app,296- { url: '/large.json', headers: { 'Range': 'basdytes=asdf' }},297- { headers: {298- 'Content-Type': 'application/json'299- }, status: 200 });300- },315+ assert.response(app,316+ { url: '/large.json', headers: { 'Range': 'bytes=500-10' }},317+ { headers: {318+ 'Content-Type': 'application/json'319+ }, status: 200 });320+ },321 302- 'test #sendfile() Range invalid range': function(assert){303- var app = express.createServer();304- 305- app.set('stream threshold', 1024);306- 307- app.get('/*', function(req, res, next){308- var file = req.params[0],309- path = __dirname + '/fixtures/' + file;310- res.sendfile(path);311- });322+ 'test #download()': function(){323+ var app = express.createServer();324+ 325+ app.get('/json', function(req, res, next){326+ var filePath = __dirname + '/fixtures/user.json';327+ res.download(filePath, 'account.json', function(err, path){328+ assert.equal(filePath, path);329+ });330+ });331 313- assert.response(app,314- { url: '/large.json', headers: { 'Range': 'bytes=500-10' }},315- { headers: {316- 'Content-Type': 'application/json'317- }, status: 200 });318- },332+ app.get('/*', function(req, res, next){333+ res.download(__dirname + '/fixtures/' + req.params[0]);334+ });335 320- 'test #download()': function(assert){321- var app = express.createServer();322- 323- app.get('/json', function(req, res, next){324- var filePath = __dirname + '/fixtures/user.json';325- res.download(filePath, 'account.json', function(err, path){326- assert.equal(filePath, path);327- });328- });336+ app.error(function(err, req, res){337+ res.send(404);338+ })339+ 340+ assert.response(app,341+ { url: '/user.json' },342+ { body: '{"name":"tj"}', status: 200, headers: {343+ 'Content-Type': 'application/json',344+ 'Content-Disposition': 'attachment; filename="user.json"'345+ }});346 330- app.get('/*', function(req, res, next){331- res.download(__dirname + '/fixtures/' + req.params[0]);332- });333- 334- app.error(function(err, req, res){335- res.send(404);336- })337- 338- assert.response(app,339- { url: '/user.json' },340- { body: '{"name":"tj"}', status: 200, headers: {341- 'Content-Type': 'application/json',342- 'Content-Disposition': 'attachment; filename="user.json"'343- }});344-345- assert.response(app,346- { url: '/json' },347- { body: '{"name":"tj"}', status: 200, headers: {348- 'Content-Type': 'application/json',349- 'Content-Length': '13',350- 'Content-Disposition': 'attachment; filename="account.json"'351- }});347+ assert.response(app,348+ { url: '/json' },349+ { body: '{"name":"tj"}', status: 200, headers: {350+ 'Content-Type': 'application/json',351+ 'Content-Length': '13',352+ 'Content-Disposition': 'attachment; filename="account.json"'353+ }});352- 353- assert.response(app,354- { url: '/missing' },355- function(res){356- assert.equal(null, res.headers['content-disposition']);357- });358- },354 360- 'test #cookie()': function(assert){361- var app = express.createServer();362- 363- app.get('/', function(req, res){364- res.cookie('rememberme', 'yes', { expires: new Date(1), httpOnly: true });365- res.redirect('/');366- });367- 368- assert.response(app,369- { url: '/' },370- function(res){371- assert.equal(372- 'rememberme=yes; expires=Thu, 01 Jan 1970 00:00:00 GMT; httpOnly',373- res.headers['set-cookie']);374- });375- },355+ assert.response(app,356+ { url: '/missing' },357+ function(res){358+ assert.equal(null, res.headers['content-disposition']);359+ });360+ },361+ 362+ 'test #cookie()': function(){363+ var app = express.createServer();364 377- 'test #clearCookie()': function(assert){378- var app = express.createServer();379- 380- app.get('/', function(req, res){381- res.clearCookie('rememberme');382- res.redirect('/');383- });365+ app.get('/', function(req, res){366+ res.cookie('rememberme', 'yes', { expires: new Date(1), httpOnly: true });367+ res.redirect('/');368+ });384- 385- assert.response(app,386- { url: '/' },387- function(res){388- assert.equal(389- 'rememberme=; expires=Thu, 01 Jan 1970 00:00:00 GMT',390- res.headers['set-cookie']);391- });392- },369 370+ assert.response(app,371+ { url: '/' },372+ function(res){373+ res.headers['set-cookie']374+ .should.equal('rememberme=yes; expires=Thu, 01 Jan 1970 00:00:00 GMT; httpOnly');375+ });376+ },377+ 378+ 'test #clearCookie()': function(){379+ var app = express.createServer();380+ 381+ app.get('/', function(req, res){382+ res.clearCookie('rememberme');383+ res.redirect('/');384+ });385+ 386+ assert.response(app,387+ { url: '/' },388+ function(res){389+ res.headers['set-cookie']390+ .should.equal('rememberme=; expires=Thu, 01 Jan 1970 00:00:00 GMT');391+ });392+ },393+ 394- 'test HEAD': function(assert){395- var app = express.createServer();396- 397- app.get('/', function(req, res, next){398- res.send('Hello World');399- });400- 401- assert.response(app,402- { url: '/', method: 'HEAD' },403- { body: '', headers: { 'Content-Length': 11 }});404- }394+ 'test HEAD': function(){395+ var app = express.createServer();396+ 397+ app.get('/', function(req, res, next){398+ res.send('Hello World');399+ });400+ 401+ assert.response(app,402+ { url: '/', method: 'HEAD' },403+ { body: '', headers: { 'Content-Length': 11 }});404+ }405 };modified:test/utils.test.js+21 added-18 removed
12345667899101112131415161718192021222324251011121314151617181920212223242526272829
/** * Module dependencies. */
var utils = require('express/utils');var utils = require('express/utils') , should = require('should');
module.exports = { 'test .miniMarkdown()': function(assert){ assert.equal('<em>foo</em>', utils.miniMarkdown('_foo_')); assert.equal('<em>foo</em>', utils.miniMarkdown('*foo*')); assert.equal('<strong>foo</strong>', utils.miniMarkdown('**foo**')); assert.equal('<strong>foo</strong>', utils.miniMarkdown('__foo__')); assert.equal('<em>foo</em>_', utils.miniMarkdown('_foo__')); assert.equal('<a href="/login">User Login</a>', utils.miniMarkdown('[User Login](/login)')); }, 'test .parseRange()': function(assert){ assert.eql([{start: 0, end: 499 }], utils.parseRange(1000, 'bytes=0-499')); assert.eql([{start: 40, end: 80 }], utils.parseRange(1000, 'bytes=40-80')); assert.eql([{start: 500, end: 999 }], utils.parseRange(1000, 'bytes=-500')); assert.eql([{start: 500, end: 999 }], utils.parseRange(1000, 'bytes=500-')); assert.eql([{start: 0, end: 0 }], utils.parseRange(1000, 'bytes=0-0')); assert.eql([{start: 999, end: 999 }], utils.parseRange(1000, 'bytes=-1')); } 'test .miniMarkdown()': function(){ utils.miniMarkdown('_foo_').should.equal('<em>foo</em>'); utils.miniMarkdown('*foo*').should.equal('<em>foo</em>'); utils.miniMarkdown('**foo**').should.equal('<strong>foo</strong>'); utils.miniMarkdown('__foo__').should.equal('<strong>foo</strong>'); utils.miniMarkdown('_foo__').should.equal('<em>foo</em>_'); utils.miniMarkdown('[User Login](/login)').should.equal('<a href="/login">User Login</a>'); }, 'test .parseRange()': function(){ utils.parseRange(1000, 'bytes=0-499').should.eql([{ start: 0, end: 499 }]); utils.parseRange(1000, 'bytes=40-80').should.eql([{ start: 40, end: 80 }]); utils.parseRange(1000, 'bytes=-500').should.eql([{ start: 500, end: 999 }]); utils.parseRange(1000, 'bytes=-400').should.eql([{ start: 600, end: 999 }]); utils.parseRange(1000, 'bytes=500-').should.eql([{ start: 500, end: 999 }]); utils.parseRange(1000, 'bytes=400-').should.eql([{ start: 400, end: 999 }]); utils.parseRange(1000, 'bytes=0-0').should.eql([{ start: 0, end: 0 }]); utils.parseRange(1000, 'bytes=-1').should.eql([{ start: 999, end: 999 }]); }};No newline at end of fileNo newline at end of filemodified:test/view.test.js+621 added-605 removed
1 unmodified line2 /**3 * Module dependencies.4 */5 6-var express = require('express'),7- connect = require('connect'),8- view = require('express/view');6+var express = require('express')7+ , connect = require('connect')8+ , assert = require('assert')9+ , should = require('should')10+ , view = require('express/view');11 12+/**13+ * Create a test server with views set to ./fixtures.14+ */15+16 var create = function(){11- var app = express.createServer.apply(express, arguments);12- app.set('views', __dirname + '/fixtures');13- return app;17+ var app = express.createServer.apply(express, arguments);18+ app.set('views', __dirname + '/fixtures');19+ return app;20 };21 22 module.exports = {17- 'test #render()': function(assert){18- var app = create();19- app.set('view engine', 'jade');23+ 'test #render()': function(){24+ var app = create();25+ app.set('view engine', 'jade');26 21- app.get('/', function(req, res){22- res.render('index.jade', { layout: false });23- });24- app.get('/jade', function(req, res){25- res.render('index', { layout: false });26- });27- app.get('/haml', function(req, res){28- res.render('hello.haml', { layout: false });29- });30- app.get('/callback/layout/no-options', function(req, res){31- res.render('hello.jade', function(err, str){32- assert.ok(!err);33- res.send(str.replace(':(', ':)'));34- });35- });36- app.get('/callback/layout', function(req, res){37- res.render('hello.jade', {}, function(err, str){38- assert.ok(!err);39- res.send(str.replace(':(', ':)'));40- });41- });42- app.get('/callback', function(req, res){43- res.render('hello.haml', { layout: false }, function(err, str){44- assert.ok(!err);45- res.send(str.replace('Hello World', ':)'));46- });47- });48- app.get('/invalid', function(req, res){49- res.render('invalid.jade', { layout: false });50- });51- app.get('/invalid-async', function(req, res){52- process.nextTick(function(){53- res.render('invalid.jade', { layout: false });54- });55- });56- app.get('/error', function(req, res){57- res.render('invalid.jade', { layout: false }, function(err){58- res.send(err.arguments[0]);59- });60- });61- app.get('/absolute', function(req, res){62- res.render(__dirname + '/fixtures/index.jade', { layout: false });63- });27+ app.get('/', function(req, res){28+ res.render('index.jade', { layout: false });29+ });30 65- assert.response(app,66- { url: '/' },67- { body: '<p>Welcome</p>', headers: { 'Content-Type': 'text/html; charset=utf-8' }});68- assert.response(app,69- { url: '/jade' },70- { body: '<p>Welcome</p>' });71- assert.response(app,72- { url: '/absolute' },73- { body: '<p>Welcome</p>' });74- assert.response(app,75- { url: '/haml' },76- { body: '\n<p>Hello World</p>' });77- assert.response(app,78- { url: '/callback' },79- { body: '\n<p>:)</p>' });80- assert.response(app,81- { url: '/callback/layout' },82- { body: '<html><body><p>:)</p></body></html>' });83- assert.response(app,84- { url: '/callback/layout/no-options' },85- { body: '<html><body><p>:)</p></body></html>' });86- assert.response(app,87- { url: '/error' },88- { body: 'doesNotExist' });89- assert.response(app,90- { url: '/invalid' },91- function(res){92- assert.ok(res.body.indexOf('ReferenceError') >= 0);93- assert.ok(res.body.indexOf('doesNotExist') >= 0);94- });95- assert.response(app,96- { url: '/invalid-async' },97- function(res){98- assert.ok(res.body.indexOf('ReferenceError') >= 0);99- assert.ok(res.body.indexOf('doesNotExist') >= 0);100- });31+ app.get('/jade', function(req, res){32+ res.render('index', { layout: false });33+ });34 102- },103- 104- 'test #render() layout': function(assert){105- var app = create();106- app.set('view engine', 'jade');35+ app.get('/haml', function(req, res){36+ res.render('hello.haml', { layout: false });37+ });38 108- app.get('/', function(req, res){109- res.render('index.jade');110- });111- app.get('/jade', function(req, res){112- res.render('index');113- });39+ app.get('/callback/layout/no-options', function(req, res){40+ res.render('hello.jade', function(err, str){41+ assert.ok(!err);42+ res.send(str.replace(':(', ':)'));43+ });44+ });45 115- assert.response(app,116- { url: '/' },117- { body: '<html><body><p>Welcome</p></body></html>' });118- },119- 120- 'test #render() specific layout': function(assert, beforeExit){121- var app = create(),122- called;46+ app.get('/callback/layout', function(req, res){47+ res.render('hello.jade', {}, function(err, str){48+ assert.ok(!err);49+ res.send(str.replace(':(', ':)'));50+ });51+ });52 124- app.get('/', function(req, res){125- res.render('index.jade', { layout: 'cool-layout.jade' }, function(err, html){126- called = true;127- res.send(html);128- });129- });130- app.get('/no-ext', function(req, res){131- res.render('index.jade', { layout: 'cool-layout' });132- });133- app.get('/relative', function(req, res){134- res.render('index.jade', { layout: 'layouts/foo.jade' });135- });136- app.get('/absolute', function(req, res){137- res.render('index.jade', { layout: __dirname + '/fixtures/layouts/foo.jade' });138- });139- app.get('/nope', function(req, res){140- res.render('index.jade', { layout: 'nope.jade' });141- });53+ app.get('/callback', function(req, res){54+ res.render('hello.haml', { layout: false }, function(err, str){55+ assert.ok(!err);56+ res.send(str.replace('Hello World', ':)'));57+ });58+ });59 143- assert.response(app,144- { url: '/' },145- { body: '<cool><p>Welcome</p></cool>' });146- assert.response(app,147- { url: '/no-ext' },148- { body: '<cool><p>Welcome</p></cool>' });149- assert.response(app,150- { url: '/relative' },151- { body: '<foo></foo>' });152- assert.response(app,153- { url: '/absolute' },154- { body: '<foo></foo>' });155- assert.response(app,156- { url: '/nope' },157- function(res){158- assert.ok(res.body.indexOf('Error: ENOENT') >= 0);159- assert.ok(res.body.indexOf('nope.jade') >= 0);160- });60+ app.get('/invalid', function(req, res){61+ res.render('invalid.jade', { layout: false });62+ });63 162- beforeExit(function(){163- assert.ok(called, 'Layout callback never called'); 64+ app.get('/invalid-async', function(req, res){65+ process.nextTick(function(){66+ res.render('invalid.jade', { layout: false });67+ });68+ });69+70+ app.get('/error', function(req, res){71+ res.render('invalid.jade', { layout: false }, function(err){72+ res.send(err.arguments[0]);73 });74+ });75+76+ app.get('/absolute', function(req, res){77+ res.render(__dirname + '/fixtures/index.jade', { layout: false });78+ });79+80+ assert.response(app,81+ { url: '/' },82+ { body: '<p>Welcome</p>', headers: { 'Content-Type': 'text/html; charset=utf-8' }});83+ assert.response(app,84+ { url: '/jade' },85+ { body: '<p>Welcome</p>' });86+ assert.response(app,87+ { url: '/absolute' },88+ { body: '<p>Welcome</p>' });89+ assert.response(app,90+ { url: '/haml' },91+ { body: '\n<p>Hello World</p>' });92+ assert.response(app,93+ { url: '/callback' },94+ { body: '\n<p>:)</p>' });95+ assert.response(app,96+ { url: '/callback/layout' },97+ { body: '<html><body><p>:)</p></body></html>' });98+ assert.response(app,99+ { url: '/callback/layout/no-options' },100+ { body: '<html><body><p>:)</p></body></html>' });101+ assert.response(app,102+ { url: '/error' },103+ { body: 'doesNotExist' });104+ assert.response(app,105+ { url: '/invalid' },106+ function(res){107+ assert.ok(res.body.indexOf('ReferenceError') >= 0);108+ assert.ok(res.body.indexOf('doesNotExist') >= 0);109+ });110+ assert.response(app,111+ { url: '/invalid-async' },112+ function(res){113+ assert.ok(res.body.indexOf('ReferenceError') >= 0);114+ assert.ok(res.body.indexOf('doesNotExist') >= 0);115+ });165- },116+ },117+ 118+ 'test #render() layout': function(){119+ var app = create();120+ app.set('view engine', 'jade');121+122+ app.get('/', function(req, res){123+ res.render('index.jade');124+ });125+ app.get('/jade', function(req, res){126+ res.render('index');127+ });128+129+ assert.response(app,130+ { url: '/' },131+ { body: '<html><body><p>Welcome</p></body></html>' });132+ },133+ 134+ 'test #render() specific layout': function(beforeExit){135+ var app = create()136+ , called;137+138+ app.get('/', function(req, res){139+ res.render('index.jade', { layout: 'cool-layout.jade' }, function(err, html){140+ called = true;141+ res.send(html);142+ });143+ });144+ app.get('/no-ext', function(req, res){145+ res.render('index.jade', { layout: 'cool-layout' });146+ });147+ app.get('/relative', function(req, res){148+ res.render('index.jade', { layout: 'layouts/foo.jade' });149+ });150+ app.get('/absolute', function(req, res){151+ res.render('index.jade', { layout: __dirname + '/fixtures/layouts/foo.jade' });152+ });153+ app.get('/nope', function(req, res){154+ res.render('index.jade', { layout: 'nope.jade' });155+ });156+157+ assert.response(app,158+ { url: '/' },159+ { body: '<cool><p>Welcome</p></cool>' });160+ assert.response(app,161+ { url: '/no-ext' },162+ { body: '<cool><p>Welcome</p></cool>' });163+ assert.response(app,164+ { url: '/relative' },165+ { body: '<foo></foo>' });166+ assert.response(app,167+ { url: '/absolute' },168+ { body: '<foo></foo>' });169+ assert.response(app,170+ { url: '/nope' },171+ function(res){172+ assert.ok(res.body.indexOf('Error: ENOENT') >= 0);173+ assert.ok(res.body.indexOf('nope.jade') >= 0);174+ });175+176+ beforeExit(function(){177+ assert.ok(called, 'Layout callback never called'); 178+ });179+ },180+ 181+ 'test #render() specific layout "view engine"': function(){182+ var app = create();183+ app.set('view engine', 'jade');184 167- 'test #render() specific layout "view engine"': function(assert){168- var app = create();169- app.set('view engine', 'jade');170- 171- app.get('/', function(req, res){172- res.render('index', { layout: 'cool-layout' });173- });185+ app.get('/', function(req, res){186+ res.render('index', { layout: 'cool-layout' });187+ });174- 175- assert.response(app,176- { url: '/' },177- { body: '<cool><p>Welcome</p></cool>' });178- },188 189+ assert.response(app,190+ { url: '/' },191+ { body: '<cool><p>Welcome</p></cool>' });192+ },193+ 180- 'test #render() scope': function(assert){181- var app = create();182- app.set('view engine', 'jade');183- 184- app.get('/', function(req, res){185- req.internal = '1';186- req.method = function(){187- return this.internal;188- };189- res.render('scope.jade', { layout: false });190- });191- 192- app.get('/custom', function(req, res){193- var scope = {194- internal: '2',195- method: function(){196- return this.internal;197- }198- };199- res.render('scope.jade', { layout: false, scope: scope });200- });201- 202- assert.response(app,203- { url: '/' },204- { body: '<p>1</p>'});194+ 'test #render() scope': function(){195+ var app = create();196+ app.set('view engine', 'jade');197+ 198+ app.get('/', function(req, res){199+ req.internal = '1';200+ req.method = function(){201+ return this.internal;202+ };203+ res.render('scope.jade', { layout: false });204+ });205+ 206+ app.get('/custom', function(req, res){207+ var scope = {208+ internal: '2',209+ method: function(){210+ return this.internal;211+ }212+ };213+ res.render('scope.jade', { layout: false, scope: scope });214+ });215+ 216+ assert.response(app,217+ { url: '/' },218+ { body: '<p>1</p>'});219 206- assert.response(app,207- { url: '/custom' },208- { body: '<p>2</p>'});209- },220+ assert.response(app,221+ { url: '/custom' },222+ { body: '<p>2</p>'});223+ },224+ 225+ 'test #render() status': function(){226+ var app = create();227 211- 'test #render() status': function(assert){212- var app = create();213- 214- app.get('/', function(req, res){215- res.render('hello.jade', {216- layout: false,217- status: 404218- });219- });228+ app.get('/', function(req, res){229+ res.render('hello.jade', {230+ layout: false,231+ status: 404232+ });233+ });220- 221- assert.response(app,222- { url: '/' },223- { body: '<p>:(</p>', status: 404 });224- },234 226- 'test #render() headers': function(assert){227- var app = create();228- 229- app.get('/', function(req, res){230- res.render('hello.jade', {231- layout: false,232- status: 500,233- headers: {234- 'X-Foo': 'bar'235- }236- });237- });238- 239- assert.response(app,240- { url: '/' },241- { body: '<p>:(</p>', status: 500, headers: {242- 'X-Foo': 'bar',243- 'Content-Type': 'text/html; charset=utf-8'244- }});245- },235+ assert.response(app,236+ { url: '/' },237+ { body: '<p>:(</p>', status: 404 });238+ },239+ 240+ 'test #render() headers': function(){241+ var app = create();242 243+ app.get('/', function(req, res){244+ res.render('hello.jade', {245+ layout: false,246+ status: 500,247+ headers: {248+ 'X-Foo': 'bar'249+ }250+ });251+ });252+ 253+ assert.response(app,254+ { url: '/' },255+ { body: '<p>:(</p>', status: 500, headers: {256+ 'X-Foo': 'bar',257+ 'Content-Type': 'text/html; charset=utf-8'258+ }});259+ },260+ 247- 'test #render() view helpers': function(assert, beforeExit){248- var app = create(),249- calls = 0;261+ 'test #render() view helpers': function(beforeExit){262+ var app = create()263+ , calls = 0;264 251- app.helpers({ 252- lastName: 'holowaychuk',253- greetings: function(sess, lastName){254- return 'Hello ' + sess.name + ' ' + lastName; 255- }256- });265+ app.helpers({ 266+ lastName: 'holowaychuk',267+ greetings: function(sess, lastName){268+ return 'Hello ' + sess.name + ' ' + lastName; 269+ }270+ });271 258- var ret = app.dynamicHelpers({259- session: function(req, res){260- ++calls;261- assert.equal('object', typeof req, 'Test dynamic helper req');262- assert.equal('object', typeof res, 'Test dynamic helper res');263- assert.ok(this instanceof express.Server, 'Test dynamic helper app scope');264- return req.session;265- }266- });272+ var ret = app.dynamicHelpers({273+ session: function(req, res){274+ ++calls;275+ assert.equal('object', typeof req, 'Test dynamic helper req');276+ assert.equal('object', typeof res, 'Test dynamic helper res');277+ assert.ok(this instanceof express.Server, 'Test dynamic helper app scope');278+ return req.session;279+ }280+ });281 268- assert.equal(app, ret, 'Server#helpers() is not chainable');269- 270- app.get('/', function(req, res){271- req.session = { name: 'tj' };272- res.render('dynamic-helpers.jade', { layout: false });273- });274- app.get('/ejs', function(req, res){275- req.session = { name: 'tj' };276- res.render('dynamic-helpers.ejs', { layout: false });277- });278- app.get('/precedence', function(req, res){279- req.session = { name: 'tj' };280- res.render('dynamic-helpers.jade', {281- locals: {282- lastName: 'foobar'283- }284- });285- });286- 287- assert.response(app,288- { url: '/' },289- { body: '<p>Hello tj holowaychuk</p>' });290- assert.response(app,291- { url: '/ejs' },292- { body: '<p>Hello tj holowaychuk</p>' });293- assert.response(app,294- { url: '/precedence' },295- { body: '<html><body><p>Hello tj foobar</p></body></html>' });296-297- beforeExit(function(){298- assert.equal(3, calls);299- });300- },282+ assert.equal(app, ret, 'Server#helpers() is not chainable');283 302- 'test #partial()': function(assert){303- var app = create();284+ app.get('/', function(req, res){285+ req.session = { name: 'tj' };286+ res.render('dynamic-helpers.jade', { layout: false });287+ });288 305- // Auto-assigned local w/ collection option306- app.get('/', function(req, res){307- res.render('items.jade', { locals: { items: ['one', 'two'] }});308- });309- 310- assert.response(app,311- { url: '/' },312- { body: '<html><body><ul><li>one</li><li>two</li></ul></body></html>' });289+ app.get('/ejs', function(req, res){290+ req.session = { name: 'tj' };291+ res.render('dynamic-helpers.ejs', { layout: false });292+ });293 314- // Auto-assigned local w/ collection array 315- var movies = [316- { title: 'Nightmare Before Christmas', director: 'Tim Burton' },317- { title: 'Avatar', director: 'James Cameron' }318- ];319- app.get('/movies', function(req, res){320- res.render('movies.jade', { locals: { movies: movies }});321- });322- 323- var html = [324- '<html>',325- '<body>',326- '<ul>',327- '<li>',328- '<div class="title">Nightmare Before Christmas</div>',329- '<div class="director">Tim Burton</div>',330- '</li>',331- '<li>',332- '<div class="title">Avatar</div>',333- '<div class="director">James Cameron</div>',334- '</li>',335- '</ul>',336- '</body>',337- '</html>'338- ].join('');294+ app.get('/precedence', function(req, res){295+ req.session = { name: 'tj' };296+ res.render('dynamic-helpers.jade', {297+ locals: {298+ lastName: 'foobar'299+ }300+ });301+ });302+ 303+ assert.response(app,304+ { url: '/' },305+ { body: '<p>Hello tj holowaychuk</p>' });306+ assert.response(app,307+ { url: '/ejs' },308+ { body: '<p>Hello tj holowaychuk</p>' });309+ assert.response(app,310+ { url: '/precedence' },311+ { body: '<html><body><p>Hello tj foobar</p></body></html>' });312 340- assert.response(app,341- { url: '/movies' },342- { body: html });313+ beforeExit(function(){314+ assert.equal(3, calls);315+ });316+ },317+ 318+ 'test #partial()': function(){319+ var app = create();320+321+ // Auto-assigned local w/ collection option322+ app.get('/', function(req, res){323+ res.render('items.jade', { locals: { items: ['one', 'two'] }});324+ });325 344- // as: str collection option345- app.get('/user', function(req, res){346- res.send(res.partial('user.jade', {347- as: 'person',348- collection: [{ name: 'tj' }]349- }));350- });351- 352- assert.response(app,353- { url: '/user' },354- { body: '<p>tj</p>' });326+ assert.response(app,327+ { url: '/' },328+ { body: '<html><body><ul><li>one</li><li>two</li></ul></body></html>' });329 356- // as: with object collection357- app.get('/user/object', function(req, res){358- res.send(res.partial('user.jade', {359- as: 'person',360- collection: { 0: { name: 'tj' }, length: 1 }361- }));362- });330+ // Auto-assigned local w/ collection array 331+ var movies = [332+ { title: 'Nightmare Before Christmas', director: 'Tim Burton' },333+ { title: 'Avatar', director: 'James Cameron' }334+ ];335+ app.get('/movies', function(req, res){336+ res.render('movies.jade', { locals: { movies: movies }});337+ });338 364- assert.response(app,365- { url: '/user' },366- { body: '<p>tj</p>' });367- 368- // as: this collection option369- app.get('/person', function(req, res){370- res.send(res.partial('person.jade', {371- as: this,372- collection: [{ name: 'tj' }],373- locals: { label: 'name:' }374- }));375- });376- 377- assert.response(app,378- { url: '/person' },379- { body: '<p>name: tj</p>' });339+ var html = [340+ '<html>',341+ '<body>',342+ '<ul>',343+ '<li>',344+ '<div class="title">Nightmare Before Christmas</div>',345+ '<div class="director">Tim Burton</div>',346+ '</li>',347+ '<li>',348+ '<div class="title">Avatar</div>',349+ '<div class="director">James Cameron</div>',350+ '</li>',351+ '</ul>',352+ '</body>',353+ '</html>'354+ ].join('');355 381- // as: global collection option382- app.get('/videos', function(req, res){383- res.send(res.partial('video.jade', {384- as: global,385- collection: movies386- }));387- });356+ assert.response(app,357+ { url: '/movies' },358+ { body: html });359 389- assert.response(app,390- { url: '/videos' },391- { body: '<p>Tim Burton</p><p>James Cameron</p>' });392- 393- // Magic variables394- app.get('/magic', function(req, res){395- res.send(res.partial('magic.jade', {396- as: 'word',397- collection: ['one', 'two', 'three']398- }));399- });400- 401- assert.response(app,402- { url: '/magic' },403- { body: '<li class="first">one</li><li class="word-1">two</li><li class="last">three</li>' });360+ // as: str collection option361+ app.get('/user', function(req, res){362+ res.send(res.partial('user.jade', {363+ as: 'person',364+ collection: [{ name: 'tj' }]365+ }));366+ });367+ 368+ assert.response(app,369+ { url: '/user' },370+ { body: '<p>tj</p>' });404- 405- // Non-collection support406- app.get('/movie', function(req, res){407- res.send(res.partial('movie.jade', {408- object: movies[0]409- }));410- });411- 412- assert.response(app,413- { url: '/movie' },414- { body: '<li><div class="title">Nightmare Before Christmas</div><div class="director">Tim Burton</div></li>' });415- 416- app.get('/video-global', function(req, res){417- res.send(res.partial('video.jade', {418- object: movies[0],419- as: global420- })); 421- });422- 423- // Non-collection as: global424- assert.response(app,425- { url: '/video-global' },426- { body: '<p>Tim Burton</p>' });371 428- app.get('/person-this', function(req, res){429- res.send(res.partial('person.jade', {430- object: { name: 'tj' },431- locals: { label: 'User:' },432- as: this433- })); 434- });435- 436- // Non-collection as: this437- assert.response(app,438- { url: '/person-this' },439- { body: '<p>User: tj</p>' });372+ // as: with object collection373+ app.get('/user/object', function(req, res){374+ res.send(res.partial('user.jade', {375+ as: 'person',376+ collection: { 0: { name: 'tj' }, length: 1 }377+ }));378+ });379 380+ assert.response(app,381+ { url: '/user' },382+ { body: '<p>tj</p>' });383+ 384+ // as: this collection option385+ app.get('/person', function(req, res){386+ res.send(res.partial('person.jade', {387+ as: this,441- // No options442- app.get('/nothing', function(req, res){443- res.send(res.partial('hello.ejs'));444- });445- 446- assert.response(app,447- { url: '/nothing' },448- { body: 'Hello' });388+ collection: [{ name: 'tj' }],389+ locals: { label: 'name:' }390+ }));391+ });392+ 393+ assert.response(app,394+ { url: '/person' },395+ { body: '<p>name: tj</p>' });396 450- // Path segments + "as"451- app.get('/role/as', function(req, res){452- res.send(res.partial('user/role.ejs', { as: 'role', collection: ['admin', 'member'] }));453- });397+ // as: global collection option398+ app.get('/videos', function(req, res){399+ res.send(res.partial('video.jade', {400+ as: global,401+ collection: movies402+ }));403+ });404 455- assert.response(app,456- { url: '/role/as' },457- { body: '<li>Role: admin</li><li>Role: member</li>' });405+ assert.response(app,406+ { url: '/videos' },407+ { body: '<p>Tim Burton</p><p>James Cameron</p>' });408+ 409+ // Magic variables410+ app.get('/magic', function(req, res){411+ res.send(res.partial('magic.jade', {412+ as: 'word',413+ collection: ['one', 'two', 'three']414+ }));415+ });416+ 417+ assert.response(app,418+ { url: '/magic' },419+ { body: '<li class="first">one</li><li class="word-1">two</li><li class="last">three</li>' });420+ 421+ // Non-collection support422+ app.get('/movie', function(req, res){423+ res.send(res.partial('movie.jade', {424+ object: movies[0]425+ }));426+ });427+ 428+ assert.response(app,429+ { url: '/movie' },430+ { body: '<li><div class="title">Nightmare Before Christmas</div><div class="director">Tim Burton</div></li>' });431+ 432+ app.get('/video-global', function(req, res){433+ res.send(res.partial('video.jade', {434+ object: movies[0],435+ as: global436+ })); 437+ });438+ 439+ // Non-collection as: global440+ assert.response(app,441+ { url: '/video-global' },442+ { body: '<p>Tim Burton</p>' });443 459- // Deduce name from last segment460- app.get('/role', function(req, res){461- res.send(res.partial('user/role.ejs', ['admin', 'member']));462- });444+ app.get('/person-this', function(req, res){445+ res.send(res.partial('person.jade', {446+ object: { name: 'tj' },447+ locals: { label: 'User:' },448+ as: this449+ })); 450+ });451+ 452+ // Non-collection as: this453+ assert.response(app,454+ { url: '/person-this' },455+ { body: '<p>User: tj</p>' });456 464- assert.response(app,465- { url: '/role' },466- { body: '<li>Role: admin</li><li>Role: member</li>' });467- },457+ // No options458+ app.get('/nothing', function(req, res){459+ res.send(res.partial('hello.ejs'));460+ });461 469- 'test #partial() locals': function(assert){470- var app = create();462+ assert.response(app,463+ { url: '/nothing' },464+ { body: 'Hello' });465 472- app.get('/', function(req, res, next){473- res.send(res.partial('pet-count.jade', {474- locals: {475- pets: {476- length: 5477- }478- }479- }));480- });466+ // Path segments + "as"467+ app.get('/role/as', function(req, res){468+ res.send(res.partial('user/role.ejs', { as: 'role', collection: ['admin', 'member'] }));469+ });470 482- assert.response(app,483- { url: '/' },484- { body: 'We have 5 cool pets\n' });485- },486- 487- 'test #partial() locals precedence': function(assert){488- var app = create();471+ assert.response(app,472+ { url: '/role/as' },473+ { body: '<li>Role: admin</li><li>Role: member</li>' });474 490- app.get('/', function(req, res, next){491- res.render('greetings.jade', {492- locals: {493- name: 'TJ'494- , otherName: 'Overridden'495- }496- });497- });475+ // Deduce name from last segment476+ app.get('/role', function(req, res){477+ res.send(res.partial('user/role.ejs', ['admin', 'member']));478+ });479 499- assert.response(app,500- { url: '/' },501- { body: '<html><body><h1>TJ</h1><p>Welcome Overridden</p></body></html>' });502- },503- 504- 'test #partial() object': function(assert){505- var app = create();480+ assert.response(app,481+ { url: '/role' },482+ { body: '<li>Role: admin</li><li>Role: member</li>' });483+ },484+ 485+ 'test #partial() locals': function(){486+ var app = create();487 507- app.get('/', function(req, res, next){508- res.send(res.partial('movie.jade', {509- title: 'Foobar'510- , director: 'Tim Burton'511- }));512- });488+ app.get('/', function(req, res, next){489+ res.send(res.partial('pet-count.jade', {490+ locals: {491+ pets: {492+ length: 5493+ }494+ }495+ }));496+ });497 514- assert.response(app,515- { url: '/' },516- { body: '<li><div class="title">Foobar</div><div class="director">Tim Burton</div></li>' });517- },518- 519- 'test #partial() locals with collection': function(assert){520- var app = create();498+ assert.response(app,499+ { url: '/' },500+ { body: 'We have 5 cool pets\n' });501+ },502+ 503+ 'test #partial() locals precedence': function(){504+ var app = create();505 522- app.get('/', function(req, res, next){523- res.render('pet-land.jade', {524- locals: {525- pets: ['Ewald']526- }527- });528- });506+ app.get('/', function(req, res, next){507+ res.render('greetings.jade', {508+ locals: {509+ name: 'TJ'510+ , otherName: 'Overridden'511+ }512+ });513+ });514 530- assert.response(app,531- { url: '/' },532- { body: '<html><body><div><li>Ewald is the coolest of Animal land</li></div></body></html>' });533- },534- 535- 'test #partial() inheriting initial locals': function(assert){536- var app = create();515+ assert.response(app,516+ { url: '/' },517+ { body: '<html><body><h1>TJ</h1><p>Welcome Overridden</p></body></html>' });518+ },519+ 520+ 'test #partial() object': function(){521+ var app = create();522 538- app.get('/pets', function(req, res, next){539- res.render('pets.jade', {540- locals: {541- site: 'My Cool Pets',542- pets: ['Tobi', 'Jane', 'Bandit']543- }544- });545- });523+ app.get('/', function(req, res, next){524+ res.send(res.partial('movie.jade', {525+ title: 'Foobar'526+ , director: 'Tim Burton'527+ }));528+ });529 547- var html = [548- '<html>',549- '<body>',550- '<h1>My Cool Pets</h1>',551- '<p>We have 3 cool pets\n</p>',552- '<ul>',553- '<li>Tobi is the coolest of My Cool Pets</li>',554- '<li>Jane</li>',555- '<li>Bandit</li>',556- '</ul>',557- '</body>',558- '</html>'559- ].join('');530+ assert.response(app,531+ { url: '/' },532+ { body: '<li><div class="title">Foobar</div><div class="director">Tim Burton</div></li>' });533+ },534+ 535+ 'test #partial() locals with collection': function(){536+ var app = create();537 561- assert.response(app,562- { url: '/pets' },563- { body: html });564- },565- 566- 'test #partial() with array-like collection': function(assert){567- var app = create();538+ app.get('/', function(req, res, next){539+ res.render('pet-land.jade', {540+ locals: {541+ pets: ['Ewald']542+ }543+ });544+ });545 569- var movies = {570- 0: { title: 'Nightmare Before Christmas', director: 'Tim Burton' },571- 1: { title: 'Avatar', director: 'James Cameron' },572- length: 2573- };574- app.get('/movies', function(req, res){575- res.render('movies.jade', { locals: { movies: movies }});576- });577- 578- var html = [579- '<html>',580- '<body>',581- '<ul>',582- '<li>',583- '<div class="title">Nightmare Before Christmas</div>',584- '<div class="director">Tim Burton</div>',585- '</li>',586- '<li>',587- '<div class="title">Avatar</div>',588- '<div class="director">James Cameron</div>',589- '</li>',590- '</ul>',591- '</body>',592- '</html>'593- ].join('');546+ assert.response(app,547+ { url: '/' },548+ { body: '<html><body><div><li>Ewald is the coolest of Animal land</li></div></body></html>' });549+ },550+ 551+ 'test #partial() inheriting initial locals': function(){552+ var app = create();553 595- assert.response(app,596- { url: '/movies' },597- { body: html });598- },599- 600- 'test "partials" setting': function(assert){601- var app = create();602- app.set('partials', __dirname + '/fixtures/sub-templates');554+ app.get('/pets', function(req, res, next){555+ res.render('pets.jade', {556+ locals: {557+ site: 'My Cool Pets',558+ pets: ['Tobi', 'Jane', 'Bandit']559+ }560+ });561+ });562 604- app.get('/', function(req, res){605- res.render('items.jade', {606- layout: false,607- locals: {608- items: ['foo', 'bar']609- }610- });611- });563+ var html = [564+ '<html>',565+ '<body>',566+ '<h1>My Cool Pets</h1>',567+ '<p>We have 3 cool pets\n</p>',568+ '<ul>',569+ '<li>Tobi is the coolest of My Cool Pets</li>',570+ '<li>Jane</li>',571+ '<li>Bandit</li>',572+ '</ul>',573+ '</body>',574+ '</html>'575+ ].join('');576+577+ assert.response(app,578+ { url: '/pets' },579+ { body: html });580+ },581+ 582+ 'test #partial() with array-like collection': function(){583+ var app = create();584+585+ var movies = {586+ 0: { title: 'Nightmare Before Christmas', director: 'Tim Burton' },587+ 1: { title: 'Avatar', director: 'James Cameron' },588+ length: 2589+ };590+ app.get('/movies', function(req, res){591+ res.render('movies.jade', { locals: { movies: movies }});592+ });593 594+ var html = [595+ '<html>',596+ '<body>',597+ '<ul>',598+ '<li>',599+ '<div class="title">Nightmare Before Christmas</div>',600+ '<div class="director">Tim Burton</div>',601+ '</li>',602+ '<li>',603+ '<div class="title">Avatar</div>',604+ '<div class="director">James Cameron</div>',605+ '</li>',606+ '</ul>',607+ '</body>',608+ '</html>'609+ ].join('');610+613- assert.response(app,614- { url: '/' },615- { body: '<ul><li class="item">foo</li><li class="item">bar</li></ul>' });616- },611+ assert.response(app,612+ { url: '/movies' },613+ { body: html });614+ },615+ 616+ 'test "partials" setting': function(){617+ var app = create();618+ app.set('partials', __dirname + '/fixtures/sub-templates');619+620+ app.get('/', function(req, res){621+ res.render('items.jade', {622+ layout: false,623+ locals: {624+ items: ['foo', 'bar']625+ }626+ });627+ });628 618- 'test "view options"': function(assert){619- var app = create();620- 621- app.set('view options', {622- layout: false,623- open: '{{',624- close: '}}'625- });626- 627- app.get('/', function(req, res, next){628- res.render('user.ejs', {629- locals: {630- name: 'tj',631- email: 'tj@vision-media.ca'632- }633- });634- });635- 636- app.get('/video', function(req, res, next){637- res.render('video.ejs', {638- open: '<?',639- close: '?>',640- locals: {641- title: 'keyboard cat'642- }643- });644- });645- 646- assert.response(app,647- { url: '/' },648- { body: '<h1>tj</h1>\n<p>tj@vision-media.ca</p>' });649- assert.response(app,650- { url: '/video' },651- { body: '<h1>keyboard cat</h1>' });652- },629+ assert.response(app,630+ { url: '/' },631+ { body: '<ul><li class="item">foo</li><li class="item">bar</li></ul>' });632+ },633+ 634+ 'test "view options"': function(){635+ var app = create();636 637+ app.set('view options', {638+ layout: false,639+ open: '{{',640+ close: '}}'641+ });642+ 643+ app.get('/', function(req, res, next){644+ res.render('user.ejs', {645+ locals: {646+ name: 'tj',647+ email: 'tj@vision-media.ca'648+ }649+ });650+ });651+ 652+ app.get('/video', function(req, res, next){653+ res.render('video.ejs', {654+ open: '<?',655+ close: '?>',656+ locals: {657+ title: 'keyboard cat'658+ }659+ });660+ });661+ 662+ assert.response(app,663+ { url: '/' },664+ { body: '<h1>tj</h1>\n<p>tj@vision-media.ca</p>' });665+ assert.response(app,666+ { url: '/video' },667+ { body: '<h1>keyboard cat</h1>' });668+ },669+ 654- 'test .register()': function(assert){655- var app = create();656- 657- app.register('.bar', require('jade'));658- 659- app.get('/', function(req, res, next){660- res.render('foo.bar', { layout: false });661- });662- 663- assert.response(app,664- { url: '/' },665- { body: '<p>This is actually jade :)</p>' });666- }670+ 'test .register()': function(){671+ var app = create();672+ 673+ app.register('.bar', require('jade'));674+ 675+ app.get('/', function(req, res, next){676+ res.render('foo.bar', { layout: false });677+ });678+ 679+ assert.response(app,680+ { url: '/' },681+ { body: '<p>This is actually jade :)</p>' });682+ }683 };modified:.gitmodules+3 added
14 unmodified lines15 url = git://github.com/senchalabs/connect.git16 [submodule "support/jade"]17 path = support/jade18 url = git://github.com/visionmedia/jade.git19+[submodule "support/should"]20+ path = support/should21+ url = git://github.com/visionmedia/should.js.gitmodified:Makefile+1 added
36 unmodified lines37 38 test:39 @NODE_ENV=test ./support/expresso/bin/expresso \40 -I lib \41+ -I support \42 -I support/connect/lib \43 -I support/haml/lib \44 -I support/jade/lib \45 -I support/ejs/lib \32 unmodified lines