Remove old 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 6b1dc31 · Browse files · 56 files·+0 added−3692 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
56 files+0 added−3692 removed
- tests:+0 added−3692 removed
Provenance
- Commit
9efc4b2- Tree
d4cb1c4- Author
Tj Holowaychuk <tj@vision-media.ca>- Committer
Tj Holowaychuk <tj@vision-media.ca>- Parent
6b1dc31
56 files changed+0 added−3692 removed
deleted:test/fixtures/ferret/index.jade-1 removed
1-li.ferret= ferret.namedeleted:test/fixtures/ferret/list.jade-3 removed
1-ul#ferrets2- - each ferret in list3- != partial('ferret', ferret)deleted:test/fixtures/forum/thread.jade-3 removed
1-h1 Forum Thread2-!= partial('../hello')3-!= partial('../hello.haml')deleted:test/fixtures/layouts/alternate.jade-1 removed
1-#alternate!= bodydeleted:test/fixtures/layouts/foo.jade-1 removed
1-foodeleted:test/fixtures/nested/partial.jade-1 removed
1-!= partial('stats', { hits: 15, misses: 1 })deleted:test/fixtures/nested/partial2.jade-1 removed
1-!= partial('messages')deleted:test/fixtures/sub-templates/item.jade-1 removed
1-li.item= itemdeleted:test/fixtures/user/role.ejs-1 removed
1-<li>Role: <%= role %></li>deleted:test/fixtures/_foobar.jade-1 removed
1-p twodeleted:test/fixtures/_messages.jade-1 removed
1-p Testingdeleted:test/fixtures/cool-layout.jade-1 removed
1-cool!= bodydeleted:test/fixtures/dynamic-helpers.ejs-1 removed
1-<p><%= greetings(session, lastName) %></p>deleted:test/fixtures/dynamic-helpers.jade-1 removed
1-p #{greetings(session, lastName)}deleted:test/fixtures/error.jade-1 removed
1-= user.namedeleted:test/fixtures/foo.bar-1 removed
1-p This is actually jade :)deleted:test/fixtures/foobar.jade-1 removed
1-p onedeleted:test/fixtures/greeting.jade-1 removed
1-p Welcome #{name}deleted:test/fixtures/greetings.jade-2 removed
1-h1= name2-!= partial('greeting', { locals: { name: otherName }})deleted:test/fixtures/hello.ejs-1 removed
1-Hellodeleted:test/fixtures/hello.haml-1 removed
1-%p Hello Worlddeleted:test/fixtures/hello.jade-1 removed
1-p :(deleted:test/fixtures/index.jade-1 removed
1-p Welcomedeleted:test/fixtures/invalid.jade-1 removed
1-p= doesNotExistdeleted:test/fixtures/item-title.jade-1 removed
1-li #{title} #{item}deleted:test/fixtures/item.jade-1 removed
1-li= itemdeleted:test/fixtures/items.jade-1 removed
1-ul!= partial('item.jade', { collection: items })deleted:test/fixtures/large.json-151 removed
1-{2- "foo":"bar",3- "foo":"bar",4- "foo":"bar",5- "foo":"bar",6- "foo":"bar",7- "foo":"bar",8- "foo":"bar",9- "foo":"bar",10- "foo":"bar",11- "foo":"bar",12- "foo":"bar",13- "foo":"bar",14- "foo":"bar",15- "foo":"bar",16- "foo":"bar",17- "foo":"bar",18- "foo":"bar",19- "foo":"bar",20- "foo":"bar",21- "foo":"bar",22- "foo":"bar",23- "foo":"bar",24- "foo":"bar",25- "foo":"bar",26- "foo":"bar",27- "foo":"bar",28- "foo":"bar",29- "foo":"bar",30- "foo":"bar",31- "foo":"bar",32- "foo":"bar",33- "foo":"bar",34- "foo":"bar",35- "foo":"bar",36- "foo":"bar",37- "foo":"bar",38- "foo":"bar",39- "foo":"bar",40- "foo":"bar",41- "foo":"bar",42- "foo":"bar",43- "foo":"bar",44- "foo":"bar",45- "foo":"bar",46- "foo":"bar",47- "foo":"bar",48- "foo":"bar",49- "foo":"bar",50- "foo":"bar",51- "foo":"bar",52- "foo":"bar",53- "foo":"bar",54- "foo":"bar",55- "foo":"bar",56- "foo":"bar",57- "foo":"bar",58- "foo":"bar",59- "foo":"bar",60- "foo":"bar",61- "foo":"bar",62- "foo":"bar",63- "foo":"bar",64- "foo":"bar",65- "foo":"bar",66- "foo":"bar",67- "foo":"bar",68- "foo":"bar",69- "foo":"bar",70- "foo":"bar",71- "foo":"bar",72- "foo":"bar",73- "foo":"bar",74- "foo":"bar",75- "foo":"bar",76- "foo":"bar",77- "foo":"bar",78- "foo":"bar",79- "foo":"bar",80- "foo":"bar",81- "foo":"bar",82- "foo":"bar",83- "foo":"bar",84- "foo":"bar",85- "foo":"bar",86- "foo":"bar",87- "foo":"bar",88- "foo":"bar",89- "foo":"bar",90- "foo":"bar",91- "foo":"bar",92- "foo":"bar",93- "foo":"bar",94- "foo":"bar",95- "foo":"bar",96- "foo":"bar",97- "foo":"bar",98- "foo":"bar",99- "foo":"bar",100- "foo":"bar",101- "foo":"bar",102- "foo":"bar",103- "foo":"bar",104- "foo":"bar",105- "foo":"bar",106- "foo":"bar",107- "foo":"bar",108- "foo":"bar",109- "foo":"bar",110- "foo":"bar",111- "foo":"bar",112- "foo":"bar",113- "foo":"bar",114- "foo":"bar",115- "foo":"bar",116- "foo":"bar",117- "foo":"bar",118- "foo":"bar",119- "foo":"bar",120- "foo":"bar",121- "foo":"bar",122- "foo":"bar",123- "foo":"bar",124- "foo":"bar",125- "foo":"bar",126- "foo":"bar",127- "foo":"bar",128- "foo":"bar",129- "foo":"bar",130- "foo":"bar",131- "foo":"bar",132- "foo":"bar",133- "foo":"bar",134- "foo":"bar",135- "foo":"bar",136- "foo":"bar",137- "foo":"bar",138- "foo":"bar",139- "foo":"bar",140- "foo":"bar",141- "foo":"bar",142- "foo":"bar",143- "foo":"bar",144- "foo":"bar",145- "foo":"bar",146- "foo":"bar",147- "foo":"bar",148- "foo":"bar",149- "foo":"bar",150- "foo":"bar"151-}deleted:test/fixtures/layout-switch.jade-2 removed
1-- layout('layouts/alternate')2-h1 My Pagedeleted:test/fixtures/layout.jade-2 removed
1-html2- body!= bodydeleted:test/fixtures/list-item.jade-4 removed
1-- if ('undefined' == typeof listItem)2- li empty3-- else4- li= listItemdeleted:test/fixtures/list-item2.jade-4 removed
1-- if ('undefined' == typeof item)2- li empty3-- else4- li= itemdeleted:test/fixtures/list.jade-3 removed
1-ul2- != partial('list-item', { object: 'foo' })3- != partial('list-item')deleted:test/fixtures/list2.jade-4 removed
1-ul2- != partial('list-item2', { locals: { item: 'foo' }})3- != partial('list-item2', { locals: { item: 'bar' }})4- != partial('list-item2')deleted:test/fixtures/magic.jade-6 removed
1-- if (firstInCollection)2- li.first= word3-- else if (lastInCollection)4- li.last= word5-- else6- li(class='word-' + indexInCollection)= worddeleted:test/fixtures/movie.jade-3 removed
1-li2- .title= movie.title3- .director= movie.directordeleted:test/fixtures/movies.jade-1 removed
1-ul!= partial('movie', movies)deleted:test/fixtures/object-item.jade-1 removed
1-li #{keyInCollection}: #{item}deleted:test/fixtures/pet-count.jade-1 removed
1-| We have #{pets.length} cool petsdeleted:test/fixtures/pet-land.jade-1 removed
1-div!= partial('pet', { collection: pets, locals: { site: 'Animal land' }})deleted:test/fixtures/pet.jade-4 removed
1-- if (firstInCollection)2- li #{pet} is the coolest of #{site}3-- else4- li= petdeleted:test/fixtures/pets.jade-3 removed
1-h1= site2-p!= partial('pet-count')3-ul!= partial('pet', pets)deleted:test/fixtures/pets.json-1 removed
1-["tobi", "loki", "jane"]deleted:test/fixtures/some random text file.txt-1 removed
1-hellodeleted:test/fixtures/stats.jade-2 removed
1-p Hits #{hits}2-p Misses #{misses}deleted:test/fixtures/user.ejs-2 removed
1-<h1>{{= name }}</h1>2-<p>{{= email }}</p>deleted:test/fixtures/user.jade-1 removed
1-p= person.namedeleted:test/fixtures/user.json-1 removed
1-{"name":"tj"}deleted:test/fixtures/video.ejs-1 removed
1-<h1><?= title ?></h1>deleted:test/fixtures/video.jade-1 removed
1-p= directordeleted:test/express.test.js-424 removed
1-2-/**3- * Module dependencies.4- */5-6-var express = require('express')7- , connect = require('connect')8- , assert = require('assert')9- , should = require('should')10- , Route = express.Route;11-12-module.exports = {13- 'test inheritance': function(){14- var server = express.createServer();15- server.should.be.an.instanceof(connect.HTTPServer);16- },17-18- 'test constructor exports': function(){19- express.should.have.property('HTTPServer');20- express.should.have.property('HTTPSServer');21- express.should.have.property('Route');22- },23- 24- 'test connect middleware autoloaders': function(){25- express.errorHandler.should.equal(connect.errorHandler);26- },27- 28- 'test createServer() precedence': function(){29- var app = express.createServer(function(req, res){30- res.send(req.query.bar);31- });32- 33- assert.response(app,34- { url: '/foo?bar=baz' },35- { body: 'baz' });36- },37- 38- 'test basic server': function(){39- var server = express.createServer();40-41- server.get('/', function(req, res){42- server.set('env').should.equal('test');43- res.writeHead(200, {});44- res.end('wahoo');45- });46-47- server.put('/user/:id', function(req, res){48- res.writeHead(200, {});49- res.end('updated user ' + req.params.id)50- });51-52- server.del('/something', function(req, res){53- res.send('Destroyed');54- });55-56- server.delete('/something/else', function(req, res){57- res.send('Destroyed');58- });59- 60- server.all('/staff/:id', function(req, res, next){61- req.staff = { id: req.params.id };62- next();63- });64-65- server.get('/staff/:id', function(req, res){66- res.send('GET Staff ' + req.staff.id);67- });68- 69- server.post('/staff/:id', function(req, res){70- res.send('POST Staff ' + req.staff.id);71- });72- 73- server.all('*', function(req, res){74- res.send('requested ' + req.url);75- });76-77- assert.response(server,78- { url: '/' },79- { body: 'wahoo' });80- 81- assert.response(server,82- { url: '/user/12', method: 'PUT' },83- { body: 'updated user 12' });84-85- assert.response(server,86- { url: '/something', method: 'DELETE' },87- { body: 'Destroyed' });88-89- assert.response(server,90- { url: '/something/else', method: 'DELETE' },91- { body: 'Destroyed' });92-93- assert.response(server,94- { url: '/staff/12' },95- { body: 'GET Staff 12' });96- 97- assert.response(server,98- { url: '/staff/12', method: 'POST' },99- { body: 'POST Staff 12' });100- 101- assert.response(server,102- { url: '/foo/bar/baz', method: 'DELETE' },103- { body: 'requested /foo/bar/baz' });104- },105- 106- 'test constructor middleware': function(beforeExit){107- var calls = [];108-109- function one(req, res, next){110- calls.push('one');111- next();112- }113-114- function two(req, res, next){115- calls.push('two');116- next();117- }118-119- var app = express.createServer(one, two);120- app.get('/', function(req, res){121- res.writeHead(200, {});122- res.end('foo bar');123- });124- 125- assert.response(app,126- { url: '/' },127- { body: 'foo bar' });128- 129- beforeExit(function(){130- calls.should.eql(['one', 'two']);131- });132- },133-134- 'test next()': function(){135- var app = express.createServer();136- 137- app.get('/user.:format?', function(req, res, next){138- switch (req.params.format) {139- case 'json':140- res.writeHead(200, {});141- res.end('some json');142- break;143- default:144- next();145- }146- });147- 148- app.get('/user', function(req, res){149- res.writeHead(200, {});150- res.end('no json :)');151- });152- 153- assert.response(app,154- { url: '/user.json' },155- { body: 'some json' });156- 157- assert.response(app,158- { url: '/user' },159- { body: 'no json :)' });160- },161- 162- 'test #use()': function(){163- var app = express.createServer();164-165- app.get('/users', function(req, res, next){166- next(new Error('fail!!'));167- });168- app.use('/', connect.errorHandler({ showMessage: true }));169- 170- assert.response(app,171- { url: '/users' },172- { body: 'Error: fail!!' });173- },174- 175- 'test #configure()': function(beforeExit){176- var calls = [];177- var server = express.createServer();178- server.set('env', 'development');179- 180- var ret = server.configure(function(){181- assert.equal(this, server, 'Test context of configure() is the server');182- calls.push('any');183- }).configure('development', function(){184- calls.push('dev');185- }).configure('production', function(){186- calls.push('production');187- });188-189- should.equal(ret, server, 'Test #configure() returns server for chaining');190-191- assert.response(server,192- { url: '/' },193- { body: 'Cannot GET /' });194-195- beforeExit(function(){196- calls.should.eql(['any', 'dev']);197- });198- },199- 200- 'test #configure() immediate call': function(){201- var app = express.createServer();202-203- app.configure(function(){204- app.use(connect.bodyParser());205- });206- 207- app.post('/', function(req, res){208- res.send(req.param('name') || 'nope');209- });210-211- assert.response(app,212- { url: '/', method: 'POST', data: 'name=tj', headers: { 'Content-Type': 'application/x-www-form-urlencoded' }},213- { body: 'tj' });214- },215-216- 'test #configure() precedence': function(){217- var app = express.createServer();218-219- app.configure(function(){220- app.use(function(req, res, next){221- res.writeHead(200, {});222- res.write('first');223- next();224- });225- app.use(app.router);226- app.use(function(req, res, next){227- res.end('last');228- });229- });230- 231- app.get('/', function(req, res, next){232- res.write(' route ');233- next();234- });235-236- assert.response(app,237- { url: '/' },238- { body: 'first route last' });239- },240-241- 'test #configure() multiple envs': function(){242- var app = express.createServer();243- app.set('env', 'prod');244- var calls = [];245-246- app.configure('stage', 'prod', function(){247- calls.push('stage/prod');248- });249-250- app.configure('prod', function(){251- calls.push('prod');252- });253-254- calls.should.eql(['stage/prod', 'prod']);255- },256-257- 'test #set()': function(){258- var app = express.createServer();259- var ret = app.set('title', 'My App').set('something', 'else');260- ret.should.equal(app);261- app.set('title').should.equal('My App');262- app.set('something').should.equal('else');263- },264-265- 'test .settings': function(){266- var app = express.createServer();267- app.set('title', 'My App');268- app.settings.title.should.equal('My App');269- app.settings.title = 'Something Else';270- app.settings.title.should.equal('Something Else');271- app.set('title').should.equal('Something Else');272- },273- 274- 'test #enable()': function(){275- var app = express.createServer();276- var ret = app.enable('some feature');277- ret.should.equal(app);278- app.set('some feature').should.be.true;279- app.enabled('some feature').should.be.true;280- app.enabled('something else').should.be.false;281- },282- 283- 'test #disable()': function(){284- var app = express.createServer();285- var ret = app.disable('some feature');286- ret.should.equal(app);287- app.set('some feature').should.be.false;288- app.disabled('some feature').should.be.true;289- app.disabled('something else').should.be.true;290- },291- 292- 'test mounting': function(){293- var called294- , app = express.createServer()295- , blog = express.createServer()296- , map = express.createServer()297- , reg = connect.createServer();298-299- map.mounted(function(parent){300- called = true;301- assert.equal(this, map, 'mounted() is not in context of the child app');302- assert.equal(app, parent, 'mounted() was not called with parent app');303- });304-305- reg.use(function(req, res){ res.end('hey'); });306- app.use('/regular', reg);307-308- app.use('/blog', blog);309- app.use('/contact', map);310- blog.route.should.equal('/blog');311- map.route.should.equal('/contact');312- should.equal(true, called);313-314- app.set("test", "parent setting");315- blog.set('test').should.equal('parent setting');316- 317- app.get('/', function(req, res){318- blog.set('basepath').should.equal('/blog');319- map.set('basepath').should.equal('/contact');320- res.send('main app');321- });322-323- blog.get('/', function(req, res){324- res.send('blog index');325- });326- 327- blog.get('/post/:id', function(req, res){328- res.send('blog post ' + req.params.id);329- });330- 331- assert.response(app,332- { url: '/' },333- { body: 'main app' });334- assert.response(app,335- { url: '/blog' },336- { body: 'blog index' });337- assert.response(app,338- { url: '/blog/post/12' },339- { body: 'blog post 12' });340- assert.response(blog,341- { url: '/' },342- { body: 'blog index' });343- assert.response(app,344- { url: '/regular' },345- { body: 'hey' });346- },347-348- 'test .app property after returning control to parent': function() {349- var app = express.createServer()350- , blog = express.createServer();351-352- // Mounted servers did not restore `req.app` and `res.app` when353- // passing control back to parent via `out()` in `#handle()`.354-355- blog.get('/', function(req, res, next){356- req.app.should.equal(blog);357- res.app.should.equal(blog);358- next();359- });360-361- app.use(blog);362-363- app.use(function(req, res, next) {364- res.send((res.app === app) ? 'restored' : 'not-restored');365- });366-367- assert.response(app,368- { url: '/' },369- { body: 'restored' }370- );371- },372-373- 'test "basepath" setting': function(){374- var app = express.createServer();375- 376- app.set('basepath', '/shop');377- 378- app.get('/redirect', function(req, res){379- res.redirect('/cart');380- });381- 382- assert.response(app,383- { url: '/redirect', headers: { Host: 'foo.com' }},384- { headers: { Location: 'http://foo.com/shop/cart' }});385- },386-387- 'test routes with same callback': function(){388- function handle(req, res) {389- res.send('got ' + req.string);390- }391-392- var app = express.createServer();393-394- app.get('/', function(req, res, next){395- req.string = '/';396- next();397- }, handle);398-399- app.get('/another', function(req, res, next){400- req.string = '/another';401- next();402- }, handle);403-404- assert.response(app,405- { url: '/' },406- { body: 'got /' });407-408- assert.response(app,409- { url: '/another' },410- { body: 'got /another' });411- },412- 413- 'invalid chars': function(){414- var app = express.createServer();415-416- app.get('/:name', function(req, res, next){417- res.send('invalid');418- });419-420- assert.response(app,421- { url: '/%a0' },422- { status: 500 });423- }424-};deleted:test/request.test.js-356 removed
1-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 = {12- 'test #path': function(){13- var app = express.createServer();14-15- app.get('/search', function(req, res){16- res.send(req.path);17- });18-19- assert.response(app,20- { url: '/search?q=tobi' },21- { body: '/search' });22- },23-24- 'test #isXMLHttpRequest': function(){25- var app = express.createServer();26-27- app.get('/isxhr', function(req, res){28- assert.equal(req.xhr, req.isXMLHttpRequest);29- res.send(req.isXMLHttpRequest30- ? 'yeaaa boy'31- : 'nope');32- });33- 34- assert.response(app,35- { url: '/isxhr' },36- { body: 'nope' });37- 38- assert.response(app,39- { url: '/isxhr', headers: { 'X-Requested-With': 'XMLHttpRequest' } },40- { body: 'yeaaa boy' });41- },42- 43- 'test #header()': function(){44- var app = express.createServer();45- 46- app.get('/', function(req, res){47- req.header('Host').should.equal('foo.com');48- req.header('host').should.equal('foo.com');49- res.send('wahoo');50- });51- 52- assert.response(app,53- { url: '/', headers: { Host: 'foo.com' }},54- { body: 'wahoo' });55- },56- 57- 'test #accepts()': function(){58- var app = express.createServer();59- 60- app.get('/all', function(req, res){61- req.accepts('html').should.be.true;62- req.accepts('.html').should.be.true;63- req.accepts('json').should.be.true;64- req.accepts('.json').should.be.true;65- res.send('ok');66- });67- 68- app.get('/', function(req, res){69- req.accepts('html').should.be.true;70- req.accepts('.html').should.be.true;71- req.accepts('text/html').should.be.true;72- req.accepts('text/*').should.be.true;73- req.accepts('json').should.be.true;74- req.accepts('application/json').should.be.true;75- 76- req.accepts('xml').should.be.false;77- req.accepts('image/*').should.be.false;78- req.accepts('png').should.be.false;79- req.accepts().should.be.false;80- res.send('ok');81- });82- 83- app.get('/type', function(req, res){84- req.accepts('html').should.be.true;85- req.accepts('text/html').should.be.true;86- req.accepts('json').should.be.true;87- req.accepts('application/json').should.be.true;88- 89- req.accepts('png').should.be.false;90- req.accepts('image/png').should.be.false;91- res.send('ok'); 92- });93- 94- assert.response(app,95- { url: '/all', headers: { Accept: '*/*' }},96- { body: 'ok' });97- assert.response(app,98- { url: '/type', headers: { Accept: 'text/*; application/*' }},99- { body: 'ok' });100- assert.response(app,101- { url: '/', headers: { Accept: 'text/html; application/json; text/*' }},102- { body: 'ok' });103- },104- 105- 'test #param()': function(){106- var app = express.createServer(107- connect.bodyParser()108- );109- 110- app.get('/user/:id?', function(req, res){111- res.send('user ' + req.param('id', 'unknown'));112- });113- 114- app.post('/user', function(req, res){115- res.send('user ' + req.param('id'));116- });117-118- app.get('/:sort', function(req, res){119- res.send('sort ' + req.param('sort'));120- });121-122- assert.response(app,123- { url: '/asc' },124- { body: 'sort asc' });125-126- assert.response(app,127- { url: '/user/12' },128- { body: 'user 12' });129- 130- assert.response(app,131- { url: '/user?id=5' },132- { body: 'user 5' });133- 134- assert.response(app,135- { url: '/user' },136- { body: 'user unknown' });137- 138- assert.response(app,139- { url: '/user', method: 'POST', data: 'id=1', headers: { 'Content-Type': 'application/x-www-form-urlencoded' }},140- { body: 'user 1' });141- },142- 143- 'test #notify()': function(){144- var app = express.createServer(145- connect.cookieParser()146- , connect.session({ secret: 'something' })147- );148-149- app.formatters = {150- u: function(val){151- return String(val).toUpperCase();152- }153- };154-155- app.get('/', function(req, res){156- req.notify('info').should.be.empty;157- req.notify('error').should.be.empty;158- req.notify().should.eql({});159- req.session.notifications.should.eql({});160-161- req.notify('info', 'one').should.equal(1);162- req.notify('info', 'two').should.equal(2);163- req.notify('info').should.eql(['one', 'two']);164- req.notify('info').should.eql([]);165- 166- req.notify('info', 'one').should.equal(1);167- req.notify('info').should.eql(['one']);168- 169- req.notify('info', 'Email _sent_.');170- req.notify('info', '<em>%s</em>', 'html');171- req.notify('info').should.eql(['Email <em>sent</em>.', '<em>html</em>']);172- 173- req.notify('info', 'Welcome _%s_ to %s', 'TJ', 'something');174- req.notify('info').should.eql(['Welcome <em>TJ</em> to something']);175-176- req.notify('info', 'Test %s', '<script>');177- req.notify('info').should.eql(['Test <script>']);178-179- req.notify('info', 'TJ has %d pets', 5.12323);180- req.notify('info').should.eql(['TJ has 5 pets']);181- 182- req.notify('error', 'Foo %u', 'bar');183- req.notify('error').should.eql(['Foo BAR']);184-185- res.send('ok');186- });187- 188- assert.response(app,189- { url: '/' },190- { body: 'ok' });191- },192- 193- 'test #is()': function(){194- var app = express.createServer();195-196- app.is('an image', function(req){197- return 0 == req.headers['content-type'].indexOf('image');198- });199- 200- app.is('text', function(req){201- return 0 == req.headers['content-type'].indexOf('text');202- });203-204- app.get('/', function(req, res, next){205- if (req.is('html')) return res.send('html');206- res.send('not sure');207- });208- 209- app.post('/', function(req, res, next){210- if (req.is('html')) return res.send('/ html');211- if (req.is('json')) return res.send('/ json');212- if (req.is('png')) return res.send('/ png');213- res.send('/ not sure');214- });215- 216- app.post('/long', function(req, res, next){217- if (req.is('text/html')) return res.send('/long html');218- if (req.is('application/json')) return res.send('/long json');219- if (req.is('image/png')) return res.send('/long png');220- res.send('/long not sure');221- });222- 223- app.put('/custom', function(req, res, next){224- if (req.is('an image')) return res.send('/custom an image');225- if (req.is('text')) return res.send('/custom text');226- });227-228- assert.response(app,229- { url: '/' },230- { body: 'not sure' });231-232- assert.response(app,233- { url: '/', method: 'POST', headers: { 'Content-Type': 'text/html' }},234- { body: '/ html' });235- assert.response(app,236- { url: '/', method: 'POST', headers: { 'Content-Type': 'application/json; charset=utf-8' }},237- { body: '/ json' });238- assert.response(app,239- { url: '/', method: 'POST', headers: { 'Content-Type': 'image/png' }},240- { body: '/ png' });241- assert.response(app,242- { url: '/', method: 'POST' },243- { body: '/ not sure' });244-245- assert.response(app,246- { url: '/long', method: 'POST', headers: { 'Content-Type': 'text/html' }},247- { body: '/long html' });248- assert.response(app,249- { url: '/long', method: 'POST', headers: { 'Content-Type': 'application/json; charset=utf-8' }},250- { body: '/long json' });251- assert.response(app,252- { url: '/long', method: 'POST', headers: { 'Content-Type': 'image/png' }},253- { body: '/long png' });254- assert.response(app,255- { url: '/long', method: 'POST' },256- { body: '/long not sure' });257- 258- assert.response(app,259- { url: '/custom', method: 'PUT', headers: { 'Content-Type': 'text/plain' }},260- { body: '/custom text' });261- assert.response(app,262- { url: '/custom', method: 'PUT', headers: { 'Content-Type': 'text/html' }},263- { body: '/custom text' });264- assert.response(app,265- { url: '/custom', method: 'PUT', headers: { 'Content-Type': 'image/jpeg' }},266- { body: '/custom an image' });267- assert.response(app,268- { url: '/custom', method: 'PUT', headers: { 'Content-Type': 'image/png' }},269- { body: '/custom an image' });270- },271- 272- 'test #is() wildcard': function(){273- var app = express.createServer();274-275- app.post('/', function(req, res, next){276- if (req.is('image/*')) return res.send('image');277- if (req.is('*/json')) return res.send('json');278- res.send('not sure');279- });280-281- assert.response(app,282- { url: '/', method: 'POST', headers: { 'Content-Type': 'image/png' }},283- { body: 'image' });284- assert.response(app,285- { url: '/', method: 'POST', headers: { 'Content-Type': 'image/jpeg' }},286- { body: 'image' });287- assert.response(app,288- { url: '/', method: 'POST', headers: { 'Content-Type': 'text/plain' }},289- { body: 'not sure' });290- assert.response(app,291- { url: '/', method: 'POST', headers: { 'Content-Type': 'text/json' }},292- { body: 'json' });293- assert.response(app,294- { url: '/', method: 'POST', headers: { 'Content-Type': 'application/json' }},295- { body: 'json' });296- },297- 298- 'test #header() referrer': function(){299- var app = express.createServer();300-301- app.get('/correct', function(req, res){302- res.send(req.header('Referrer'));303- });304- 305- app.get('/incorrect', function(req, res){306- res.send(req.header('Referer'));307- });308-309- assert.response(app,310- { url: '/correct', headers: { Referer: 'expressjs.com' }},311- { body: 'expressjs.com' });312-313- assert.response(app,314- { url: '/correct', headers: { Referrer: 'expressjs.com' }},315- { body: 'expressjs.com' });316-317- assert.response(app,318- { url: '/incorrect', headers: { Referrer: 'expressjs.com' }},319- { body: 'expressjs.com' });320-321- assert.response(app,322- { url: '/incorrect', headers: { Referer: 'expressjs.com' }},323- { body: 'expressjs.com' });324- },325- 326- 'test #get(field, param)': function(){327- var app = express.createServer();328-329- app.get('/', function(req, res, next){330- req.get('content-disposition', 'filename')331- .should.equal('foo bar.jpg');332-333- req.get('Content-Disposition', 'filename')334- .should.equal('foo bar.jpg');335-336- req.get('x-content-foo', 'foo').should.equal('bar');337- req.get('x-content-foo', 'bar').should.equal('foo bar baz');338- req.get('x-content-foo', 'woot').should.equal('tobi loki jane');339- req.get('cache-control', 'max-age').should.equal('500');340-341- req.get('foo').should.equal('');342- req.get('foo', 'bar').should.equal('');343- res.end();344- });345-346- var fields = {347- 'Content-Disposition': 'attachment; filename="foo bar.jpg"'348- , 'X-Content-Foo': 'foo=bar; bar=foo bar baz; woot=tobi loki jane;'349- , 'Cache-Control': 'max-age = 500'350- };351-352- assert.response(app,353- { url: '/', headers: fields },354- { body: '' });355- }356-};deleted:test/response.test.js-769 removed
1-2-/**3- * Module dependencies.4- */5-6-var express = require('express')7- , Stream = require('stream').Stream8- , assert = require('assert')9- , should = require('should');10-11-module.exports = {12- 'test #json()': function(){13- var app = express.createServer()14- , json = 'application/json; charset=utf-8';15-16- app.get('/user', function(req, res, next){17- res.json({ name: 'tj' });18- });19-20- app.get('/string', function(req, res, next){21- res.json('whoop!');22- });23-24- app.get('/error', function(req, res, next){25- res.json(500, 'oh noes!');26- });27-28- assert.response(app,29- { url: '/error' },30- { body: '"oh noes!"'31- , status: 50032- , headers: { 'Content-Type': json }});33-34- assert.response(app,35- { url: '/string' },36- { body: '"whoop!"'37- , headers: {38- 'Content-Type': json39- , 'Content-Length': 840- }});41-42- assert.response(app,43- { url: '/user' },44- { body: '{"name":"tj"}', headers: { 'Content-Type': json }});45- },46- 47- 'test #status()': function(){48- var app = express.createServer();49- 50- app.get('/error', function(req, res, next){51- res.status(500).send('OH NO');52- });53- 54- assert.response(app,55- { url: '/error' },56- { body: 'OH NO', status: 500 });57- },58- 59- 'test #send()': function(){60- var app = express.createServer();61- 62- app.get('/html', function(req, res){63- res.send('<p>test</p>');64- });65- 66- app.get('/json', function(req, res){67- res.header('X-Foo', 'bar');68- res.send(201, { foo: 'bar' });69- });70- 71- app.get('/text', function(req, res){72- res.header('X-Foo', 'bar').contentType('txt');73- res.send('wahoo');74- });75- 76- app.get('/status', function(req, res){77- res.send(404);78- });79- 80- app.get('/status/text', function(req, res){81- res.send(404, 'Oh noes!');82- });83- 84- app.get('/error', function(req, res){85- res.header('Content-Type', 'text/plain');86- res.send(500, 'Oh shit!');87- });88- 89- app.get('/buffer', function(req, res){90- res.send(new Buffer('wahoo!'));91- });92- 93- app.get('/204', function(req, res, next){94- res.send(204);95- });96-97- app.get('/null', function(req, res, next){98- res.send(null);99- });100-101- app.get('/undefined', function(req, res, next){102- res.send(undefined);103- });104- 105- app.get('/bool', function(req, res, next){106- res.send(true);107- });108- 109- assert.response(app,110- { url: '/bool' },111- { body: 'true'112- , headers: { 'Content-Type': 'application/json; charset=utf-8' }});113- 114- assert.response(app,115- { url: '/html' },116- { body: '<p>test</p>'117- , headers: {118- 'Content-Type': 'text/html; charset=utf-8'119- }});120- 121- assert.response(app,122- { url: '/json' },123- { body: '{"foo":"bar"}'124- , status: 201125- , headers: {126- 'Content-Type': 'application/json; charset=utf-8'127- , 'X-Foo': 'bar'128- }});129- 130- assert.response(app,131- { url: '/text' },132- { body: 'wahoo'133- , headers: {134- 'Content-Type': 'text/plain'135- , 'X-Foo': 'bar'136- }});137- 138- assert.response(app,139- { url: '/status/text' },140- { body: 'Oh noes!', status: 404 });141- 142- assert.response(app,143- { url: '/status' },144- { body: 'Not Found'145- , status: 404146- , headers: { 'Content-Type': 'text/plain' }});147- 148- assert.response(app,149- { url: '/error' },150- { body: 'Oh shit!'151- , status: 500152- , headers: {153- 'Content-Type': 'text/plain'154- , 'Content-Length': '8'155- }});156- 157- assert.response(app,158- { url: '/buffer' },159- { body: 'wahoo!'160- , headers: {161- 'Content-Type': 'application/octet-stream'162- , 'Content-Length': '6'163- }});164- 165- assert.response(app,166- { url: '/204' },167- { status: 204 }, function(res){168- assert.equal(undefined, res.headers['content-type']);169- assert.equal(undefined, res.headers['content-length']);170- });171-172- assert.response(app,173- { url: '/null' },174- { body: '' });175-176- assert.response(app,177- { url: '/undefined' },178- { body: '' });179- 180- assert.response(app,181- { url: '/json?callback=test' },182- { body: '{"foo":"bar"}'183- , status: 201184- , headers: {185- 'Content-Type': 'application/json; charset=utf-8'186- , 'X-Foo': 'bar'187- }});188- },189- 190- 'test #send() JSONP': function(){191- var app = express.createServer();192- 193- app.enable('jsonp callback');194- 195- app.get('/jsonp', function(req, res){196- res.header('X-Foo', 'bar');197- res.send(201, { foo: 'bar' });198- });199- 200- assert.response(app,201- { url: '/jsonp?callback=test' },202- { body: 'test({"foo":"bar"});'203- , status: 201204- , headers: {205- 'Content-Type': 'text/javascript; charset=utf-8'206- , 'X-Foo': 'bar'207- }});208- 209- assert.response(app,210- { url: '/jsonp?callback=baz' },211- { body: 'baz({"foo":"bar"});'212- , status: 201, headers: {213- 'Content-Type': 'text/javascript; charset=utf-8'214- , 'X-Foo': 'bar'215- }});216- 217- assert.response(app,218- { url: '/jsonp?callback=invalid()[]' },219- { body: 'invalid({"foo":"bar"});'220- , status: 201221- , headers: {222- 'Content-Type': 'text/javascript; charset=utf-8'223- , 'X-Foo': 'bar'224- }});225- },226- 227- 'test #json() JSONP': function(){228- var app = express.createServer();229- 230- app.enable('jsonp callback');231- 232- app.get('/jsonp', function(req, res){233- res.header('X-Foo', 'bar');234- res.json(201, { foo: 'bar' });235- });236- 237- assert.response(app,238- { url: '/jsonp?callback=test' },239- { body: 'test({"foo":"bar"});'240- , status: 201241- , headers: {242- 'Content-Type': 'text/javascript; charset=utf-8'243- , 'X-Foo': 'bar'244- }});245- 246- assert.response(app,247- { url: '/jsonp?callback=baz' },248- { body: 'baz({"foo":"bar"});'249- , status: 201, headers: {250- 'Content-Type': 'text/javascript; charset=utf-8'251- , 'X-Foo': 'bar'252- }});253- 254- assert.response(app,255- { url: '/jsonp?callback=invalid()[]' },256- { body: 'invalid({"foo":"bar"});'257- , status: 201258- , headers: {259- 'Content-Type': 'text/javascript; charset=utf-8'260- , 'X-Foo': 'bar'261- }});262- },263- 264- 'test #contentType()': function(){265- var app = express.createServer();266- 267- app.get('/html', function(req, res){268- res.contentType('index.html');269- res.writeHead(200, res.headers);270- res.end('<p>yay</p>');271- });272- 273- app.get('/json', function(req, res, next){274- res.contentType('json');275- res.send('{"foo":"bar"}');276- });277- 278- app.get('/literal', function(req, res){279- res.contentType('application/json');280- res.send('{"foo":"bar"}')281- });282- 283- assert.response(app,284- { url: '/literal' },285- { headers: { 'Content-Type': 'application/json' }}); 286- assert.response(app,287- { url: '/html' },288- { body: '<p>yay</p>', headers: { 'Content-Type': 'text/html' }});289- assert.response(app,290- { url: '/json' },291- { headers: { 'Content-Type': 'application/json' }});292- },293- 294- 'test #attachment()': function(){295- var app = express.createServer();296- 297- app.get('/style.css', function(req, res){298- res.attachment();299- res.send('some stylezzz');300- });301- 302- app.get('/*', function(req, res){303- res.attachment(req.params[0]);304- res.send('whatever');305- });306- 307- assert.response(app,308- { url: '/javascripts/jquery.js' },309- { body: 'whatever'310- , headers: { 'Content-Type': 'application/javascript'311- , 'Content-Disposition': 'attachment; filename="jquery.js"' }});312- 313- assert.response(app,314- { url: '/style.css' },315- { body: 'some stylezzz'316- , headers: { 'Content-Type': 'text/html; charset=utf-8'317- , 'Content-Disposition': 'attachment' }});318- },319- 320- 'test #redirect()': function(){321- var app = express.createServer()322- , app2 = express.createServer();323- 324- app2.set('basepath', '/blog');325- 326- app2.redirect('google', 'http://google.com');327- 328- app2.redirect('blog', function(req, res){329- return req.params.id330- ? '/user/' + req.params.id + '/posts'331- : null;332- });333- 334- app.get('/', function(req, res){335- res.redirect('http://google.com', 301);336- });337- 338- app.get('/back', function(req, res){339- res.redirect('back');340- });341- 342- app.get('/home', function(req, res){343- res.redirect('home');344- });345- 346- app.get('/html', function(req, res){347- res.redirect('http://google.com');348- });349- 350- app2.get('/', function(req, res){351- res.redirect('http://google.com', 301);352- });353- 354- app2.get('/back', function(req, res){355- res.redirect('back');356- });357- 358- app2.get('/home', function(req, res){359- res.redirect('home');360- });361- 362- app2.get('/google', function(req, res){363- res.redirect('google');364- });365- 366- app2.get('/user/:id', function(req, res){367- res.header('X-Foo', 'bar');368- res.redirect('blog');369- });370- 371- assert.response(app,372- { url: '/html', headers: { Accept: 'text/html,text/plain', Host: 'foo.com' }},373- { body: '<p>Moved Temporarily. Redirecting to <a href="http://google.com">http://google.com</a></p>' });374- 375- assert.response(app,376- { url: '/', headers: { Accept: 'text/plain', Host: 'foo.com' }},377- { body: 'Moved Permanently. Redirecting to http://google.com'378- , status: 301, headers: { Location: 'http://google.com' }});379- 380- assert.response(app,381- { url: '/back', headers: { Accept: 'text/plain', Host: 'foo.com' }},382- { body: 'Moved Temporarily. Redirecting to http://foo.com/'383- , status: 302, headers: { Location: 'http://foo.com/', 'Content-Type': 'text/plain' }});384- 385- assert.response(app,386- { url: '/back', headers: { Referer: '/foo', Accept: 'text/plain', Host: 'foo.com' }},387- { body: 'Moved Temporarily. Redirecting to http://foo.com/foo'388- , status: 302, headers: { Location: 'http://foo.com/foo' }});389- 390- assert.response(app,391- { url: '/back', headers: { Referrer: '/foo', Accept: 'text/plain', Host: 'foo.com' }},392- { body: 'Moved Temporarily. Redirecting to http://foo.com/foo'393- , status: 302, headers: { Location: 'http://foo.com/foo' }});394- 395- assert.response(app,396- { url: '/home', headers: { Accept: 'text/plain', Host: 'foo.com' } },397- { body: 'Moved Temporarily. Redirecting to http://foo.com/'398- , status: 302, headers: { Location: 'http://foo.com/' }});399- 400- assert.response(app2,401- { url: '/', headers: { Accept: 'text/plain', Host: 'foo.com' }},402- { body: 'Moved Permanently. Redirecting to http://google.com'403- , status: 301, headers: { Location: 'http://google.com' }});404- 405- assert.response(app2,406- { url: '/back', headers: { Accept: 'text/plain', Host: 'foo.com' }},407- { body: 'Moved Temporarily. Redirecting to http://foo.com/blog'408- , status: 302, headers: { Location: 'http://foo.com/blog' }});409- 410- assert.response(app2,411- { url: '/home', headers: { Accept: 'text/plain', Host: 'foo.com' }},412- { body: 'Moved Temporarily. Redirecting to http://foo.com/blog'413- , status: 302, headers: { Location: 'http://foo.com/blog' }});414- 415- assert.response(app2,416- { url: '/google', headers: { Accept: 'text/plain', Host: 'foo.com' }},417- { body: 'Moved Temporarily. Redirecting to http://google.com'418- , status: 302, headers: { Location: 'http://google.com' }});419- 420- assert.response(app2,421- { url: '/user/12', headers: { Accept: 'text/plain', Host: 'foo.com' }},422- { body: 'Moved Temporarily. Redirecting to http://foo.com/blog/user/12/posts'423- , status: 302, headers: { Location: 'http://foo.com/blog/user/12/posts', 'X-Foo': 'bar' }});424- },425- 426- 'test #redirect() when mounted': function(){427- var app = express.createServer()428- , blog = express.createServer();429- 430- 431- blog.get('/posts', function(req, res){432- res.redirect('/posts/all');433- });434- 435- blog.get('/posts/all', function(req, res){436- res.send('all blog posts');437- });438- 439- app.use('/blog', blog);440- 441- assert.response(app,442- { url: '/blog/posts', headers: { Host: 'foo.com' }},443- { status: 302444- , headers: { Location: 'http://foo.com/blog/posts/all' }});445- },446- 447- 'test #sendfile()': function(){448- var app = express.createServer();449- 450- app.get('/*', function(req, res, next){451- var file = req.params[0]452- , path = __dirname + '/fixtures/' + file;453- res.sendfile(path);454- });455- 456- app.use(express.errorHandler());457- 458- assert.response(app,459- { url: '/../express.test.js' },460- { body: 'Forbidden', status: 403 });461- 462- assert.response(app,463- { url: '/user.json' },464- { body: '{"name":"tj"}'465- , status: 200, headers: { 'Content-Type': 'application/json' }});466- 467- assert.response(app,468- { url: '/hello.haml' },469- { body: '%p Hello World'470- , status: 200, headers: { 'Content-Type': 'application/octet-stream' }});471- 472- assert.response(app,473- { url: '/doesNotExist' },474- { body: 'Cannot GET /doesNotExist', status: 404 });475- 476- assert.response(app,477- { url: '/partials' },478- { body: 'Cannot GET /partials', status: 404 });479- 480- assert.response(app,481- { url: '/large.json' },482- { status: 200, headers: { 'Content-Type': 'application/json' }});483- },484- 485- 'test #sendfile(path, callback)': function(beforeExit){486- var app = express.createServer()487- , calls = 0;488- 489- app.get('/*', function(req, res, next){490- var file = req.params[0]491- , path = __dirname + '/fixtures/' + file;492- res.sendfile(path, function(err){493- if (err) return res.send('got an error');494- ++calls;495- });496- });497- 498- assert.response(app,499- { url: '/does-not-exist' },500- { body: 'Cannot GET /does-not-exist' });501- 502- assert.response(app,503- { url: '/large.json' },504- { headers: { 'Accept-Ranges': 'bytes' }});505- 506- beforeExit(function(){507- calls.should.equal(1);508- });509- },510- 511- 'test #sendfile(path, options, callback)': function(beforeExit){512- var app = express.createServer()513- , calls = 0;514- 515- app.get('/*', function(req, res, next){516- var file = req.params[0]517- , path = __dirname + '/fixtures/' + file;518- res.sendfile(path, { maxAge: 3600000 }, function(err){519- if (err) return res.send('got an error');520- ++calls;521- });522- });523- 524- assert.response(app,525- { url: '/does-not-exist' },526- { body: 'Cannot GET /does-not-exist' });527- 528- assert.response(app,529- { url: '/large.json' },530- { headers: {531- 'Accept-Ranges': 'bytes'532- , 'Cache-Control': 'public, max-age=3600'533- }});534- 535- beforeExit(function(){536- calls.should.equal(1);537- });538- },539- 540- 'test #sendfile() Accept-Ranges': function(){541- var app = express.createServer();542- 543- app.get('/*', function(req, res, next){544- var file = req.params[0]545- , path = __dirname + '/fixtures/' + file;546- res.sendfile(path);547- });548- 549- assert.response(app,550- { url: '/large.json' },551- { headers: { 'Accept-Ranges': 'bytes' }});552- },553- 554- 'test #sendfile() Range': function(){555- var app = express.createServer();556- 557- app.get('/*', function(req, res, next){558- var file = req.params[0]559- , path = __dirname + '/fixtures/' + file;560- res.sendfile(path);561- });562- 563- assert.response(app,564- { url: '/large.json', headers: { 'Range': 'bytes=0-499' }},565- { headers: {566- 'Content-Type': 'application/json',567- 'Content-Range': 'bytes 0-499/2535'568- }, status: 206 });569- },570- 571- 'test #sendfile() Range invalid syntax': function(){572- var app = express.createServer();573- 574- app.get('/*', function(req, res, next){575- var file = req.params[0]576- , path = __dirname + '/fixtures/' + file;577- res.sendfile(path);578- });579- 580- assert.response(app,581- { url: '/large.json', headers: { 'Range': 'basdytes=asdf' }},582- { body: /Requested Range Not Satisfiable/, status: 416 });583- },584- 585- 'test #sendfile() Range invalid range': function(){586- var app = express.createServer();587- 588- app.get('/*', function(req, res, next){589- var file = req.params[0]590- , path = __dirname + '/fixtures/' + file;591- res.sendfile(path);592- });593- 594- assert.response(app,595- { url: '/large.json', headers: { 'Range': 'bytes=500-10' }},596- { body: /Requested Range Not Satisfiable/, status: 416 });597- },598- 599- 'test #download()': function(beforeExit){600- var app = express.createServer()601- , calls = 0;602- 603- app.get('/json', function(req, res, next){604- var path = __dirname + '/fixtures/user.json';605- res.download(path, 'account.json');606- });607- 608- app.get('/callback', function(req, res, next){609- res.download(__dirname + '/fixtures/pets.json', function(err){610- ++calls;611- });612- });613- 614- app.get('/*', function(req, res, next){615- res.download(__dirname + '/fixtures/' + req.params[0]);616- });617- 618- assert.response(app,619- { url: '/callback' },620- { body: '["tobi", "loki", "jane"]' });621- 622- assert.response(app,623- { url: '/user.json' },624- { body: '{"name":"tj"}', status: 200, headers: {625- 'Content-Type': 'application/json',626- 'Content-Disposition': 'attachment; filename="user.json"'627- }});628- 629- assert.response(app,630- { url: '/json' },631- { body: '{"name":"tj"}', status: 200, headers: {632- 'Content-Type': 'application/json',633- 'Content-Length': '13',634- 'Content-Disposition': 'attachment; filename="account.json"'635- }});636- 637- assert.response(app,638- { url: '/missing' },639- function(res){640- assert.equal(null, res.headers['content-disposition']);641- });642- 643- assert.response(app,644- { url: '/some%20random%20text%20file.txt' },645- { body: 'hello' });646- 647- beforeExit(function(){648- calls.should.equal(1);649- });650- },651- 652- 'test #cookie() path default': function(){653- var app = express.createServer();654- 655- app.set('basepath', '/foo');656- 657- app.get('/', function(req, res){658- res.cookie('rememberme', 'yes', { expires: new Date(1), httpOnly: true });659- res.cookie('something', 'else');660- res.redirect('/');661- });662- 663- assert.response(app,664- { url: '/', headers: { Host: 'foo.com' }},665- function(res){666- res.headers['set-cookie']667- .should.eql(['rememberme=yes; path=/foo; expires=Thu, 01 Jan 1970 00:00:00 GMT; httpOnly', 'something=else; path=/foo']);668- });669- },670- 671- 'test #cookie() explicit path': function(){672- var app = express.createServer();673- 674- app.set('/home', '/foo');675- 676- app.get('/', function(req, res){677- res.cookie('rememberme', 'yes', { path: '/', expires: new Date(1), httpOnly: true });678- res.cookie('something', 'else', { path: '/' });679- res.redirect('/');680- });681- 682- assert.response(app,683- { url: '/', headers: { Host: 'foo.com' }},684- function(res){685- res.headers['set-cookie']686- .should.eql(['rememberme=yes; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT; httpOnly', 'something=else; path=/']);687- });688- },689- 690- 'test #cookie() null path': function(){691- var app = express.createServer();692- 693- app.set('/home', '/foo');694- 695- app.get('/', function(req, res){696- res.cookie('rememberme', 'yes', { path: null, expires: new Date(1), httpOnly: true });697- res.cookie('something', 'else', { path: null });698- res.redirect('/');699- });700- 701- assert.response(app,702- { url: '/', headers: { Host: 'foo.com' }},703- function(res){704- res.headers['set-cookie']705- .should.eql(['rememberme=yes; expires=Thu, 01 Jan 1970 00:00:00 GMT; httpOnly', 'something=else']);706- });707- },708- 709- 'test #clearCookie() default path': function(){710- var app = express.createServer();711- 712- app.set('basepath', '/foo');713- 714- app.get('/', function(req, res){715- res.clearCookie('rememberme');716- res.redirect('/');717- });718- 719- assert.response(app,720- { url: '/' },721- function(res){722- res.headers['set-cookie']723- .should.eql(['rememberme=; path=/foo; expires=Thu, 01 Jan 1970 00:00:00 GMT']);724- });725- },726- 727- 'test #clearCookie() explicit path': function(){728- var app = express.createServer();729- 730- app.set('basepath', '/bar');731- 732- app.get('/', function(req, res){733- res.clearCookie('rememberme', { path: '/foo' });734- res.redirect('/');735- });736- 737- assert.response(app,738- { url: '/' },739- function(res){740- res.headers['set-cookie']741- .should.eql(['rememberme=; path=/foo; expires=Thu, 01 Jan 1970 00:00:00 GMT']);742- });743- },744- 745- 'test HEAD': function(){746- var app = express.createServer();747- 748- app.get('/', function(req, res, next){749- res.send('Hello World');750- });751- 752- assert.response(app,753- { url: '/', method: 'HEAD' },754- { body: '', headers: { 'Content-Length': 11 }});755- },756- 757- 'test .charset with res.send()': function(){758- var app = express.createServer();759- 760- app.get('/', function(req, res){761- res.charset = 'ISO-8859-1';762- res.send('<p>hey</p>');763- });764- 765- assert.response(app,766- { url: '/' },767- { headers: { 'Content-Type': 'text/html; charset=ISO-8859-1' }});768- }769-};deleted:test/router.test.js-837 removed
1-2-/**3- * Module dependencies.4- */5-6-var express = require('express')7- , connect = require('connect')8- , assert = require('assert')9- , should = require('should')10- , Route = express.Route;11-12-module.exports = {13- 'test route middleware': function(beforeExit){14- var app = express.createServer()15- , calls = 0;16-17- function allow(role) {18- return function(req, res, next) {19- // this is totally not real, dont use this :)20- // for tests only21- if (req.headers['x-role'] == role) {22- next();23- } else {24- res.send(401);25- }26- }27- }28- 29- function restrictAge(age) {30- return function(req, res, next){31- if (req.headers['x-age'] >= age) {32- next();33- } else {34- res.send(403);35- }36- }37- }38-39- app.param('user', function(req, res, next, user){40- ++calls;41- next();42- });43-44- app.get('/xxx', allow('member'), restrictAge(18), function(req, res){45- res.send(200);46- });47-48- app.get('/booze', [allow('member')], restrictAge(18), function(req, res){49- res.send(200);50- });51-52- app.get('/tobi', [allow('member')], [[restrictAge(18)]], function(req, res){53- res.send(200);54- });55- 56- app.get('/user/:user', [allow('member'), [[restrictAge(18)]]], function(req, res){57- res.send(200);58- });59-60- ['xxx', 'booze', 'tobi', 'user/tj'].forEach(function(thing){61- assert.response(app,62- { url: '/' + thing },63- { body: 'Unauthorized', status: 401 });64- assert.response(app,65- { url: '/' + thing, headers: { 'X-Role': 'member' }},66- { body: 'Forbidden', status: 403 });67- assert.response(app,68- { url: '/' + thing, headers: { 'X-Role': 'member', 'X-Age': 18 }},69- { body: 'OK', status: 200 });70- });71-72- beforeExit(function(){73- calls.should.equal(3);74- });75- },76-77- 'test app.param() multiple mapping functions': function(){78- var app = express.createServer();79-80- app.param(function(name, fn){81- if (fn.length < 3) {82- return function(req, res, next, val){83- val = req.params[name] = fn(val);84- if (false === val) {85- next('route');86- } else {87- next();88- }89- };90- }91- });92-93- app.param(function(name, range){94- if (!~String(range).indexOf('..')) return;95- var parts = range.split('..')96- , from = parseInt(parts.shift())97- , to = parseInt(parts.shift());98-99- return function(req, res, next, val){100- if (val < from || val > to) return next('route');101- next();102- }103- });104-105- app.param('user', Number);106- app.param('user', '0..5');107-108- app.get('/user/:user', function(req, res){109- res.json(req.params.user);110- });111-112- assert.response(app,113- { url: '/user/3' },114- { body: '3' });115-116- assert.response(app,117- { url: '/user/6' },118- { status: 404 });119- },120-121- 'test app.param() name passing': function(){122- var app = express.createServer();123- 124- app.param(function(name, fn){125- if (fn.length < 3) {126- return function(req, res, next, val){127- val = req.params[name] = fn(val);128- if (false === val) {129- next('route');130- } else {131- next();132- }133- };134- }135- });136-137- function within(a, b) {138- return function(req, res, next, val, name){139- if (val < a || val > b) {140- return next(new Error(name + ' should be within ' + a + '..' + b));141- }142- next();143- }144- }145-146- app.param('user', Number);147- app.param('user', within(0, 5));148-149- app.get('/user/:user', function(req, res){150- res.json(req.params.user);151- });152-153- app.use(function(err, req, res, next){154- res.json({ error: err.message });155- });156-157- assert.response(app,158- { url: '/user/0' },159- { body: '0' });160-161- assert.response(app,162- { url: '/user/6' },163- { body: '{"error":"user should be within 0..5"}' });164- },165-166- 'test app.param() multiple callbacks and array of params': function(){167- var app = express.createServer();168- var users = [{ name: 'tj' }];169- var pets = [['tobi', 'loki', 'jane', 'manny', 'luna']];170-171- function loadUser(req, res, next, id) {172- req.user = users[id];173- next();174- }175-176- function loadUserPets(req, res, next, id) {177- req.user.pets = pets[id];178- next();179- }180-181- app.param(['user_id', 'user'], loadUser, loadUserPets);182-183- app.get('/user/:user_id', function(req, res){184- res.send(req.user);185- });186-187- app.get('/account/:user', function(req, res){188- res.send(req.user);189- });190-191- assert.response(app,192- { url: '/account/0' },193- { body: '{"name":"tj","pets":["tobi","loki","jane","manny","luna"]}' });194-195- assert.response(app,196- { url: '/user/0' },197- { body: '{"name":"tj","pets":["tobi","loki","jane","manny","luna"]}' });198- },199-200- 'test app.param() multiple callbacks': function(){201- var app = express.createServer();202- var users = [{ name: 'tj' }];203- var pets = [['tobi', 'loki', 'jane', 'manny', 'luna']];204-205- function loadUser(req, res, next, id) {206- req.user = users[id];207- next();208- }209-210- function loadUserPets(req, res, next, id) {211- req.user.pets = pets[id];212- next();213- }214-215- app.param('user_id', loadUser, loadUserPets);216-217- app.get('/user/:user_id', function(req, res){218- res.send(req.user);219- });220-221- assert.response(app,222- { url: '/user/0' },223- { body: '{"name":"tj","pets":["tobi","loki","jane","manny","luna"]}' });224- },225-226- 'test app.param() multiple calls with error': function(){227- var app = express.createServer();228-229- var commits = ['foo', 'bar', 'baz'];230-231- app.param('commit', function(req, res, next, id){232- req.commit = parseInt(id);233- if (isNaN(req.commit)) return next('route');234- next();235- });236-237- app.param('commit', function(req, res, next, id){238- req.commit = commits[req.commit];239- next(new Error('failed'));240- });241-242- app.get('/commit/:commit', function(req, res){243- res.send(req.commit);244- });245-246- assert.response(app,247- { url: '/commit/0' },248- { status: 500 });249- },250-251- 'test app.param() multiple calls': function(){252- var app = express.createServer();253-254- var commits = ['foo', 'bar', 'baz'];255-256- app.param('commit', function(req, res, next, id){257- req.commit = parseInt(id);258- if (isNaN(req.commit)) return next('route');259- next();260- });261-262- app.param('commit', function(req, res, next, id){263- req.commit = commits[req.commit];264- next();265- });266-267- app.get('/commit/:commit', function(req, res){268- res.send(req.commit);269- });270-271- assert.response(app,272- { url: '/commit/0' },273- { body: 'foo' });274-275- assert.response(app,276- { url: '/commit/0x01' },277- { body: 'bar' });278-279- assert.response(app,280- { url: '/commit/asdf' },281- { status: 404 });282- },283-284- 'test app.param(fn)': function(){285- var app = express.createServer();286- 287- app.param(function(name, fn){288- if (fn instanceof RegExp) {289- return function(req, res, next, val){290- var captures;291- if (captures = fn.exec(String(val))) {292- req.params[name] = captures[1];293- next();294- } else {295- next('route');296- }297- }298- }299- });300-301- app.param('commit', /^(\d+)$/);302-303- app.get('/commit/:commit', function(req, res){304- res.send(req.params.commit);305- });306-307- assert.response(app,308- { url: '/commit/12' },309- { body: '12' });310-311- assert.response(app,312- { url: '/commit/asdf' },313- { status: 404 });314- },315-316- 'test precedence': function(){317- var app = express.createServer();318- 319- var hits = [];320- 321- app.all('*', function(req, res, next){322- hits.push('all');323- next();324- });325- 326- app.get('/foo', function(req, res, next){327- hits.push('GET /foo');328- next();329- });330- 331- app.get('/foo', function(req, res, next){332- hits.push('GET /foo2');333- next();334- });335- 336- app.put('/foo', function(req, res, next){337- hits.push('PUT /foo');338- next();339- });340- 341- assert.response(app,342- { url: '/foo' },343- function(){344- hits.should.eql(['all', 'GET /foo', 'GET /foo2']);345- });346- },347- 348- 'test named capture groups': function(){349- var app = express.createServer();350- 351- app.get('/user/:id([0-9]{2,10})', function(req, res){352- res.send('user ' + req.params.id);353- });354- 355- app.post('/pin/save/:lat(\\d+.\\d+)/:long(\\d+.\\d+)', function(req, res){356- res.send(req.params.lat + ' ' + req.params.long);357- });358- 359- app.post('/pin/save2/:lat([0-9]+.[0-9]+)/:long([0-9]+.[0-9]+)', function(req, res){360- res.send(req.params.lat + ' ' + req.params.long);361- });362- 363- assert.response(app,364- { url: '/pin/save/1.2/3.4', method: 'POST' },365- { body: '1.2 3.4' });366- 367- assert.response(app,368- { url: '/pin/save2/1.2/3.4', method: 'POST' },369- { body: '1.2 3.4' });370- 371- assert.response(app,372- { url: '/user/12' },373- { body: 'user 12' });374- 375- assert.response(app,376- { url: '/user/ab' },377- { body: 'Cannot GET /user/ab' });378- },379- 380- 'test named capture group after dot': function(){381- var app = express.createServer();382- 383- app.get('/user/:name.:format?', function(req, res){384- res.send(req.params.name + ' - ' + (req.params.format || ''));385- });386-387- app.get('/commit/:from-:to.:format?', function(req, res, next){388- res.send(req.params.from + '..' + req.params.to + ' ' + (req.params.format || ''));389- });390-391- assert.response(app,392- { url: '/commit/foo-baz.bar.patch' },393- { body: 'foo..baz.bar patch' });394-395- assert.response(app,396- { url: '/commit/foo-baz' },397- { body: 'foo..baz ' });398-399- assert.response(app,400- { url: '/user/foo' },401- { body: 'foo - ' });402- 403- assert.response(app,404- { url: '/user/foo.json' },405- { body: 'foo - json' });406- 407- assert.response(app,408- { url: '/user/foo.bar.json' },409- { body: 'foo.bar - json' });410- },411- 412- 'test optional * value': function(){413- var app = express.createServer();414- 415- app.get('/admin*', function(req, res){416- res.send(req.params[0]);417- });418-419- app.get('/file/*.*', function(req, res){420- res.send(req.params[0] + ' - ' + req.params[1]);421- });422-423- assert.response(app,424- { url: '/file/some.foo.bar' },425- { body: 'some.foo - bar' });426-427- assert.response(app,428- { url: '/admin', },429- { body: '', status: 200 });430-431- assert.response(app,432- { url: '/adminify', },433- { body: 'ify', status: 200 });434- },435- 436- 'test app.param()': function(){437- var app = express.createServer();438- 439- var users = [440- { name: 'tj' }441- , { name: 'tobi' }442- , { name: 'loki' }443- , { name: 'jane' }444- , { name: 'bandit' }445- ];446- 447- app.param('user', function(req, res, next, id){448- if (req.user = users[id]) {449- next();450- } else {451- next(new Error('failed to find user'));452- }453- });454- 455- app.get('/user/:user', function(req, res, next){456- res.send('user ' + req.user.name);457- });458- 459- assert.response(app,460- { url: '/user/0' },461- { body: 'user tj' });462- 463- assert.response(app,464- { url: '/user/1' },465- { body: 'user tobi' });466- },467- 468- 'test app.param() optional execution': function(beforeExit){469- var app = express.createServer()470- , calls = 0;471- 472- var months = ['Jan', 'Feb', 'Mar'];473- 474- app.param('month', function(req, res, next, n){475- req.params.month = months[n];476- ++calls;477- next();478- });479- 480- app.get('/calendar/:month?', function(req, res, next){481- res.send(req.params.month || months[0]);482- });483- 484- assert.response(app,485- { url: '/calendar' },486- { body: 'Jan' });487- 488- assert.response(app,489- { url: '/calendar/1' },490- { body: 'Feb' });491- 492- beforeExit(function(){493- calls.should.equal(1);494- });495- },496- 497- 'test OPTIONS': function(){498- var app = express.createServer();499- 500- app.get('/', function(){});501- app.get('/user/:id', function(){});502- app.put('/user/:id', function(){});503- 504- assert.response(app,505- { url: '/', method: 'OPTIONS' },506- { headers: { Allow: 'GET' }});507- 508- assert.response(app,509- { url: '/user/12', method: 'OPTIONS' },510- { headers: { Allow: 'GET,PUT' }});511- },512-513- 'test app.lookup': function(){514- var app = express.createServer();515- app.get('/user', function(){});516- app.get('/user/:id', function(){});517- app.get('/user/:id/:op?', function(){});518- app.put('/user/:id', function(){});519- app.get('/user/:id/edit', function(){});520- 521- var route = app.get('/user/:id')[0]522- route.should.be.an.instanceof(Route);523- route.callbacks.should.be.an.instanceof(Array);524- route.path.should.equal('/user/:id');525- route.regexp.should.be.an.instanceof(RegExp);526- route.method.should.equal('get');527- route.keys.should.eql([{ name: 'id', optional: false }]);528- 529- app.get('/user').should.have.length(1);530- app.get('/user/:id').should.have.length(1);531- app.get('/user/:id/:op?').should.have.length(1);532- app.put('/user/:id').should.have.length(1);533- app.get('/user/:id/edit').should.have.length(1);534- app.get('/').should.have.be.empty;535- app.all('/user/:id').should.have.length(2);536- 537- app.lookup.get('/user').should.have.length(1);538- app.lookup.get('/user/:id').should.have.length(1);539- app.lookup.get('/user/:id/:op?').should.have.length(1);540- app.lookup.put('/user/:id').should.have.length(1);541- app.lookup.get('/user/:id/edit').should.have.length(1);542- app.lookup.get('/').should.have.be.empty;543- app.lookup.all('/user/:id').should.have.length(2);544- app.lookup('/user/:id').should.have.length(2);545- },546- 547- 'test app.remove': function(){548- var app = express.createServer();549- app.get('/user', function(){});550- app.get('/user', function(){});551- app.put('/user', function(){});552- 553- app.get('/user').should.have.length(2);554- var removed = app.remove.get('/user');555- removed.should.have.length(2);556- 557- var removed = app.remove.get('/user');558- removed.should.have.length(0);559- app.get('/user').should.have.length(0);560- 561- app.get('/user/:id', function(){});562- app.put('/user/:id', function(){});563- app.del('/user/:id', function(){});564- 565- app.remove.all('/user/:id').should.have.length(3);566- app.remove.all('/user/:id').should.have.length(0);567- 568- app.get('/user/:id', function(){});569- app.put('/user/:id', function(){});570- app.del('/user/:id', function(){});571- 572- app.remove('/user/:id').should.have.length(3);573- },574- 575- 'test app.match': function(){576- var app = express.createServer();577- app.get('/user', function(){});578- app.get('/user/:id', function(){});579- app.get('/user/:id/:op?', function(){});580- app.put('/user/:id', function(){});581- app.get('/user/:id/edit', function(){});582- 583- var route = app.match.get('/user/12')[0];584- route.should.be.an.instanceof(Route);585- route.path.should.equal('/user/:id');586- route.regexp.should.be.an.instanceof(RegExp);587- route.method.should.equal('get');588- route.keys.should.eql([{ name: 'id', optional: false }]);589- //route.params.id.should.equal('12');590- 591- app.match.get('/user').should.have.length(1);592- app.match.get('/user/12').should.have.length(2);593- app.match.get('/user/12/:op?').should.have.length(1);594- app.match.put('/user/100').should.have.length(1);595- app.match.get('/user/5/edit').should.have.length(2);596- app.match.get('/').should.have.be.empty;597- app.match.all('/user/123').should.have.length(3);598- app.match('/user/123').should.have.length(3);599- },600-601- 'test app.routes.all()': function(){602- var app = express.createServer();603- app.get('/user', function(){});604- app.get('/user/:id', function(){});605- app.get('/user/:id/:op?', function(){});606- app.put('/user/:id', function(){});607- app.get('/user/:id/edit', function(){});608- app.routes.all()[0].should.be.an.instanceof(Route);609- app.routes.all().length.should.equal(5);610- },611-612- 'test Collection': function(){613- var app = express.createServer();614- app.get('/user', function(){});615- app.get('/user/:id', function(){});616- app.get('/user/:id/:op?', function(){});617- app.put('/user/:id', function(){});618- app.get('/user/:id/edit', function(){});619- 620- var ret = app.match.all('/user/12').remove();621- ret.should.have.length(3);622- app.match.all('/user/12').should.have.length(0);623- app.get('/user/:id').should.have.length(0);624- },625- 626- 'test "strict routing" setting': function(){627- var app = express.createServer();628- 629- app.enable('strict routing');630- 631- app.get('/:path', function(req, res, next){632- res.send({ type: 'directory' });633- });634- 635- app.get('/:path/', function(req, res, next){636- res.send(['.', '..', 'foo.js', 'bar.js']);637- });638- 639- assert.response(app,640- { url: '/lib' },641- { body: '{"type":"directory"}' });642- 643- assert.response(app,644- { url: '/lib/' },645- { body: '[".","..","foo.js","bar.js"]' });646- },647- 648- 'test "case sensitive routes" setting': function(){649- var app = express.createServer();650- 651- app.enable('case sensitive routes');652- 653- app.get('/account', function(req, res){654- res.send('account');655- });656- 657- app.get('/Account', function(req, res){658- res.send('Account');659- });660- 661- assert.response(app,662- { url: '/account' },663- { body: 'account' });664- 665- assert.response(app,666- { url: '/Account' },667- { body: 'Account' });668- },669- 670- 'override OPTIONS default': function(){671- var app = express.createServer();672- 673- app.get('/', function(req, res, next){674- 675- });676- 677- app.options('/foo', function(req, res, next){678- res.header('Allow', 'GET')679- res.send('whatever');680- });681- 682- assert.response(app,683- { url: '/', method: 'OPTIONS' },684- { body: 'GET', headers: { Allow: 'GET' }});685- 686- assert.response(app,687- { url: '/foo', method: 'OPTIONS' },688- { body: 'whatever', headers: { Allow: 'GET' }});689- },690- 691- 'test req.route': function(){692- var app = express.createServer();693- 694- var routes = [];695- 696- app.get('/:foo?', function(req, res, next){697- routes.push(req.route.path);698- next();699- });700- 701- app.get('/foo', function(req, res, next){702- routes.push(req.route.path);703- next();704- });705- 706- assert.response(app,707- { url: '/foo' },708- function(){709- routes.should.eql(['/:foo?', '/foo']);710- });711- },712- 713- 'test route callback error handling': function(){714- var app = express.createServer()715- , calls = [];716-717- app.get('/user/:id', function(req, res, next){718- calls.push('one');719- next();720- });721-722- app.get('/user/:id', function(req, res, next){723- calls.push('two');724- next(new Error('fail'));725- });726-727- app.get('/user/:id', function(req, res, next){728- calls.push('three');729- next();730- });731- 732- app.get('/user/*', function(err, req, res, next){733- res.statusCode = 500;734- res.send('error: ' + err.message);735- });736-737- app.get('/user/*', function(req, res, next){738- calls.push('four');739- next();740- });741-742- assert.response(app,743- { url: '/user/12' },744- { body: 'error: fail' }, function(){745- calls.should.eql(['one', 'two']);746- });747- },748- 749- 'test route callback thrown error handling': function(){750- var app = express.createServer()751- , calls = [];752-753- app.get('/user/:id', function(req, res, next){754- calls.push('one');755- next();756- });757-758- app.get('/user/:id', function(req, res, next){759- calls.push('two');760- throw new Error('fail');761- });762-763- app.get('/user/:id', function(req, res, next){764- calls.push('three');765- next();766- });767- 768- app.get('/user/*', function(err, req, res, next){769- res.statusCode = 500;770- res.send('error: ' + err.message);771- });772-773- app.get('/user/*', function(req, res, next){774- calls.push('four');775- next();776- });777-778- assert.response(app,779- { url: '/user/12' },780- { body: 'error: fail' }, function(){781- calls.should.eql(['one', 'two']);782- });783- },784- 785- 'test route callback error recovery': function(){786- var app = express.createServer();787-788- app.get('/user/:id', function(req, res, next){789- next(new Error('fail'));790- });791-792- app.get('/user/*', function(err, req, res, next){793- req.error = err;794- next();795- });796-797- app.get('/user/*', function(req, res, next){798- res.send('recovered from error: ' + req.error.message);799- });800-801- assert.response(app,802- { url: '/user/12' },803- { body: 'recovered from error: fail' });804- },805- 806- 'test multiple param callbacks': function(){807- var app = express.createServer();808-809- app.param('user', function(req, res, next, id){810- req.user = { id: id };811- next();812- });813-814- app.param('forum_id', function(req, res, next, id){815- req.forum = { id: id };816- next();817- });818-819- app.param('thread_id', function(req, res, next, id){820- req.thread = { id: id };821- next();822- });823-824- function array(req, res, next) {825- req.arr = [req.user.id, req.forum.id, req.thread.id];826- next();827- }828-829- app.get('/:user/:forum_id/:thread_id', array, function(req, res){830- res.send(req.arr);831- });832-833- assert.response(app,834- { url: '/1/2/3' },835- { body: '["1","2","3"]' });836- }837-};deleted:test/utils.test.js-18 removed
1-2-/**3- * Module dependencies.4- */5-6-var utils = require('../lib/utils')7- , should = require('should');8-9-module.exports = {10- 'test .miniMarkdown()': function(){11- utils.miniMarkdown('_foo_').should.equal('<em>foo</em>');12- utils.miniMarkdown('*foo*').should.equal('<em>foo</em>');13- utils.miniMarkdown('**foo**').should.equal('<strong>foo</strong>');14- utils.miniMarkdown('__foo__').should.equal('<strong>foo</strong>');15- utils.miniMarkdown('_foo__').should.equal('<em>foo</em>_'); 16- utils.miniMarkdown('[User Login](/login)').should.equal('<a href="/login">User Login</a>');17- }18-};deleted:test/view.test.js-1056 removed
1-2-/**3- * Module dependencies.4- */5-6-var express = require('express')7- , connect = require('connect')8- , assert = require('assert')9- , should = require('should')10- , View = require('../lib/view')11- , partial = require('../lib/view/partial')12-13-/**14- * Create a test server with views set to ./fixtures.15- */16-17-var create = function(){18- var app = express.createServer.apply(express, arguments);19- app.set('views', __dirname + '/fixtures');20- return app;21-};22-23-module.exports = {24- 'test View#path': function(){25- var view = new View('forum/thread.ejs', { root: '/www/mysite/views' });26- view.path.should.equal('/www/mysite/views/forum/thread.ejs');27-28- var view = new View('/www/mysite/views/path.ejs');29- view.path.should.equal('/www/mysite/views/path.ejs');30-31- var view = new View('user', { parentView: view });32- view.path.should.equal('/www/mysite/views/user.ejs');33-34- var view = new View('user/list', { parentView: view });35- view.path.should.equal('/www/mysite/views/user/list.ejs');36-37- var view = new View('user.jade', { parentView: new View('foo', { root: '/bar' }) });38- view.path.should.equal('/bar/user.jade');39-40- var view = new View('/foo.bar.baz/user.ejs');41- view.path.should.equal('/foo.bar.baz/user.ejs');42- 43- var view = new View('/foo.bar.baz/user', { parentView: view });44- view.path.should.equal('/foo.bar.baz/user.ejs');45-46- var view = new View('user', { parentView: view });47- view.path.should.equal('/foo.bar.baz/user.ejs');48- },49- 50- 'test View#engine': function(){51- var view = new View('/absolute/path.ejs');52- view.engine.should.equal('ejs');53-54- var view = new View('user', { parentView: view });55- view.engine.should.equal('ejs');56-57- var view = new View('/user', { defaultEngine: 'jade' });58- view.engine.should.equal('jade');59-60- var view = new View('/foo.bar/user.ejs');61- view.engine.should.equal('ejs');62- },63- 64- 'test View#extension': function(){65- var view = new View('/absolute/path.ejs');66- view.extension.should.equal('.ejs');67-68- var view = new View('user', { parentView: view });69- view.extension.should.equal('.ejs');70-71- var view = new View('/user', { defaultEngine: 'jade' });72- view.extension.should.equal('.jade');73-74- var view = new View('/foo.bar/user.ejs');75- view.extension.should.equal('.ejs');76- },77- 78- 'test View#dirname': function(){79- var view = new View('/absolute/path.ejs');80- view.dirname.should.equal('/absolute');81-82- var view = new View('user', { parentView: view });83- view.dirname.should.equal('/absolute');84- },85- 86- 'test View#contents': function(){87- var view = new View(__dirname + '/fixtures/hello.jade');88- view.contents.should.equal('p :(');89- },90- 91- 'test View#templateEngine': function(){92- var view = new View(__dirname + '/fixtures/hello.jade');93- view.templateEngine.should.equal(require('jade'));94- },95- 96- 'test partial.resolveObjectName()': function(){97- var resolve = partial.resolveObjectName;98- resolve('/path/to/user.ejs').should.equal('user');99- resolve('/path/to/user-post.ejs').should.equal('userPost');100- resolve('/path/to/user post.ejs').should.equal('userPost');101- resolve('forum thread post.ejs').should.equal('forumThreadPost');102- resolve('forum thread post.ejs').should.equal('forumThreadPost');103- },104- 105- 'test #render()': function(){106- var app = create();107- app.set('view engine', 'jade');108- app.register('haml', require('hamljs'));109- 110- app.get('/', function(req, res){111- res.render('index.jade', { layout: false });112- });113- 114- app.get('/jade', function(req, res){115- res.render('index', { layout: false });116- });117- 118- app.get('/haml', function(req, res){119- res.render('hello.haml', { layout: false });120- });121- 122- app.get('/callback/layout/no-options', function(req, res){123- res.render('hello.jade', function(err, str){124- assert.ok(!err);125- res.send(str.replace(':(', ':)'));126- });127- });128- 129- app.get('/callback/layout', function(req, res){130- res.render('hello.jade', {}, function(err, str){131- assert.ok(!err);132- res.send(str.replace(':(', ':)'));133- });134- });135- 136- app.get('/callback', function(req, res){137- res.render('hello.haml', { layout: false }, function(err, str){138- assert.ok(!err);139- res.send(str.replace('Hello World', ':)'));140- });141- });142- 143- app.get('/invalid', function(req, res){144- res.render('invalid.jade', { layout: false });145- });146- 147- app.get('/invalid-async', function(req, res){148- process.nextTick(function(){149- res.render('invalid.jade', { layout: false });150- });151- });152- 153- app.get('/error', function(req, res){154- res.render('invalid.jade', { layout: false }, function(err){155- res.send(err.arguments[0]);156- });157- });158- 159- app.get('/absolute', function(req, res){160- res.render(__dirname + '/fixtures/index.jade', { layout: false });161- });162- 163- app.get('/ferret', function(req, res){164- res.render('ferret', { layout: false, ferret: { name: 'Tobi' }});165- });166- 167- app.get('/status', function(req, res){168- res.render('hello.jade', { status: 500 });169- });170- 171- assert.response(app,172- { url: '/status' },173- { status: 500 });174- assert.response(app,175- { url: '/ferret' },176- { body: '<li class="ferret">Tobi</li>' });177- assert.response(app,178- { url: '/' },179- { body: '<p>Welcome</p>', headers: { 'Content-Type': 'text/html; charset=utf-8' }});180- assert.response(app,181- { url: '/jade' },182- { body: '<p>Welcome</p>' });183- assert.response(app,184- { url: '/absolute' },185- { body: '<p>Welcome</p>' });186- assert.response(app,187- { url: '/haml' },188- { body: '\n<p>Hello World</p>' });189- assert.response(app,190- { url: '/callback' },191- { body: '\n<p>:)</p>' });192- assert.response(app,193- { url: '/callback/layout' },194- { body: '<html><body><p>:)</p></body></html>' });195- assert.response(app,196- { url: '/callback/layout/no-options' },197- { body: '<html><body><p>:)</p></body></html>' });198- assert.response(app,199- { url: '/error' },200- { body: 'doesNotExist' });201- assert.response(app,202- { url: '/invalid' },203- function(res){204- assert.ok(res.body.indexOf('ReferenceError') >= 0);205- assert.ok(res.body.indexOf('doesNotExist') >= 0);206- });207- assert.response(app,208- { url: '/invalid-async' },209- function(res){210- assert.ok(res.body.indexOf('ReferenceError') >= 0);211- assert.ok(res.body.indexOf('doesNotExist') >= 0);212- });213- },214- 215- 'test #render() layout': function(){216- var app = create();217- app.set('view engine', 'jade');218- 219- app.get('/', function(req, res){220- res.render('index.jade');221- });222- app.get('/jade', function(req, res){223- res.render('index');224- });225- 226- assert.response(app,227- { url: '/' },228- { body: '<html><body><p>Welcome</p></body></html>' });229- },230- 231- 'test #render() specific layout': function(beforeExit){232- var app = create()233- , called;234- 235- app.get('/', function(req, res){236- res.render('index.jade', { layout: 'cool-layout.jade' }, function(err, html){237- called = true;238- res.send(html);239- });240- });241- app.get('/no-ext', function(req, res){242- res.render('index.jade', { layout: 'cool-layout' });243- });244- app.get('/relative', function(req, res){245- res.render('index.jade', { layout: 'layouts/foo.jade' });246- });247- app.get('/absolute', function(req, res){248- res.render('index.jade', { layout: __dirname + '/fixtures/layouts/foo.jade' });249- });250- app.get('/nope', function(req, res){251- res.render('index.jade', { layout: 'nope.jade' });252- });253- 254- assert.response(app,255- { url: '/' },256- { body: '<cool><p>Welcome</p></cool>' });257- assert.response(app,258- { url: '/no-ext' },259- { body: '<cool><p>Welcome</p></cool>' });260- assert.response(app,261- { url: '/relative' },262- { body: '<foo></foo>' });263- assert.response(app,264- { url: '/absolute' },265- { body: '<foo></foo>' });266- assert.response(app,267- { url: '/nope' },268- function(res){269- assert.ok(~res.body.indexOf('Error: failed to locate view'));270- assert.ok(~res.body.indexOf('nope'));271- });272- 273- beforeExit(function(){274- assert.ok(called, 'Layout callback never called'); 275- });276- },277- 278- 'test #render() specific layout "view engine"': function(){279- var app = create();280- app.set('view engine', 'jade');281- 282- app.get('/', function(req, res){283- res.render('index', { layout: 'cool-layout' });284- });285- 286- assert.response(app,287- { url: '/' },288- { body: '<cool><p>Welcome</p></cool>' });289- },290- 291- 'test #render() view layout control': function(){292- var app = create();293- app.set('view engine', 'jade');294- 295- app.get('/', function(req, res){296- res.render('layout-switch');297- });298- 299- assert.response(app,300- { url: '/' },301- { body: '<div id="alternate"><h1>My Page</h1></div>' });302- },303- 304- 'test #render() "view engine" with periods in dirname': function(){305- var app = create();306- app.set('view engine', 'jade');307- 308- app.get('/', function(req, res){309- res.render('index', { layout: __dirname + '/fixtures/user/../cool-layout' });310- });311- 312- assert.response(app,313- { url: '/' },314- { body: '<cool><p>Welcome</p></cool>' });315- },316- 317- 'test #partial() collection object': function(){318- var app = create();319-320- app.get('/', function(req, res){321- var items = { 2: 'foo', bar: 'bar' };322- res.partial('object-item.jade', { as: 'item', collection: items });323- });324-325- assert.response(app,326- { url: '/' },327- { body: '<li>2: foo</li><li>bar: bar</li>' });328- },329- 330- 'test #partial()': function(){331- var app = create();332- 333- app.set('view engine', 'jade');334- 335- // Auto-assigned local w/ collection option336- app.get('/', function(req, res){337- res.render('items.jade', { items: ['one', 'two'] });338- });339- 340- assert.response(app,341- { url: '/' },342- { body: '<html><body><ul><li>one</li><li>two</li></ul></body></html>' });343- 344- // Auto-assigned local w/ collection array 345- var movies = [346- { title: 'Nightmare Before Christmas', director: 'Tim Burton' },347- { title: 'Avatar', director: 'James Cameron' }348- ];349- app.get('/movies', function(req, res){350- res.render('movies.jade', { movies: movies });351- });352- 353- var html = [354- '<html>',355- '<body>',356- '<ul>',357- '<li>',358- '<div class="title">Nightmare Before Christmas</div>',359- '<div class="director">Tim Burton</div>',360- '</li>',361- '<li>',362- '<div class="title">Avatar</div>',363- '<div class="director">James Cameron</div>',364- '</li>',365- '</ul>',366- '</body>',367- '</html>'368- ].join('');369- 370- assert.response(app,371- { url: '/movies' },372- { body: html });373- 374- // as: str collection option375- app.get('/user', function(req, res){376- res.partial('user', {377- as: 'person',378- collection: [{ name: 'tj' }]379- });380- });381- 382- assert.response(app,383- { url: '/user' },384- { body: '<p>tj</p>' });385- 386- // as: with object collection387- app.get('/user/object', function(req, res){388- res.partial('user.jade', {389- as: 'person',390- collection: { 0: { name: 'tj' }, length: 1 }391- });392- });393- 394- assert.response(app,395- { url: '/user' },396- { body: '<p>tj</p>' });397-398- // as: global collection option399- app.get('/videos', function(req, res){400- res.partial('video.jade', {401- as: global,402- collection: movies403- });404- });405- 406- assert.response(app,407- { url: '/videos' },408- { body: '<p>Tim Burton</p><p>James Cameron</p>' });409- 410- // Magic variables411- app.get('/magic', function(req, res){412- res.partial('magic.jade', {413- as: 'word',414- collection: ['one', 'two', 'three']415- });416- });417- 418- assert.response(app,419- { url: '/magic' },420- { body: '<li class="first">one</li><li class="word-1">two</li><li class="last">three</li>' });421- 422- // Non-collection support423- app.get('/movie', function(req, res){424- res.partial('movie.jade', {425- object: movies[0]426- });427- });428- 429- assert.response(app,430- { url: '/movie' },431- { body: '<li><div class="title">Nightmare Before Christmas</div><div class="director">Tim Burton</div></li>' });432-433- app.get('/video-global', function(req, res){434- res.partial('video.jade', {435- object: movies[0],436- as: global437- }); 438- });439- 440- // Non-collection as: global441- assert.response(app,442- { url: '/video-global' },443- { body: '<p>Tim Burton</p>' });444- 445- // No options446- app.get('/nothing', function(req, res){447- res.partial('hello.ejs');448- });449- 450- assert.response(app,451- { url: '/nothing' },452- { body: 'Hello' });453- 454- // Path segments + "as"455- app.get('/role/as', function(req, res){456- res.partial('user/role.ejs', { as: 'role', collection: ['admin', 'member'] });457- });458- 459- assert.response(app,460- { url: '/role/as' },461- { body: '<li>Role: admin</li><li>Role: member</li>' });462- 463- // Deduce name from last segment464- app.get('/role', function(req, res){465- res.partial('user/role.ejs', ['admin', 'member']);466- });467- 468- assert.response(app,469- { url: '/role' },470- { body: '<li>Role: admin</li><li>Role: member</li>' });471- 472- // Non-basic object support473- function Movie(title, director){474- this.title = title;475- this.director = director;476- }477- 478- app.get('/movie/object', function(req, res){479- res.partial('movie', new Movie('The TJ', 'tj'));480- });481- 482- assert.response(app,483- { url: '/movie/object' },484- { body: '<li><div class="title">The TJ</div><div class="director">tj</div></li>' });485-486- // Locals487- app.get('/stats', function(req, res){488- res.partial('stats', {489- hits: 12490- , misses: 1491- });492- });493-494- assert.response(app,495- { url: '/stats' },496- { body: '<p>Hits 12</p><p>Misses 1</p>' });497-498- // Locals499- app.get('/stats/locals', function(req, res){500- res.partial('stats', {501- locals: {502- hits: 12503- , misses: 1 504- }505- });506- });507-508- assert.response(app,509- { url: '/stats/locals' },510- { body: '<p>Hits 12</p><p>Misses 1</p>' });511-512- // Collection + locals513- app.get('/items', function(req, res){514- res.partial('item-title', {515- collection: ['foo', 'bar']516- , title: 'test'517- , as: 'item'518- });519- });520- 521- assert.response(app,522- { url: '/items' },523- { body: '<li>test foo</li><li>test bar</li>' });524- 525- app.get('/stats/callback', function(req, res){526- res.partial('stats', { hits: 12, misses: 1 }, function(err, html){527- res.send('got: ' + html);528- });529- });530-531- assert.response(app,532- { url: '/stats/callback' },533- { body: 'got: <p>Hits 12</p><p>Misses 1</p>' });534-535- app.get('/stats/callback/2', function(req, res){536- res.locals.hits = 12;537- res.locals({ misses: 1 });538- res.partial('stats', function(err, html){539- res.send('got: ' + html);540- });541- });542-543- assert.response(app,544- { url: '/stats/callback/2' },545- { body: 'got: <p>Hits 12</p><p>Misses 1</p>' });546-547- // root lookup548-549- app.get('/root', function(req, res){550- res.partial('nested/partial');551- });552-553- assert.response(app,554- { url: '/root' },555- { body: '<p>Hits 15</p><p>Misses 1</p>' });556-557- // root _* lookup558-559- app.get('/root/underscore', function(req, res){560- res.partial('nested/partial2');561- });562-563- assert.response(app,564- { url: '/root/underscore' },565- { body: '<p>Testing</p>' });566-567- // error in template568-569- app.get('/error', function(req, res){570- process.nextTick(function(){571- res.partial('error');572- });573- });574-575- assert.response(app,576- { url: '/error' },577- { status: 500 });578-579- app.get('/underscore', function(req, res, next){580- res.partial('foobar');581- });582-583- assert.response(app,584- { url: '/underscore' },585- { body: '<p>two</p>' });586- },587- 588- 'test #partial() relative lookup with "view engine"': function(){589- var app = create();590- app.set('view engine', 'jade');591-592- app.get('/', function(req, res, next){593- res.render('forum/thread', { layout: false });594- });595-596- app.get('/2', function(req, res, next){597- res.render('forum/../forum/thread', { layout: false });598- });599-600- assert.response(app,601- { url: '/2' },602- { body: '<h1>Forum Thread</h1><p>:(</p>\n<p>Hello World</p>' });603-604- assert.response(app,605- { url: '/' },606- { body: '<h1>Forum Thread</h1><p>:(</p>\n<p>Hello World</p>' });607- },608-609- 'test #partial() relative lookup without "view engine"': function(){610- var app = create();611-612- app.get('/', function(req, res, next){613- res.render('forum/thread.jade', { layout: false });614- });615-616- app.get('/2', function(req, res, next){617- res.render('forum/../forum/thread.jade', { layout: false });618- });619-620- assert.response(app,621- { url: '/2' },622- { body: '<h1>Forum Thread</h1><p>:(</p>\n<p>Hello World</p>' });623-624- assert.response(app,625- { url: '/' },626- { body: '<h1>Forum Thread</h1><p>:(</p>\n<p>Hello World</p>' });627- },628- 629- 'test #partial() relative lookup': function(){630- var app = create();631-632- app.get('/', function(req, res, next){633- res.partial('forum/thread.jade');634- });635-636- app.get('/2', function(req, res, next){637- res.partial('forum/../forum/thread.jade');638- });639-640- assert.response(app,641- { url: '/2' },642- { body: '<h1>Forum Thread</h1><p>:(</p>\n<p>Hello World</p>' });643-644- assert.response(app,645- { url: '/' },646- { body: '<h1>Forum Thread</h1><p>:(</p>\n<p>Hello World</p>' });647- },648-649- 'test #partial() with several calls': function(){650- var app = create();651- 652- app.get('/', function(req, res, next){653- res.render('list.jade', { layout: false });654- });655- 656- assert.response(app,657- { url: '/' },658- { body: '<ul><li>foo</li><li>empty</li></ul>' });659- },660- 661- 'test #partial() with several calls using locals': function(){662- var app = create();663- 664- app.get('/', function(req, res, next){665- res.render('list2.jade', { layout: false });666- });667- 668- assert.response(app,669- { url: '/' },670- { body: '<ul><li>foo</li><li>bar</li><li>empty</li></ul>' });671- },672- 673- 'test #partial() locals': function(){674- var app = create();675- 676- app.set('view engine', 'jade');677- 678- app.get('/', function(req, res, next){679- res.partial('pet-count', {680- locals: {681- pets: {682- length: 5683- }684- }685- });686- });687- 688- assert.response(app,689- { url: '/' },690- { body: 'We have 5 cool pets\n' });691- },692- 693- 'test #partial() locals precedence': function(){694- var app = create();695- 696- app.get('/', function(req, res, next){697- res.render('greetings.jade', {698- name: 'TJ'699- , locals: { otherName: 'Overridden' }700- });701- });702- 703- assert.response(app,704- { url: '/' },705- { body: '<html><body><h1>TJ</h1><p>Welcome Overridden</p></body></html>' });706- },707- 708- 'test #partial() index': function(){709- var app = create();710- 711- app.set('view engine', 'jade');712-713- function Ferret(name){ this.name = name; };714-715- app.get('/ferret', function(req, res){716- res.partial('ferret', new Ferret('Tobi'));717- });718- 719- app.get('/ferret/basic', function(req, res){720- res.partial('ferret', { ferret: { name: 'Tobi' }});721- });722-723- assert.response(app,724- { url: '/ferret/basic' },725- { body: '<li class="ferret">Tobi</li>' });726-727- assert.response(app,728- { url: '/ferret' },729- { body: '<li class="ferret">Tobi</li>' });730- },731- 732- 'test #partial() relative index': function(){733- var app = create();734-735- app.set('view engine', 'jade');736-737- function Ferret(name) { this.name = name; }738- app.get('/ferret', function(req, res){739- var tobi = new Ferret('Tobi')740- , loki = new Ferret('Loki');741- res.partial('ferret/list', { object: [tobi, loki] });742- });743- 744- assert.response(app,745- { url: '/ferret' },746- { body: '<ul id="ferrets"><li class="ferret">Tobi</li><li class="ferret">Loki</li></ul>' });747- },748- 749- 'test #partial() object': function(){750- var app = create();751- 752- app.get('/', function(req, res, next){753- function Movie(title, director) {754- this.title = title;755- this.director = director;756- }757- res.partial('movie.jade', new Movie('Foobar', 'Tim Burton'));758- });759- 760- assert.response(app,761- { url: '/' },762- { body: '<li><div class="title">Foobar</div><div class="director">Tim Burton</div></li>' });763- },764- 765- 'test #partial() locals with collection': function(){766- var app = create();767- 768- app.get('/', function(req, res, next){769- res.render('pet-land.jade', {770- pets: ['Ewald']771- });772- });773- 774- assert.response(app,775- { url: '/' },776- { body: '<html><body><div><li>Ewald is the coolest of Animal land</li></div></body></html>' });777- },778- 779- 'test #partial() inheriting initial locals': function(){780- var app = create();781- 782- app.get('/pets', function(req, res, next){783- res.render('pets.jade', {784- site: 'My Cool Pets'785- , pets: ['Tobi', 'Jane', 'Bandit']786- });787- });788- 789- var html = [790- '<html>',791- '<body>',792- '<h1>My Cool Pets</h1>',793- '<p>We have 3 cool pets\n</p>',794- '<ul>',795- '<li>Tobi is the coolest of My Cool Pets</li>',796- '<li>Jane</li>',797- '<li>Bandit</li>',798- '</ul>',799- '</body>',800- '</html>'801- ].join('');802- 803- assert.response(app,804- { url: '/pets' },805- { body: html });806- },807- 808- 'test #partial() with array-like collection': function(){809- var app = create();810- 811- var movies = {812- 0: { title: 'Nightmare Before Christmas', director: 'Tim Burton' },813- 1: { title: 'Avatar', director: 'James Cameron' },814- length: 2815- };816- app.get('/movies', function(req, res){817- res.render('movies.jade', { movies: movies });818- });819- 820- var html = [821- '<html>',822- '<body>',823- '<ul>',824- '<li>',825- '<div class="title">Nightmare Before Christmas</div>',826- '<div class="director">Tim Burton</div>',827- '</li>',828- '<li>',829- '<div class="title">Avatar</div>',830- '<div class="director">James Cameron</div>',831- '</li>',832- '</ul>',833- '</body>',834- '</html>'835- ].join('');836- 837- assert.response(app,838- { url: '/movies' },839- { body: html });840- },841- 842- 'test "partials" setting': function(){843- var app = create();844- app.set('partials', __dirname + '/fixtures/sub-templates');845- 846- app.get('/', function(req, res){847- res.render('items.jade', {848- layout: false,849- items: ['foo', 'bar']850- });851- });852- 853- assert.response(app,854- { url: '/' },855- { body: '<ul><li>foo</li><li>bar</li></ul>' });856- },857- 858- 'test .register()': function(){859- var app = create();860- 861- app.register('.bar', require('jade'));862- 863- app.get('/', function(req, res, next){864- res.render('foo.bar', { layout: false });865- });866- 867- assert.response(app,868- { url: '/' },869- { body: '<p>This is actually jade :)</p>' });870- },871-872- 'test app.locals': function(){873- var app = create();874-875- app.locals.title = 'Wahoo';876- app.locals({ open: '<?', close: '?>' });877-878- app.get('/video', function(req, res, next){879- res.render('video.ejs', { layout: false });880- });881- 882- assert.response(app,883- { url: '/video' },884- { body: '<h1>Wahoo</h1>' });885- },886- 887- 'test res.locals': function(){888- var app = create();889- 890- app.get('/video', function(req, res, next){891- res.locals.open = '<?';892- res.locals.close = '?>';893- res.locals.title = 'Wahoo';894- res.render('video.ejs', { layout: false });895- });896- 897- assert.response(app,898- { url: '/video' },899- { body: '<h1>Wahoo</h1>' });900- },901- 902- 'test app.locals / res.locals precedence': function(){903- var app = create();904-905- app.locals.title = 'App Level';906-907- app.get('/render', function(req, res, next){908- res.locals.open = '<?';909- res.locals.close = '?>';910- res.locals.title = 'Response Level';911- res.render('video.ejs', { layout: false, title: 'Render Level' });912- });913-914- var app2 = create();915-916- app2.locals.title = 'App Level';917-918- app2.get('/response', function(req, res, next){919- res.locals.open = '<?';920- res.locals.close = '?>';921- res.locals.title = 'Response Level';922- res.render('video.ejs', { layout: false });923- });924-925- var app3 = create();926-927- app3.locals.title = 'App Level';928-929- app3.get('/app', function(req, res, next){930- res.locals.open = '<?';931- res.locals.close = '?>';932- res.render('video.ejs', { layout: false });933- });934-935- assert.response(app3,936- { url: '/app' },937- { body: '<h1>App Level</h1>' });938-939- assert.response(app2,940- { url: '/response' },941- { body: '<h1>Response Level</h1>' });942-943- assert.response(app,944- { url: '/render' },945- { body: '<h1>Render Level</h1>' });946- },947-948- 'test res.locals partials': function(){949- var app = create();950-951- app.locals.site = 'My Cool Pets';952- 953- app.get('/pets', function(req, res, next){954- res.locals.pets = ['Tobi'];955- next();956- });957- 958- app.get('/pets', function(req, res, next){959- if (pets = res.locals.pets) {960- res.locals.pets.push('Jane', 'Bandit');961- }962- next();963- });964- 965- app.get('/pets', function(req, res, next){966- res.render('pets.jade');967- });968- 969- var html = [970- '<html>',971- '<body>',972- '<h1>My Cool Pets</h1>',973- '<p>We have 3 cool pets\n</p>',974- '<ul>',975- '<li>Tobi is the coolest of My Cool Pets</li>',976- '<li>Jane</li>',977- '<li>Bandit</li>',978- '</ul>',979- '</body>',980- '</html>'981- ].join('');982- 983- assert.response(app,984- { url: '/pets' },985- { body: html });986- },987- 988- 'test .charset with res.render()': function(){989- var app = create();990- 991- app.get('/', function(req, res){992- res.charset = 'ISO-8859-1';993- res.render('hello.jade');994- });995- 996- assert.response(app,997- { url: '/' },998- { headers: { 'Content-Type': 'text/html; charset=ISO-8859-1' }});999- },1000- 1001- 'test charset res.render() option': function(){1002- var app = create();1003- 1004- app.get('/', function(req, res){1005- res.render('hello.jade', { charset: 'ISO-8859-1' });1006- });1007- 1008- assert.response(app,1009- { url: '/' },1010- { headers: { 'Content-Type': 'text/html; charset=ISO-8859-1' }});1011- },1012- 1013- 'test "charset" option': function(){1014- var app = create();1015-1016- app.set('charset', 'ISO-8859-1');1017-1018- app.get('/option', function(req, res, next){1019- res.render('hello.jade');1020- });1021-1022- app.get('/local', function(req, res){1023- res.locals.charset = 'ISO-8859-1';1024- res.render('hello.jade');1025- });1026-1027- app.get('/render', function(req, res){1028- res.render('hello.jade', { charset: 'ISO-8859-1' });1029- });1030-1031- assert.response(app,1032- { url: '/option' },1033- { headers: { 'Content-Type': 'text/html; charset=ISO-8859-1' }});1034-1035- assert.response(app,1036- { url: '/render' },1037- { headers: { 'Content-Type': 'text/html; charset=ISO-8859-1' }});1038- 1039- assert.response(app,1040- { url: '/local' },1041- { headers: { 'Content-Type': 'text/html; charset=ISO-8859-1' }});1042- },1043- 1044- 'test charset override': function(){1045- var app = create();1046- app.locals.charset = 'ISO-8859-1';1047- 1048- app.get('/', function(req, res){1049- res.render('hello.jade', { charset: 'utf8' });1050- });1051- 1052- assert.response(app,1053- { url: '/' },1054- { headers: { 'Content-Type': 'text/html; charset=utf8' }});1055- }1056-};