view.test.js
This file
Path
test/view.test.js
414 lines · 12.6 KiB · JavaScript
Last changed by
Merge branch 'fix-layouts'Tj Holowaychukbefore adoptiondadea8c
History of this fileTake it
The walk stopped after 200 commits: lines older than 893aa80 point at it.
Added link to user account for github exampleTj Holowaychukbefore adoption893aa80
lines 1–9why, one step back12/**3 * Module dependencies.4 */56var express = require('express'),7 connect = require('connect'),8 view = require('express/view');9Added helper method create() to view tests to get a server with the correct views directory Make the default scope for rendering the response Added tests for default scope and custom scopeGuillermo Rauchbefore adoptionbb6164e
line 10why, one step back10var create = function(){Style fixesTj Holowaychukbefore adoption0eeef2d
lines 11–13why, one step back11 var app = express.createServer.apply(express, arguments);12 app.set('views', __dirname + '/fixtures');13 return app;Added helper method create() to view tests to get a server with the correct views directory Make the default scope for rendering the response Added tests for default scope and custom scopeGuillermo Rauchbefore adoptionbb6164e
lines 14–15why, one step back14};15Added link to user account for github exampleTj Holowaychukbefore adoption893aa80
lines 16–17why, one step back16module.exports = {17 'test #render()': function(assert){Merge branch 'fix-layouts'Tj Holowaychukbefore adoptiondadea8c
line 18why, one step back18 var app = create();Added link to user account for github exampleTj Holowaychukbefore adoption893aa80
lines 19–38why, one step back19 app.set('view engine', 'jade');2021 app.get('/', function(req, res){22 res.render('index.jade', { layout: false });23 });24 app.get('/jade', function(req, res){25 res.render('index', { layout: false });26 });27 app.get('/haml', function(req, res){28 res.render('hello.haml', { layout: false });29 });30 app.get('/callback', function(req, res){31 res.render('hello.haml', { layout: false }, function(err, str){32 assert.ok(!err);33 res.send(str.replace('Hello World', ':)'));34 });35 });36 app.get('/invalid', function(req, res){37 res.render('invalid.jade', { layout: false });38 });Merge branch 'render-next'Tj Holowaychukbefore adoption699e6e1
lines 39–43why, one step back39 app.get('/invalid-async', function(req, res){40 process.nextTick(function(){41 res.render('invalid.jade', { layout: false });42 });43 });Added link to user account for github exampleTj Holowaychukbefore adoption893aa80
lines 44–48why, one step back44 app.get('/error', function(req, res){45 res.render('invalid.jade', { layout: false }, function(err){46 res.send(err.arguments[0]);47 });48 });Added test for absolute view pathTj Holowaychukbefore adoptione6f4b04
lines 49–51why, one step back49 app.get('/absolute', function(req, res){50 res.render(__dirname + '/fixtures/index.jade', { layout: false });51 });Added link to user account for github exampleTj Holowaychukbefore adoption893aa80
lines 52–54why, one step back5253 assert.response(app,54 { url: '/' },res.render() using res.send()Tj Holowaychukbefore adoptioncba985b
line 55why, one step back55 { body: '<p>Welcome</p>', headers: { 'Content-Type': 'text/html; charset=utf-8' }});Added link to user account for github exampleTj Holowaychukbefore adoption893aa80
lines 56–57why, one step back56 assert.response(app,57 { url: '/jade' },Added test for absolute view pathTj Holowaychukbefore adoptione6f4b04
lines 58–60why, one step back58 { body: '<p>Welcome</p>' });59 assert.response(app,60 { url: '/absolute' },Added link to user account for github exampleTj Holowaychukbefore adoption893aa80
lines 61–76why, one step back61 { body: '<p>Welcome</p>' });62 assert.response(app,63 { url: '/haml' },64 { body: '\n<p>Hello World</p>' });65 assert.response(app,66 { url: '/callback' },67 { body: '\n<p>:)</p>' });68 assert.response(app,69 { url: '/error' },70 { body: 'doesNotExist' });71 assert.response(app,72 { url: '/invalid' },73 function(res){74 assert.ok(res.body.indexOf('ReferenceError') >= 0);75 assert.ok(res.body.indexOf('doesNotExist') >= 0);76 });Merge branch 'render-next'Tj Holowaychukbefore adoption699e6e1
lines 77–83why, one step back77 assert.response(app,78 { url: '/invalid-async' },79 function(res){80 assert.ok(res.body.indexOf('ReferenceError') >= 0);81 assert.ok(res.body.indexOf('doesNotExist') >= 0);82 });83Added link to user account for github exampleTj Holowaychukbefore adoption893aa80
lines 84–86why, one step back84 },85 86 'test #render() layout': function(assert){Added helper method create() to view tests to get a server with the correct views directory Make the default scope for rendering the response Added tests for default scope and custom scopeGuillermo Rauchbefore adoptionbb6164e
line 87why, one step back87 var app = create();Added link to user account for github exampleTj Holowaychukbefore adoption893aa80
lines 88–101why, one step back88 app.set('view engine', 'jade');8990 app.get('/', function(req, res){91 res.render('index.jade');92 });93 app.get('/jade', function(req, res){94 res.render('index');95 });9697 assert.response(app,98 { url: '/' },99 { body: '<html><body><p>Welcome</p></body></html>' });100 },101 Fixed res.render() callback when a layout is used [thanks guillermo]Tj Holowaychukbefore adoption5e1a271
lines 102–104why, one step back102 'test #render() specific layout': function(assert, beforeExit){103 var app = create(),104 called;Added link to user account for github exampleTj Holowaychukbefore adoption893aa80
lines 105–106why, one step back105106 app.get('/', function(req, res){Fixed res.render() callback when a layout is used [thanks guillermo]Tj Holowaychukbefore adoption5e1a271
lines 107–110why, one step back107 res.render('index.jade', { layout: 'cool-layout.jade' }, function(err, html){108 called = true;109 res.send(html);110 });Added link to user account for github exampleTj Holowaychukbefore adoption893aa80
line 111why, one step back111 });Added support for passing of layout name without extensionTj Holowaychukbefore adoptiona461815
lines 112–114why, one step back112 app.get('/no-ext', function(req, res){113 res.render('index.jade', { layout: 'cool-layout' });114 });s/foo/relative/Tj Holowaychukbefore adoptione554378
line 115why, one step back115 app.get('/relative', function(req, res){Added test for layouts in a directoryTj Holowaychukbefore adoptionb463bd7
lines 116–117why, one step back116 res.render('index.jade', { layout: 'layouts/foo.jade' });117 });Added failing test for absolute layoutsTj Holowaychukbefore adoptiond651ffa
lines 118–120why, one step back118 app.get('/absolute', function(req, res){119 res.render('index.jade', { layout: __dirname + '/fixtures/layouts/foo.jade' });120 });Merge branch 'fix-layouts'Tj Holowaychukbefore adoptiondadea8c
lines 121–123why, one step back121 app.get('/nope', function(req, res){122 res.render('index.jade', { layout: 'nope.jade' });123 });Added link to user account for github exampleTj Holowaychukbefore adoption893aa80
lines 124–126why, one step back124125 assert.response(app,126 { url: '/' },Added support for passing of layout name without extensionTj Holowaychukbefore adoptiona461815
lines 127–129why, one step back127 { body: '<cool><p>Welcome</p></cool>' });128 assert.response(app,129 { url: '/no-ext' },Added link to user account for github exampleTj Holowaychukbefore adoption893aa80
line 130why, one step back130 { body: '<cool><p>Welcome</p></cool>' });Added test for layouts in a directoryTj Holowaychukbefore adoptionb463bd7
line 131why, one step back131 assert.response(app,s/foo/relative/Tj Holowaychukbefore adoptione554378
line 132why, one step back132 { url: '/relative' },Added failing test for absolute layoutsTj Holowaychukbefore adoptiond651ffa
lines 133–135why, one step back133 { body: '<foo></foo>' });134 assert.response(app,135 { url: '/absolute' },Added test for layouts in a directoryTj Holowaychukbefore adoptionb463bd7
line 136why, one step back136 { body: '<foo></foo>' });Merge branch 'fix-layouts'Tj Holowaychukbefore adoptiondadea8c
lines 137–142why, one step back137 assert.response(app,138 { url: '/nope' },139 function(res){140 assert.ok(res.body.indexOf('Error: ENOENT') >= 0);141 assert.ok(res.body.indexOf('nope.jade') >= 0);142 });Fixed res.render() callback when a layout is used [thanks guillermo]Tj Holowaychukbefore adoption5e1a271
lines 143–146why, one step back143144 beforeExit(function(){145 assert.ok(called, 'Layout callback never called'); 146 });Added link to user account for github exampleTj Holowaychukbefore adoption893aa80
lines 147–148why, one step back147 },148 Added test for specific layouts with "view engine" setTj Holowaychukbefore adoptioneedf54b
line 149why, one step back149 'test #render() specific layout "view engine"': function(assert){Added helper method create() to view tests to get a server with the correct views directory Make the default scope for rendering the response Added tests for default scope and custom scopeGuillermo Rauchbefore adoptionbb6164e
line 150why, one step back150 var app = create();Added test for specific layouts with "view engine" setTj Holowaychukbefore adoptioneedf54b
lines 151–161why, one step back151 app.set('view engine', 'jade');152 153 app.get('/', function(req, res){154 res.render('index', { layout: 'cool-layout' });155 });156 157 assert.response(app,158 { url: '/' },159 { body: '<cool><p>Welcome</p></cool>' });160 },161 Added helper method create() to view tests to get a server with the correct views directory Make the default scope for rendering the response Added tests for default scope and custom scopeGuillermo Rauchbefore adoptionbb6164e
lines 162–192why, one step back162 'test #render() scope': function(assert){163 var app = create();164 app.set('view engine', 'jade');165 166 app.get('/', function(req, res){167 res.internal = '1';168 res.method = function(){169 return this.internal;170 };171 res.render('scope.jade', { layout: false });172 });173 174 app.get('/custom', function(req, res){175 var scope = {176 internal: '2',177 method: function(){178 return this.internal;179 }180 };181 res.render('scope.jade', { layout: false, scope: scope });182 });183 184 assert.response(app,185 { url: '/' },186 { body: '<p>1</p>'});187188 assert.response(app,189 { url: '/custom' },190 { body: '<p>2</p>'});191 },192 Renamed Server#helpers() to Server#dynamicHelpers()Tj Holowaychukbefore adoption92f1557
line 193why, one step back193 'test #render() view helpers': function(assert){Added helper method create() to view tests to get a server with the correct views directory Make the default scope for rendering the response Added tests for default scope and custom scopeGuillermo Rauchbefore adoptionbb6164e
line 194why, one step back194 var app = create();Added dynamic view helper support. Closes #349Tj Holowaychukbefore adoption9ef8ea9
line 195why, one step back195Renamed Server#helpers() to Server#dynamicHelpers()Tj Holowaychukbefore adoption92f1557
line 196why, one step back196 app.helpers({ Added dynamic view helper support. Closes #349Tj Holowaychukbefore adoption9ef8ea9
line 197why, one step back197 lastName: 'holowaychuk',Renamed Server#helpers() to Server#dynamicHelpers()Tj Holowaychukbefore adoption92f1557
lines 198–203why, one step back198 foo: function(){199 return 'bar'; 200 }201 });202203 var ret = app.dynamicHelpers({Route callback signature changedTj Holowaychukbefore adoption75661a2
line 204why, one step back204 session: function(req, res){Added assertions for dynamic helper params and scopeTj Holowaychukbefore adoption8e487ba
line 205why, one step back205 assert.equal('object', typeof req, 'Test dynamic helper req');Fixed a dynamic helper assertionTj Holowaychukbefore adoptionfe99eb7
line 206why, one step back206 assert.equal('object', typeof res, 'Test dynamic helper res');Added assertions for dynamic helper params and scopeTj Holowaychukbefore adoption8e487ba
line 207why, one step back207 assert.ok(this instanceof express.Server, 'Test dynamic helper app scope');Added dynamic view helper support. Closes #349Tj Holowaychukbefore adoption9ef8ea9
lines 208–210why, one step back208 return req.session;209 }210 });Renamed Server#helpers() to Server#dynamicHelpers()Tj Holowaychukbefore adoption92f1557
lines 211–212why, one step back211212 assert.equal(app, ret, 'Server#helpers() is not chainable');Added dynamic view helper support. Closes #349Tj Holowaychukbefore adoption9ef8ea9
lines 213–220why, one step back213 214 app.get('/', function(req, res){215 req.session = { name: 'tj' };216 res.render('dynamic-helpers.jade', { layout: false });217 });218 219 assert.response(app,220 { url: '/' },Renamed Server#helpers() to Server#dynamicHelpers()Tj Holowaychukbefore adoption92f1557
line 221why, one step back221 { body: '<p>tj holowaychuk bar</p>' });Added dynamic view helper support. Closes #349Tj Holowaychukbefore adoption9ef8ea9
lines 222–223why, one step back222 },223 Added link to user account for github exampleTj Holowaychukbefore adoption893aa80
line 224why, one step back224 'test #partial()': function(assert){Added helper method create() to view tests to get a server with the correct views directory Make the default scope for rendering the response Added tests for default scope and custom scopeGuillermo Rauchbefore adoptionbb6164e
line 225why, one step back225 var app = create();Added link to user account for github exampleTj Holowaychukbefore adoption893aa80
lines 226–281why, one step back226227 // Auto-assigned local w/ collection option228 app.get('/', function(req, res){229 res.render('items.jade', { locals: { items: ['one', 'two'] }});230 });231 232 assert.response(app,233 { url: '/' },234 { body: '<html><body><ul><li>one</li><li>two</li></ul></body></html>' });235236 // Auto-assigned local w/ collection array 237 var movies = [238 { title: 'Nightmare Before Christmas', director: 'Tim Burton' },239 { title: 'Avatar', director: 'James Cameron' }240 ];241 app.get('/movies', function(req, res){242 res.render('movies.jade', { locals: { movies: movies }});243 });244 245 var html = [246 '<html>',247 '<body>',248 '<ul>',249 '<li>',250 '<div class="title">Nightmare Before Christmas</div>',251 '<div class="director">Tim Burton</div>',252 '</li>',253 '<li>',254 '<div class="title">Avatar</div>',255 '<div class="director">James Cameron</div>',256 '</li>',257 '</ul>',258 '</body>',259 '</html>'260 ].join('');261262 assert.response(app,263 { url: '/movies' },264 { body: html });265 266 // as: str collection option267 app.get('/user', function(req, res){268 res.send(res.partial('user.jade', {269 as: 'person',270 collection: [{ name: 'tj' }]271 }));272 });273 274 assert.response(app,275 { url: '/user' },276 { body: '<p>tj</p>' });277 278 // as: this collection option279 app.get('/person', function(req, res){280 res.send(res.partial('person.jade', {281 as: this,Added partial tests for collection locals + passed localsTj Holowaychukbefore adoptionf86f1e8
lines 282–283why, one step back282 collection: [{ name: 'tj' }],283 locals: { label: 'name:' }Added link to user account for github exampleTj Holowaychukbefore adoption893aa80
lines 284–288why, one step back284 }));285 });286 287 assert.response(app,288 { url: '/person' },Added partial tests for collection locals + passed localsTj Holowaychukbefore adoptionf86f1e8
line 289why, one step back289 { body: '<p>name: tj</p>' });Added link to user account for github exampleTj Holowaychukbefore adoption893aa80
lines 290–315why, one step back290291 // as: global collection option292 app.get('/videos', function(req, res){293 res.send(res.partial('video.jade', {294 as: global,295 collection: movies296 }));297 });298299 assert.response(app,300 { url: '/videos' },301 { body: '<p>Tim Burton</p><p>James Cameron</p>' });302 303 // Magic variables304 app.get('/magic', function(req, res){305 res.send(res.partial('magic.jade', {306 as: 'word',307 collection: ['one', 'two', 'three']308 }));309 });310 311 assert.response(app,312 { url: '/magic' },313 { body: '<li class="first">one</li><li class="word-1">two</li><li class="last">three</li>' });314 315 // Non-collection supportAdded support for "as" for non-collection partials. Closes #341Tj Holowaychukbefore adoption8db1138
lines 316–318why, one step back316 app.get('/movie', function(req, res){317 res.send(res.partial('movie.jade', {318 object: movies[0]Added link to user account for github exampleTj Holowaychukbefore adoption893aa80
lines 319–322why, one step back319 }));320 });321 322 assert.response(app,Added support for "as" for non-collection partials. Closes #341Tj Holowaychukbefore adoption8db1138
lines 323–335why, one step back323 { url: '/movie' },324 { body: '<li><div class="title">Nightmare Before Christmas</div><div class="director">Tim Burton</div></li>' });325 326 app.get('/video-global', function(req, res){327 res.send(res.partial('video.jade', {328 object: movies[0],329 as: global330 })); 331 });332 333 // Non-collection as: global334 assert.response(app,335 { url: '/video-global' },Added link to user account for github exampleTj Holowaychukbefore adoption893aa80
line 336why, one step back336 { body: '<p>Tim Burton</p>' });Added support for "as" for non-collection partials. Closes #341Tj Holowaychukbefore adoption8db1138
lines 337–340why, one step back337338 app.get('/person-this', function(req, res){339 res.send(res.partial('person.jade', {340 object: { name: 'tj' },Added partial tests for collection locals + passed localsTj Holowaychukbefore adoptionf86f1e8
line 341why, one step back341 locals: { label: 'User:' },Added support for "as" for non-collection partials. Closes #341Tj Holowaychukbefore adoption8db1138
lines 342–348why, one step back342 as: this343 })); 344 });345 346 // Non-collection as: this347 assert.response(app,348 { url: '/person-this' },Added partial tests for collection locals + passed localsTj Holowaychukbefore adoptionf86f1e8
lines 349–358why, one step back349 { body: '<p>User: tj</p>' });350 351 // No options352 app.get('/nothing', function(req, res){353 res.send(res.partial('hello.ejs'));354 });355 356 assert.response(app,357 { url: '/nothing' },358 { body: 'Hello' });Merge branch 'integration'Tj Holowaychukbefore adoption3fae10d
lines 359–376why, one step back359 },360 361 'test "partials" setting': function(assert){362 var app = create();363 app.set('partials', __dirname + '/fixtures/sub-templates');364365 app.get('/', function(req, res){366 res.render('items.jade', {367 layout: false,368 locals: {369 items: ['foo', 'bar']370 }371 });372 });373 374 assert.response(app,375 { url: '/' },376 { body: '<ul><li class="item">foo</li><li class="item">bar</li></ul>' });Merge branch 'app-level-view-options'Tj Holowaychukbefore adoption706e32c
lines 377–412why, one step back377 },378 379 'test "view options"': function(assert){380 var app = create();381 382 app.set('view options', {383 layout: false,384 open: '{{',385 close: '}}'386 });387 388 app.get('/', function(req, res, next){389 res.render('user.ejs', {390 locals: {391 name: 'tj',392 email: 'tj@vision-media.ca'393 }394 });395 });396 397 app.get('/video', function(req, res, next){398 res.render('video.ejs', {399 open: '<?',400 close: '?>',401 locals: {402 title: 'keyboard cat'403 }404 });405 });406 407 assert.response(app,408 { url: '/' },409 { body: '<h1>tj</h1>\n<p>tj@vision-media.ca</p>' });410 assert.response(app,411 { url: '/video' },412 { body: '<h1>keyboard cat</h1>' });Added link to user account for github exampleTj Holowaychukbefore adoption893aa80
lines 413–414why, one step back413 }414};