res.render.js
This file
Path
test/res.render.js
343 lines · 8.2 KiB · JavaScript
Last changed by
tests: add test for rendering extensionless file without view engineDouglas Christopher Wilsonbefore adoption0634e7e
History of this fileTake it
The walk stopped after 200 commits: lines older than 6bc7574 point at it.
docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574
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');docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574
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();docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574
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');docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574
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();docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574
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');docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574
lines 27–36why, 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 })36tests: add test for rendering extensionless file without view engineDouglas Christopher Wilsonbefore adoption0634e7e
lines 37–50why, one step back37 it('should error without "view engine" set and no file extension', function (done) {38 var app = createApp();3940 app.locals.user = { name: 'tobi' };4142 app.use(function(req, res){43 res.render(__dirname + '/fixtures/user');44 });4546 request(app)47 .get('/')48 .expect(500, /No default engine was specified/, done);49 })50docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574
line 51why, one step back51 it('should expose app.locals', function(done){Merge tag '3.18.6'Douglas Christopher Wilsonbefore adoption4aa2801
line 52why, one step back52 var app = createApp();docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574
lines 53–57why, one step back5354 app.set('views', __dirname + '/fixtures');55 app.locals.user = { name: 'tobi' };5657 app.use(function(req, res){Merge tag '3.18.6'Douglas Christopher Wilsonbefore adoption4aa2801
line 58why, one step back58 res.render('user.tmpl');docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574
lines 59–66why, one step back59 });6061 request(app)62 .get('/')63 .expect('<p>tobi</p>', done);64 })6566 it('should expose app.locals with `name` property', function(done){Merge tag '3.18.6'Douglas Christopher Wilsonbefore adoption4aa2801
line 67why, one step back67 var app = createApp();docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574
lines 68–72why, one step back6869 app.set('views', __dirname + '/fixtures');70 app.locals.name = 'tobi';7172 app.use(function(req, res){Merge tag '3.18.6'Douglas Christopher Wilsonbefore adoption4aa2801
line 73why, one step back73 res.render('name.tmpl');docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574
lines 74–81why, one step back74 });7576 request(app)77 .get('/')78 .expect('<p>tobi</p>', done);79 })8081 it('should support index.<engine>', function(done){Merge tag '3.18.6'Douglas Christopher Wilsonbefore adoption4aa2801
line 82why, one step back82 var app = createApp();docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574
lines 83–84why, one step back8384 app.set('views', __dirname + '/fixtures');Merge tag '3.18.6'Douglas Christopher Wilsonbefore adoption4aa2801
line 85why, one step back85 app.set('view engine', 'tmpl');docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574
lines 86–97why, one step back8687 app.use(function(req, res){88 res.render('blog/post');89 });9091 request(app)92 .get('/')93 .expect('<h1>blog post</h1>', done);94 })9596 describe('when an error occurs', function(){97 it('should next(err)', function(done){Merge tag '3.18.6'Douglas Christopher Wilsonbefore adoption4aa2801
line 98why, one step back98 var app = createApp();docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574
lines 99–102why, one step back99100 app.set('views', __dirname + '/fixtures');101102 app.use(function(req, res){Merge tag '3.18.6'Douglas Christopher Wilsonbefore adoption4aa2801
line 103why, one step back103 res.render('user.tmpl');docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574
lines 104–117why, one step back104 });105106 app.use(function(err, req, res, next){107 res.end(err.message);108 });109110 request(app)111 .get('/')112 .expect(/Cannot read property '[^']+' of undefined/, done);113 })114 })115116 describe('when "view engine" is given', function(){117 it('should render the template', function(done){Merge tag '3.18.6'Douglas Christopher Wilsonbefore adoption4aa2801
line 118why, one step back118 var app = createApp();docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574
line 119why, one step back119Merge tag '3.18.6'Douglas Christopher Wilsonbefore adoption4aa2801
line 120why, one step back120 app.set('view engine', 'tmpl');docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574
lines 121–131why, one step back121 app.set('views', __dirname + '/fixtures');122123 app.use(function(req, res){124 res.render('email');125 });126127 request(app)128 .get('/')129 .expect('<p>This is an email</p>', done);130 })131 })Add support for app.set('views', array)Douglas Christopher Wilsonbefore adoption6614352
lines 132–134why, one step back132133 describe('when "views" is given', function(){134 it('should lookup the file in the path', function(done){Merge tag '3.18.6'Douglas Christopher Wilsonbefore adoption4aa2801
line 135why, one step back135 var app = createApp();Add support for app.set('views', array)Douglas Christopher Wilsonbefore adoption6614352
lines 136–139why, one step back136137 app.set('views', __dirname + '/fixtures/default_layout');138139 app.use(function(req, res){Merge tag '3.18.6'Douglas Christopher Wilsonbefore adoption4aa2801
line 140why, one step back140 res.render('user.tmpl', { user: { name: 'tobi' } });Add support for app.set('views', array)Douglas Christopher Wilsonbefore adoption6614352
lines 141–149why, one step back141 });142143 request(app)144 .get('/')145 .expect('<p>tobi</p>', done);146 })147148 describe('when array of paths', function(){149 it('should lookup the file in the path', function(done){Merge tag '3.18.6'Douglas Christopher Wilsonbefore adoption4aa2801
line 150why, one step back150 var app = createApp();Add support for app.set('views', array)Douglas Christopher Wilsonbefore adoption6614352
lines 151–155why, one step back151 var views = [__dirname + '/fixtures/local_layout', __dirname + '/fixtures/default_layout'];152153 app.set('views', views);154155 app.use(function(req, res){Merge tag '3.18.6'Douglas Christopher Wilsonbefore adoption4aa2801
line 156why, one step back156 res.render('user.tmpl', { user: { name: 'tobi' } });Add support for app.set('views', array)Douglas Christopher Wilsonbefore adoption6614352
lines 157–164why, one step back157 });158159 request(app)160 .get('/')161 .expect('<span>tobi</span>', done);162 })163164 it('should lookup in later paths until found', function(done){Merge tag '3.18.6'Douglas Christopher Wilsonbefore adoption4aa2801
line 165why, one step back165 var app = createApp();Add support for app.set('views', array)Douglas Christopher Wilsonbefore adoption6614352
lines 166–170why, one step back166 var views = [__dirname + '/fixtures/local_layout', __dirname + '/fixtures/default_layout'];167168 app.set('views', views);169170 app.use(function(req, res){Merge tag '3.18.6'Douglas Christopher Wilsonbefore adoption4aa2801
line 171why, one step back171 res.render('name.tmpl', { name: 'tobi' });Add support for app.set('views', array)Douglas Christopher Wilsonbefore adoption6614352
lines 172–179why, one step back172 });173174 request(app)175 .get('/')176 .expect('<p>tobi</p>', done);177 })178 })179 })docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574
lines 180–183why, one step back180 })181182 describe('.render(name, option)', function(){183 it('should render the template', function(done){Merge tag '3.18.6'Douglas Christopher Wilsonbefore adoption4aa2801
line 184why, one step back184 var app = createApp();docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574
lines 185–190why, one step back185186 app.set('views', __dirname + '/fixtures');187188 var user = { name: 'tobi' };189190 app.use(function(req, res){Merge tag '3.18.6'Douglas Christopher Wilsonbefore adoption4aa2801
line 191why, one step back191 res.render('user.tmpl', { user: user });docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574
lines 192–199why, one step back192 });193194 request(app)195 .get('/')196 .expect('<p>tobi</p>', done);197 })198199 it('should expose app.locals', function(done){Merge tag '3.18.6'Douglas Christopher Wilsonbefore adoption4aa2801
line 200why, one step back200 var app = createApp();docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574
lines 201–205why, one step back201202 app.set('views', __dirname + '/fixtures');203 app.locals.user = { name: 'tobi' };204205 app.use(function(req, res){Merge tag '3.18.6'Douglas Christopher Wilsonbefore adoption4aa2801
line 206why, one step back206 res.render('user.tmpl');docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574
lines 207–214why, one step back207 });208209 request(app)210 .get('/')211 .expect('<p>tobi</p>', done);212 })213214 it('should expose res.locals', function(done){Merge tag '3.18.6'Douglas Christopher Wilsonbefore adoption4aa2801
line 215why, one step back215 var app = createApp();docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574
lines 216–220why, one step back216217 app.set('views', __dirname + '/fixtures');218219 app.use(function(req, res){220 res.locals.user = { name: 'tobi' };Merge tag '3.18.6'Douglas Christopher Wilsonbefore adoption4aa2801
line 221why, one step back221 res.render('user.tmpl');docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574
lines 222–229why, one step back222 });223224 request(app)225 .get('/')226 .expect('<p>tobi</p>', done);227 })228229 it('should give precedence to res.locals over app.locals', function(done){Merge tag '3.18.6'Douglas Christopher Wilsonbefore adoption4aa2801
line 230why, one step back230 var app = createApp();docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574
lines 231–236why, one step back231232 app.set('views', __dirname + '/fixtures');233 app.locals.user = { name: 'tobi' };234235 app.use(function(req, res){236 res.locals.user = { name: 'jane' };Merge tag '3.18.6'Douglas Christopher Wilsonbefore adoption4aa2801
line 237why, one step back237 res.render('user.tmpl', {});docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574
lines 238–245why, one step back238 });239240 request(app)241 .get('/')242 .expect('<p>jane</p>', done);243 })244245 it('should give precedence to res.render() locals over res.locals', function(done){Merge tag '3.18.6'Douglas Christopher Wilsonbefore adoption4aa2801
line 246why, one step back246 var app = createApp();docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574
lines 247–252why, one step back247248 app.set('views', __dirname + '/fixtures');249 var jane = { name: 'jane' };250251 app.use(function(req, res){252 res.locals.user = { name: 'tobi' };Merge tag '3.18.6'Douglas Christopher Wilsonbefore adoption4aa2801
line 253why, one step back253 res.render('user.tmpl', { user: jane });docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574
lines 254–261why, one step back254 });255256 request(app)257 .get('/')258 .expect('<p>jane</p>', done);259 })260261 it('should give precedence to res.render() locals over app.locals', function(done){Merge tag '3.18.6'Douglas Christopher Wilsonbefore adoption4aa2801
line 262why, one step back262 var app = createApp();docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574
lines 263–268why, one step back263264 app.set('views', __dirname + '/fixtures');265 app.locals.user = { name: 'tobi' };266 var jane = { name: 'jane' };267268 app.use(function(req, res){Merge tag '3.18.6'Douglas Christopher Wilsonbefore adoption4aa2801
line 269why, one step back269 res.render('user.tmpl', { user: jane });docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574
lines 270–279why, one step back270 });271272 request(app)273 .get('/')274 .expect('<p>jane</p>', done);275 })276 })277278 describe('.render(name, options, fn)', function(){279 it('should pass the resulting string', function(done){Merge tag '3.18.6'Douglas Christopher Wilsonbefore adoption4aa2801
line 280why, one step back280 var app = createApp();docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574
lines 281–285why, one step back281282 app.set('views', __dirname + '/fixtures');283284 app.use(function(req, res){285 var tobi = { name: 'tobi' };Merge tag '3.18.6'Douglas Christopher Wilsonbefore adoption4aa2801
line 286why, one step back286 res.render('user.tmpl', { user: tobi }, function (err, html) {docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574
lines 287–299why, one step back287 html = html.replace('tobi', 'loki');288 res.end(html);289 });290 });291292 request(app)293 .get('/')294 .expect('<p>loki</p>', done);295 })296 })297298 describe('.render(name, fn)', function(){299 it('should pass the resulting string', function(done){Merge tag '3.18.6'Douglas Christopher Wilsonbefore adoption4aa2801
line 300why, one step back300 var app = createApp();docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574
lines 301–305why, one step back301302 app.set('views', __dirname + '/fixtures');303304 app.use(function(req, res){305 res.locals.user = { name: 'tobi' };Merge tag '3.18.6'Douglas Christopher Wilsonbefore adoption4aa2801
line 306why, one step back306 res.render('user.tmpl', function (err, html) {docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574
lines 307–318why, one step back307 html = html.replace('tobi', 'loki');308 res.end(html);309 });310 });311312 request(app)313 .get('/')314 .expect('<p>loki</p>', done);315 })316317 describe('when an error occurs', function(){318 it('should pass it to the callback', function(done){Merge tag '3.18.6'Douglas Christopher Wilsonbefore adoption4aa2801
line 319why, one step back319 var app = createApp();docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574
lines 320–323why, one step back320321 app.set('views', __dirname + '/fixtures');322323 app.use(function(req, res){Merge tag '3.18.6'Douglas Christopher Wilsonbefore adoption4aa2801
line 324why, one step back324 res.render('user.tmpl', function (err) {docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574
lines 325–335why, one step back325 res.end(err.message);326 });327 });328329 request(app)330 .get('/')331 .expect(/Cannot read property '[^']+' of undefined/, done);332 })333 })334 })335})Merge tag '3.18.6'Douglas Christopher Wilsonbefore adoption4aa2801
lines 336–343why, one step back336337function createApp() {338 var app = express();339340 app.engine('.tmpl', tmpl);341342 return app;343}