Skip to content
Myr

view.test.js

This file

Path

test/view.test.js

426 lines · 12.9 KiB · JavaScript

Last changed by

Merge branch 'helper-precedence'Tj Holowaychukbefore adoption5bfa3f6

History of this file

Take 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 back
1
2/**3 * Module dependencies.4 */56var express = require('express'),7 connect = require('connect'),8 view = require('express/view');9

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 10why, one step back
10var create = function(){

Style fixesTj Holowaychukbefore adoption0eeef2d

lines 11–13why, one step back
11 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 back
14};
15

Added link to user account for github exampleTj Holowaychukbefore adoption893aa80

lines 16–17why, one step back
16module.exports = {
17 'test #render()': function(assert){

Merge branch 'fix-layouts'Tj Holowaychukbefore adoptiondadea8c

line 18why, one step back
18 var app = create();

Added link to user account for github exampleTj Holowaychukbefore adoption893aa80

lines 19–38why, one step back
19 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 back
39 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 back
44 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 back
49 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 back
52
53 assert.response(app,54 { url: '/' },

res.render() using res.send()Tj Holowaychukbefore adoptioncba985b

line 55why, one step back
55 { 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 back
56 assert.response(app,
57 { url: '/jade' },

Added test for absolute view pathTj Holowaychukbefore adoptione6f4b04

lines 58–60why, one step back
58 { 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 back
61 { 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 back
77 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 });83

Added link to user account for github exampleTj Holowaychukbefore adoption893aa80

lines 84–86why, one step back
84 },
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 back
87 var app = create();

Added link to user account for github exampleTj Holowaychukbefore adoption893aa80

lines 88–101why, one step back
88 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 back
102 '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 back
105
106 app.get('/', function(req, res){

Fixed res.render() callback when a layout is used [thanks guillermo]Tj Holowaychukbefore adoption5e1a271

lines 107–110why, one step back
107 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 back
111 });

Added support for passing of layout name without extensionTj Holowaychukbefore adoptiona461815

lines 112–114why, one step back
112 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 back
115 app.get('/relative', function(req, res){

Added test for layouts in a directoryTj Holowaychukbefore adoptionb463bd7

lines 116–117why, one step back
116 res.render('index.jade', { layout: 'layouts/foo.jade' });
117 });

Added failing test for absolute layoutsTj Holowaychukbefore adoptiond651ffa

lines 118–120why, one step back
118 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 back
121 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 back
124
125 assert.response(app,126 { url: '/' },

Added support for passing of layout name without extensionTj Holowaychukbefore adoptiona461815

lines 127–129why, one step back
127 { 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 back
130 { body: '<cool><p>Welcome</p></cool>' });

Added test for layouts in a directoryTj Holowaychukbefore adoptionb463bd7

line 131why, one step back
131 assert.response(app,

s/foo/relative/Tj Holowaychukbefore adoptione554378

line 132why, one step back
132 { url: '/relative' },

Added failing test for absolute layoutsTj Holowaychukbefore adoptiond651ffa

lines 133–135why, one step back
133 { body: '<foo></foo>' });
134 assert.response(app,135 { url: '/absolute' },

Added test for layouts in a directoryTj Holowaychukbefore adoptionb463bd7

line 136why, one step back
136 { body: '<foo></foo>' });

Merge branch 'fix-layouts'Tj Holowaychukbefore adoptiondadea8c

lines 137–142why, one step back
137 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 back
143
144 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 back
147 },
148

Added test for specific layouts with "view engine" setTj Holowaychukbefore adoptioneedf54b

line 149why, one step back
149 '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 back
150 var app = create();

Added test for specific layouts with "view engine" setTj Holowaychukbefore adoptioneedf54b

lines 151–161why, one step back
151 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 back
162 '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 back
193 '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 back
194 var app = create();

Added dynamic view helper support. Closes #349Tj Holowaychukbefore adoption9ef8ea9

line 195why, one step back
195

Renamed Server#helpers() to Server#dynamicHelpers()Tj Holowaychukbefore adoption92f1557

line 196why, one step back
196 app.helpers({

Added dynamic view helper support. Closes #349Tj Holowaychukbefore adoption9ef8ea9

line 197why, one step back
197 lastName: 'holowaychuk',

Renamed Server#helpers() to Server#dynamicHelpers()Tj Holowaychukbefore adoption92f1557

lines 198–203why, one step back
198 foo: function(){
199 return 'bar'; 200 }201 });202203 var ret = app.dynamicHelpers({

Route callback signature changedTj Holowaychukbefore adoption75661a2

line 204why, one step back
204 session: function(req, res){

Added assertions for dynamic helper params and scopeTj Holowaychukbefore adoption8e487ba

line 205why, one step back
205 assert.equal('object', typeof req, 'Test dynamic helper req');

Fixed a dynamic helper assertionTj Holowaychukbefore adoptionfe99eb7

line 206why, one step back
206 assert.equal('object', typeof res, 'Test dynamic helper res');

Added assertions for dynamic helper params and scopeTj Holowaychukbefore adoption8e487ba

line 207why, one step back
207 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 back
208 return req.session;
209 }210 });

Renamed Server#helpers() to Server#dynamicHelpers()Tj Holowaychukbefore adoption92f1557

lines 211–212why, one step back
211
212 assert.equal(app, ret, 'Server#helpers() is not chainable');

Added dynamic view helper support. Closes #349Tj Holowaychukbefore adoption9ef8ea9

lines 213–217why, one step back
213
214 app.get('/', function(req, res){215 req.session = { name: 'tj' };216 res.render('dynamic-helpers.jade', { layout: false });217 });

Merge branch 'helper-precedence'Tj Holowaychukbefore adoption5bfa3f6

lines 218–226why, one step back
218 app.get('/precedence', function(req, res){
219 req.session = { name: 'tj' };220 res.render('dynamic-helpers.jade', {221 layout: false,222 locals: {223 lastName: 'foobar'224 }225 });226 });

Added dynamic view helper support. Closes #349Tj Holowaychukbefore adoption9ef8ea9

lines 227–229why, one step back
227
228 assert.response(app,229 { url: '/' },

Renamed Server#helpers() to Server#dynamicHelpers()Tj Holowaychukbefore adoption92f1557

line 230why, one step back
230 { body: '<p>tj holowaychuk bar</p>' });

Merge branch 'helper-precedence'Tj Holowaychukbefore adoption5bfa3f6

lines 231–233why, one step back
231 assert.response(app,
232 { url: '/precedence' },233 { body: '<p>tj foobar bar</p>' });

Added dynamic view helper support. Closes #349Tj Holowaychukbefore adoption9ef8ea9

lines 234–235why, one step back
234 },
235

Added link to user account for github exampleTj Holowaychukbefore adoption893aa80

line 236why, one step back
236 '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 237why, one step back
237 var app = create();

Added link to user account for github exampleTj Holowaychukbefore adoption893aa80

lines 238–293why, one step back
238
239 // Auto-assigned local w/ collection option240 app.get('/', function(req, res){241 res.render('items.jade', { locals: { items: ['one', 'two'] }});242 });243 244 assert.response(app,245 { url: '/' },246 { body: '<html><body><ul><li>one</li><li>two</li></ul></body></html>' });247248 // Auto-assigned local w/ collection array 249 var movies = [250 { title: 'Nightmare Before Christmas', director: 'Tim Burton' },251 { title: 'Avatar', director: 'James Cameron' }252 ];253 app.get('/movies', function(req, res){254 res.render('movies.jade', { locals: { movies: movies }});255 });256 257 var html = [258 '<html>',259 '<body>',260 '<ul>',261 '<li>',262 '<div class="title">Nightmare Before Christmas</div>',263 '<div class="director">Tim Burton</div>',264 '</li>',265 '<li>',266 '<div class="title">Avatar</div>',267 '<div class="director">James Cameron</div>',268 '</li>',269 '</ul>',270 '</body>',271 '</html>'272 ].join('');273274 assert.response(app,275 { url: '/movies' },276 { body: html });277 278 // as: str collection option279 app.get('/user', function(req, res){280 res.send(res.partial('user.jade', {281 as: 'person',282 collection: [{ name: 'tj' }]283 }));284 });285 286 assert.response(app,287 { url: '/user' },288 { body: '<p>tj</p>' });289 290 // as: this collection option291 app.get('/person', function(req, res){292 res.send(res.partial('person.jade', {293 as: this,

Added partial tests for collection locals + passed localsTj Holowaychukbefore adoptionf86f1e8

lines 294–295why, one step back
294 collection: [{ name: 'tj' }],
295 locals: { label: 'name:' }

Added link to user account for github exampleTj Holowaychukbefore adoption893aa80

lines 296–300why, one step back
296 }));
297 });298 299 assert.response(app,300 { url: '/person' },

Added partial tests for collection locals + passed localsTj Holowaychukbefore adoptionf86f1e8

line 301why, one step back
301 { body: '<p>name: tj</p>' });

Added link to user account for github exampleTj Holowaychukbefore adoption893aa80

lines 302–327why, one step back
302
303 // as: global collection option304 app.get('/videos', function(req, res){305 res.send(res.partial('video.jade', {306 as: global,307 collection: movies308 }));309 });310311 assert.response(app,312 { url: '/videos' },313 { body: '<p>Tim Burton</p><p>James Cameron</p>' });314 315 // Magic variables316 app.get('/magic', function(req, res){317 res.send(res.partial('magic.jade', {318 as: 'word',319 collection: ['one', 'two', 'three']320 }));321 });322 323 assert.response(app,324 { url: '/magic' },325 { body: '<li class="first">one</li><li class="word-1">two</li><li class="last">three</li>' });326 327 // Non-collection support

Added support for "as" for non-collection partials. Closes #341Tj Holowaychukbefore adoption8db1138

lines 328–330why, one step back
328 app.get('/movie', function(req, res){
329 res.send(res.partial('movie.jade', {330 object: movies[0]

Added link to user account for github exampleTj Holowaychukbefore adoption893aa80

lines 331–334why, one step back
331 }));
332 });333 334 assert.response(app,

Added support for "as" for non-collection partials. Closes #341Tj Holowaychukbefore adoption8db1138

lines 335–347why, one step back
335 { url: '/movie' },
336 { body: '<li><div class="title">Nightmare Before Christmas</div><div class="director">Tim Burton</div></li>' });337 338 app.get('/video-global', function(req, res){339 res.send(res.partial('video.jade', {340 object: movies[0],341 as: global342 })); 343 });344 345 // Non-collection as: global346 assert.response(app,347 { url: '/video-global' },

Added link to user account for github exampleTj Holowaychukbefore adoption893aa80

line 348why, one step back
348 { body: '<p>Tim Burton</p>' });

Added support for "as" for non-collection partials. Closes #341Tj Holowaychukbefore adoption8db1138

lines 349–352why, one step back
349
350 app.get('/person-this', function(req, res){351 res.send(res.partial('person.jade', {352 object: { name: 'tj' },

Added partial tests for collection locals + passed localsTj Holowaychukbefore adoptionf86f1e8

line 353why, one step back
353 locals: { label: 'User:' },

Added support for "as" for non-collection partials. Closes #341Tj Holowaychukbefore adoption8db1138

lines 354–360why, one step back
354 as: this
355 })); 356 });357 358 // Non-collection as: this359 assert.response(app,360 { url: '/person-this' },

Added partial tests for collection locals + passed localsTj Holowaychukbefore adoptionf86f1e8

lines 361–370why, one step back
361 { body: '<p>User: tj</p>' });
362 363 // No options364 app.get('/nothing', function(req, res){365 res.send(res.partial('hello.ejs'));366 });367 368 assert.response(app,369 { url: '/nothing' },370 { body: 'Hello' });

Merge branch 'integration'Tj Holowaychukbefore adoption3fae10d

lines 371–388why, one step back
371 },
372 373 'test "partials" setting': function(assert){374 var app = create();375 app.set('partials', __dirname + '/fixtures/sub-templates');376377 app.get('/', function(req, res){378 res.render('items.jade', {379 layout: false,380 locals: {381 items: ['foo', 'bar']382 }383 });384 });385 386 assert.response(app,387 { url: '/' },388 { body: '<ul><li class="item">foo</li><li class="item">bar</li></ul>' });

Merge branch 'app-level-view-options'Tj Holowaychukbefore adoption706e32c

lines 389–424why, one step back
389 },
390 391 'test "view options"': function(assert){392 var app = create();393 394 app.set('view options', {395 layout: false,396 open: '{{',397 close: '}}'398 });399 400 app.get('/', function(req, res, next){401 res.render('user.ejs', {402 locals: {403 name: 'tj',404 email: 'tj@vision-media.ca'405 }406 });407 });408 409 app.get('/video', function(req, res, next){410 res.render('video.ejs', {411 open: '<?',412 close: '?>',413 locals: {414 title: 'keyboard cat'415 }416 });417 });418 419 assert.response(app,420 { url: '/' },421 { body: '<h1>tj</h1>\n<p>tj@vision-media.ca</p>' });422 assert.response(app,423 { url: '/video' },424 { body: '<h1>keyboard cat</h1>' });

Added link to user account for github exampleTj Holowaychukbefore adoption893aa80

lines 425–426why, one step back
425 }
426};