res.render.js
This file
Path
test/res.render.js
329 lines · 7.8 KiB · JavaScript
Last changed by
Merge tag '3.18.6'Douglas Christopher Wilsonbefore adoption4aa2801
History of this fileTake it
The walk stopped after 200 commits: lines older than ad3ca25 point at it.
deps: qs@1.2.2Douglas Christopher Wilsonbefore adoptionad3ca25
line 1why, one step back1Merge tag '3.18.6'Douglas Christopher Wilsonbefore adoption4aa2801
lines 2–4why, one step back2var express = require('..');3var request = require('supertest');4var tmpl = require('./support/tmpl');deps: qs@1.2.2Douglas Christopher Wilsonbefore adoptionad3ca25
lines 5–8why, one step back56describe('res', function(){7 describe('.render(name)', function(){8 it('should support absolute paths', function(done){Merge tag '3.18.6'Douglas Christopher Wilsonbefore adoption4aa2801
line 9why, one step back9 var app = createApp();deps: qs@1.2.2Douglas Christopher Wilsonbefore adoptionad3ca25
lines 10–13why, one step back1011 app.locals.user = { name: 'tobi' };1213 app.use(function(req, res){Merge tag '3.18.6'Douglas Christopher Wilsonbefore adoption4aa2801
line 14why, one step back14 res.render(__dirname + '/fixtures/user.tmpl');deps: qs@1.2.2Douglas Christopher Wilsonbefore adoptionad3ca25
lines 15–22why, one step back15 });1617 request(app)18 .get('/')19 .expect('<p>tobi</p>', done);20 })2122 it('should support absolute paths with "view engine"', function(done){Merge tag '3.18.6'Douglas Christopher Wilsonbefore adoption4aa2801
line 23why, one step back23 var app = createApp();deps: qs@1.2.2Douglas Christopher Wilsonbefore adoptionad3ca25
lines 24–25why, one step back2425 app.locals.user = { name: 'tobi' };Merge tag '3.18.6'Douglas Christopher Wilsonbefore adoption4aa2801
line 26why, one step back26 app.set('view engine', 'tmpl');deps: qs@1.2.2Douglas Christopher Wilsonbefore adoptionad3ca25
lines 27–37why, one step back2728 app.use(function(req, res){29 res.render(__dirname + '/fixtures/user');30 });3132 request(app)33 .get('/')34 .expect('<p>tobi</p>', done);35 })3637 it('should expose app.locals', function(done){Merge tag '3.18.6'Douglas Christopher Wilsonbefore adoption4aa2801
line 38why, one step back38 var app = createApp();deps: qs@1.2.2Douglas Christopher Wilsonbefore adoptionad3ca25
lines 39–43why, one step back3940 app.set('views', __dirname + '/fixtures');41 app.locals.user = { name: 'tobi' };4243 app.use(function(req, res){Merge tag '3.18.6'Douglas Christopher Wilsonbefore adoption4aa2801
line 44why, one step back44 res.render('user.tmpl');deps: qs@1.2.2Douglas Christopher Wilsonbefore adoptionad3ca25
lines 45–52why, one step back45 });4647 request(app)48 .get('/')49 .expect('<p>tobi</p>', done);50 })5152 it('should expose app.locals with `name` property', function(done){Merge tag '3.18.6'Douglas Christopher Wilsonbefore adoption4aa2801
line 53why, one step back53 var app = createApp();deps: qs@1.2.2Douglas Christopher Wilsonbefore adoptionad3ca25
lines 54–58why, one step back5455 app.set('views', __dirname + '/fixtures');56 app.locals.name = 'tobi';5758 app.use(function(req, res){Merge tag '3.18.6'Douglas Christopher Wilsonbefore adoption4aa2801
line 59why, one step back59 res.render('name.tmpl');deps: qs@1.2.2Douglas Christopher Wilsonbefore adoptionad3ca25
lines 60–67why, one step back60 });6162 request(app)63 .get('/')64 .expect('<p>tobi</p>', done);65 })6667 it('should support index.<engine>', function(done){Merge tag '3.18.6'Douglas Christopher Wilsonbefore adoption4aa2801
line 68why, one step back68 var app = createApp();deps: qs@1.2.2Douglas Christopher Wilsonbefore adoptionad3ca25
lines 69–70why, one step back6970 app.set('views', __dirname + '/fixtures');Merge tag '3.18.6'Douglas Christopher Wilsonbefore adoption4aa2801
line 71why, one step back71 app.set('view engine', 'tmpl');deps: qs@1.2.2Douglas Christopher Wilsonbefore adoptionad3ca25
lines 72–83why, one step back7273 app.use(function(req, res){74 res.render('blog/post');75 });7677 request(app)78 .get('/')79 .expect('<h1>blog post</h1>', done);80 })8182 describe('when an error occurs', function(){83 it('should next(err)', function(done){Merge tag '3.18.6'Douglas Christopher Wilsonbefore adoption4aa2801
line 84why, one step back84 var app = createApp();deps: qs@1.2.2Douglas Christopher Wilsonbefore adoptionad3ca25
lines 85–88why, one step back8586 app.set('views', __dirname + '/fixtures');8788 app.use(function(req, res){Merge tag '3.18.6'Douglas Christopher Wilsonbefore adoption4aa2801
line 89why, one step back89 res.render('user.tmpl');deps: qs@1.2.2Douglas Christopher Wilsonbefore adoptionad3ca25
lines 90–103why, one step back90 });9192 app.use(function(err, req, res, next){93 res.end(err.message);94 });9596 request(app)97 .get('/')98 .expect(/Cannot read property '[^']+' of undefined/, done);99 })100 })101102 describe('when "view engine" is given', function(){103 it('should render the template', function(done){Merge tag '3.18.6'Douglas Christopher Wilsonbefore adoption4aa2801
line 104why, one step back104 var app = createApp();deps: qs@1.2.2Douglas Christopher Wilsonbefore adoptionad3ca25
line 105why, one step back105Merge tag '3.18.6'Douglas Christopher Wilsonbefore adoption4aa2801
line 106why, one step back106 app.set('view engine', 'tmpl');deps: qs@1.2.2Douglas Christopher Wilsonbefore adoptionad3ca25
lines 107–117why, one step back107 app.set('views', __dirname + '/fixtures');108109 app.use(function(req, res){110 res.render('email');111 });112113 request(app)114 .get('/')115 .expect('<p>This is an email</p>', done);116 })117 })Add support for app.set('views', array)Douglas Christopher Wilsonbefore adoption6614352
lines 118–120why, one step back118119 describe('when "views" is given', function(){120 it('should lookup the file in the path', function(done){Merge tag '3.18.6'Douglas Christopher Wilsonbefore adoption4aa2801
line 121why, one step back121 var app = createApp();Add support for app.set('views', array)Douglas Christopher Wilsonbefore adoption6614352
lines 122–125why, one step back122123 app.set('views', __dirname + '/fixtures/default_layout');124125 app.use(function(req, res){Merge tag '3.18.6'Douglas Christopher Wilsonbefore adoption4aa2801
line 126why, one step back126 res.render('user.tmpl', { user: { name: 'tobi' } });Add support for app.set('views', array)Douglas Christopher Wilsonbefore adoption6614352
lines 127–135why, one step back127 });128129 request(app)130 .get('/')131 .expect('<p>tobi</p>', done);132 })133134 describe('when array of paths', function(){135 it('should lookup the file in the path', function(done){Merge tag '3.18.6'Douglas Christopher Wilsonbefore adoption4aa2801
line 136why, one step back136 var app = createApp();Add support for app.set('views', array)Douglas Christopher Wilsonbefore adoption6614352
lines 137–141why, one step back137 var views = [__dirname + '/fixtures/local_layout', __dirname + '/fixtures/default_layout'];138139 app.set('views', views);140141 app.use(function(req, res){Merge tag '3.18.6'Douglas Christopher Wilsonbefore adoption4aa2801
line 142why, one step back142 res.render('user.tmpl', { user: { name: 'tobi' } });Add support for app.set('views', array)Douglas Christopher Wilsonbefore adoption6614352
lines 143–150why, one step back143 });144145 request(app)146 .get('/')147 .expect('<span>tobi</span>', done);148 })149150 it('should lookup in later paths until found', function(done){Merge tag '3.18.6'Douglas Christopher Wilsonbefore adoption4aa2801
line 151why, one step back151 var app = createApp();Add support for app.set('views', array)Douglas Christopher Wilsonbefore adoption6614352
lines 152–156why, one step back152 var views = [__dirname + '/fixtures/local_layout', __dirname + '/fixtures/default_layout'];153154 app.set('views', views);155156 app.use(function(req, res){Merge tag '3.18.6'Douglas Christopher Wilsonbefore adoption4aa2801
line 157why, one step back157 res.render('name.tmpl', { name: 'tobi' });Add support for app.set('views', array)Douglas Christopher Wilsonbefore adoption6614352
lines 158–165why, one step back158 });159160 request(app)161 .get('/')162 .expect('<p>tobi</p>', done);163 })164 })165 })deps: qs@1.2.2Douglas Christopher Wilsonbefore adoptionad3ca25
lines 166–169why, one step back166 })167168 describe('.render(name, option)', function(){169 it('should render the template', function(done){Merge tag '3.18.6'Douglas Christopher Wilsonbefore adoption4aa2801
line 170why, one step back170 var app = createApp();deps: qs@1.2.2Douglas Christopher Wilsonbefore adoptionad3ca25
lines 171–176why, one step back171172 app.set('views', __dirname + '/fixtures');173174 var user = { name: 'tobi' };175176 app.use(function(req, res){Merge tag '3.18.6'Douglas Christopher Wilsonbefore adoption4aa2801
line 177why, one step back177 res.render('user.tmpl', { user: user });deps: qs@1.2.2Douglas Christopher Wilsonbefore adoptionad3ca25
lines 178–185why, one step back178 });179180 request(app)181 .get('/')182 .expect('<p>tobi</p>', done);183 })184185 it('should expose app.locals', function(done){Merge tag '3.18.6'Douglas Christopher Wilsonbefore adoption4aa2801
line 186why, one step back186 var app = createApp();deps: qs@1.2.2Douglas Christopher Wilsonbefore adoptionad3ca25
lines 187–191why, one step back187188 app.set('views', __dirname + '/fixtures');189 app.locals.user = { name: 'tobi' };190191 app.use(function(req, res){Merge tag '3.18.6'Douglas Christopher Wilsonbefore adoption4aa2801
line 192why, one step back192 res.render('user.tmpl');deps: qs@1.2.2Douglas Christopher Wilsonbefore adoptionad3ca25
lines 193–200why, one step back193 });194195 request(app)196 .get('/')197 .expect('<p>tobi</p>', done);198 })199200 it('should expose res.locals', function(done){Merge tag '3.18.6'Douglas Christopher Wilsonbefore adoption4aa2801
line 201why, one step back201 var app = createApp();deps: qs@1.2.2Douglas Christopher Wilsonbefore adoptionad3ca25
lines 202–206why, one step back202203 app.set('views', __dirname + '/fixtures');204205 app.use(function(req, res){206 res.locals.user = { name: 'tobi' };Merge tag '3.18.6'Douglas Christopher Wilsonbefore adoption4aa2801
line 207why, one step back207 res.render('user.tmpl');deps: qs@1.2.2Douglas Christopher Wilsonbefore adoptionad3ca25
lines 208–215why, one step back208 });209210 request(app)211 .get('/')212 .expect('<p>tobi</p>', done);213 })214215 it('should give precedence to res.locals over app.locals', function(done){Merge tag '3.18.6'Douglas Christopher Wilsonbefore adoption4aa2801
line 216why, one step back216 var app = createApp();deps: qs@1.2.2Douglas Christopher Wilsonbefore adoptionad3ca25
lines 217–222why, one step back217218 app.set('views', __dirname + '/fixtures');219 app.locals.user = { name: 'tobi' };220221 app.use(function(req, res){222 res.locals.user = { name: 'jane' };Merge tag '3.18.6'Douglas Christopher Wilsonbefore adoption4aa2801
line 223why, one step back223 res.render('user.tmpl', {});deps: qs@1.2.2Douglas Christopher Wilsonbefore adoptionad3ca25
lines 224–231why, one step back224 });225226 request(app)227 .get('/')228 .expect('<p>jane</p>', done);229 })230231 it('should give precedence to res.render() locals over res.locals', function(done){Merge tag '3.18.6'Douglas Christopher Wilsonbefore adoption4aa2801
line 232why, one step back232 var app = createApp();deps: qs@1.2.2Douglas Christopher Wilsonbefore adoptionad3ca25
lines 233–238why, one step back233234 app.set('views', __dirname + '/fixtures');235 var jane = { name: 'jane' };236237 app.use(function(req, res){238 res.locals.user = { name: 'tobi' };Merge tag '3.18.6'Douglas Christopher Wilsonbefore adoption4aa2801
line 239why, one step back239 res.render('user.tmpl', { user: jane });deps: qs@1.2.2Douglas Christopher Wilsonbefore adoptionad3ca25
lines 240–247why, one step back240 });241242 request(app)243 .get('/')244 .expect('<p>jane</p>', done);245 })246247 it('should give precedence to res.render() locals over app.locals', function(done){Merge tag '3.18.6'Douglas Christopher Wilsonbefore adoption4aa2801
line 248why, one step back248 var app = createApp();deps: qs@1.2.2Douglas Christopher Wilsonbefore adoptionad3ca25
lines 249–254why, one step back249250 app.set('views', __dirname + '/fixtures');251 app.locals.user = { name: 'tobi' };252 var jane = { name: 'jane' };253254 app.use(function(req, res){Merge tag '3.18.6'Douglas Christopher Wilsonbefore adoption4aa2801
line 255why, one step back255 res.render('user.tmpl', { user: jane });deps: qs@1.2.2Douglas Christopher Wilsonbefore adoptionad3ca25
lines 256–265why, one step back256 });257258 request(app)259 .get('/')260 .expect('<p>jane</p>', done);261 })262 })263264 describe('.render(name, options, fn)', function(){265 it('should pass the resulting string', function(done){Merge tag '3.18.6'Douglas Christopher Wilsonbefore adoption4aa2801
line 266why, one step back266 var app = createApp();deps: qs@1.2.2Douglas Christopher Wilsonbefore adoptionad3ca25
lines 267–271why, one step back267268 app.set('views', __dirname + '/fixtures');269270 app.use(function(req, res){271 var tobi = { name: 'tobi' };Merge tag '3.18.6'Douglas Christopher Wilsonbefore adoption4aa2801
line 272why, one step back272 res.render('user.tmpl', { user: tobi }, function (err, html) {deps: qs@1.2.2Douglas Christopher Wilsonbefore adoptionad3ca25
lines 273–285why, one step back273 html = html.replace('tobi', 'loki');274 res.end(html);275 });276 });277278 request(app)279 .get('/')280 .expect('<p>loki</p>', done);281 })282 })283284 describe('.render(name, fn)', function(){285 it('should pass the resulting string', function(done){Merge tag '3.18.6'Douglas Christopher Wilsonbefore adoption4aa2801
line 286why, one step back286 var app = createApp();deps: qs@1.2.2Douglas Christopher Wilsonbefore adoptionad3ca25
lines 287–291why, one step back287288 app.set('views', __dirname + '/fixtures');289290 app.use(function(req, res){291 res.locals.user = { name: 'tobi' };Merge tag '3.18.6'Douglas Christopher Wilsonbefore adoption4aa2801
line 292why, one step back292 res.render('user.tmpl', function (err, html) {deps: qs@1.2.2Douglas Christopher Wilsonbefore adoptionad3ca25
lines 293–304why, one step back293 html = html.replace('tobi', 'loki');294 res.end(html);295 });296 });297298 request(app)299 .get('/')300 .expect('<p>loki</p>', done);301 })302303 describe('when an error occurs', function(){304 it('should pass it to the callback', function(done){Merge tag '3.18.6'Douglas Christopher Wilsonbefore adoption4aa2801
line 305why, one step back305 var app = createApp();deps: qs@1.2.2Douglas Christopher Wilsonbefore adoptionad3ca25
lines 306–309why, one step back306307 app.set('views', __dirname + '/fixtures');308309 app.use(function(req, res){Merge tag '3.18.6'Douglas Christopher Wilsonbefore adoption4aa2801
line 310why, one step back310 res.render('user.tmpl', function (err) {deps: qs@1.2.2Douglas Christopher Wilsonbefore adoptionad3ca25
lines 311–321why, one step back311 res.end(err.message);312 });313 });314315 request(app)316 .get('/')317 .expect(/Cannot read property '[^']+' of undefined/, done);318 })319 })320 })321})Merge tag '3.18.6'Douglas Christopher Wilsonbefore adoption4aa2801
lines 322–329why, one step back322323function createApp() {324 var app = express();325326 app.engine('.tmpl', tmpl);327328 return app;329}