res.render.js
This file
Path
test/res.render.js
350 lines · 8.5 KiB · JavaScript
Last changed by
tests: use path.join instead of concatenationchainhelenbefore adoptioneece385
History of this fileTake it
The walk stopped after 200 commits: lines older than 2ac2509 point at it.
4.13.1Douglas Christopher Wilsonbefore adoption2ac2509
lines 1–2why, one step back12var express = require('..');tests: use path.join instead of concatenationchainhelenbefore adoptioneece385
line 3why, one step back3var path = require('path')4.13.1Douglas Christopher Wilsonbefore adoption2ac2509
lines 4–14why, one step back4var request = require('supertest');5var tmpl = require('./support/tmpl');67describe('res', function(){8 describe('.render(name)', function(){9 it('should support absolute paths', function(done){10 var app = createApp();1112 app.locals.user = { name: 'tobi' };1314 app.use(function(req, res){tests: use path.join instead of concatenationchainhelenbefore adoptioneece385
line 15why, one step back15 res.render(path.join(__dirname, 'fixtures', 'user.tmpl'))4.13.1Douglas Christopher Wilsonbefore adoption2ac2509
lines 16–29why, one step back16 });1718 request(app)19 .get('/')20 .expect('<p>tobi</p>', done);21 })2223 it('should support absolute paths with "view engine"', function(done){24 var app = createApp();2526 app.locals.user = { name: 'tobi' };27 app.set('view engine', 'tmpl');2829 app.use(function(req, res){tests: use path.join instead of concatenationchainhelenbefore adoptioneece385
line 30why, one step back30 res.render(path.join(__dirname, 'fixtures', 'user'))4.13.1Douglas Christopher Wilsonbefore adoption2ac2509
lines 31–43why, one step back31 });3233 request(app)34 .get('/')35 .expect('<p>tobi</p>', done);36 })3738 it('should error without "view engine" set and no file extension', function (done) {39 var app = createApp();4041 app.locals.user = { name: 'tobi' };4243 app.use(function(req, res){tests: use path.join instead of concatenationchainhelenbefore adoptioneece385
line 44why, one step back44 res.render(path.join(__dirname, 'fixtures', 'user'))4.13.1Douglas Christopher Wilsonbefore adoption2ac2509
lines 45–54why, one step back45 });4647 request(app)48 .get('/')49 .expect(500, /No default engine was specified/, done);50 })5152 it('should expose app.locals', function(done){53 var app = createApp();54tests: use path.join instead of concatenationchainhelenbefore adoptioneece385
line 55why, one step back55 app.set('views', path.join(__dirname, 'fixtures'))4.13.1Douglas Christopher Wilsonbefore adoption2ac2509
lines 56–69why, one step back56 app.locals.user = { name: 'tobi' };5758 app.use(function(req, res){59 res.render('user.tmpl');60 });6162 request(app)63 .get('/')64 .expect('<p>tobi</p>', done);65 })6667 it('should expose app.locals with `name` property', function(done){68 var app = createApp();69tests: use path.join instead of concatenationchainhelenbefore adoptioneece385
line 70why, one step back70 app.set('views', path.join(__dirname, 'fixtures'))4.13.1Douglas Christopher Wilsonbefore adoption2ac2509
lines 71–84why, one step back71 app.locals.name = 'tobi';7273 app.use(function(req, res){74 res.render('name.tmpl');75 });7677 request(app)78 .get('/')79 .expect('<p>tobi</p>', done);80 })8182 it('should support index.<engine>', function(done){83 var app = createApp();84tests: use path.join instead of concatenationchainhelenbefore adoptioneece385
line 85why, one step back85 app.set('views', path.join(__dirname, 'fixtures'))4.13.1Douglas Christopher Wilsonbefore adoption2ac2509
lines 86–100why, one step back86 app.set('view engine', 'tmpl');8788 app.use(function(req, res){89 res.render('blog/post');90 });9192 request(app)93 .get('/')94 .expect('<h1>blog post</h1>', done);95 })9697 describe('when an error occurs', function(){98 it('should next(err)', function(done){99 var app = createApp();100tests: use path.join instead of concatenationchainhelenbefore adoptioneece385
line 101why, one step back101 app.set('views', path.join(__dirname, 'fixtures'))4.13.1Douglas Christopher Wilsonbefore adoption2ac2509
lines 102–121why, one step back102103 app.use(function(req, res){104 res.render('user.tmpl');105 });106107 app.use(function(err, req, res, next){108 res.end(err.message);109 });110111 request(app)112 .get('/')113 .expect(/Cannot read property '[^']+' of undefined/, done);114 })115 })116117 describe('when "view engine" is given', function(){118 it('should render the template', function(done){119 var app = createApp();120121 app.set('view engine', 'tmpl');tests: use path.join instead of concatenationchainhelenbefore adoptioneece385
line 122why, one step back122 app.set('views', path.join(__dirname, 'fixtures'))4.13.1Douglas Christopher Wilsonbefore adoption2ac2509
lines 123–137why, one step back123124 app.use(function(req, res){125 res.render('email');126 });127128 request(app)129 .get('/')130 .expect('<p>This is an email</p>', done);131 })132 })133134 describe('when "views" is given', function(){135 it('should lookup the file in the path', function(done){136 var app = createApp();137tests: use path.join instead of concatenationchainhelenbefore adoptioneece385
line 138why, one step back138 app.set('views', path.join(__dirname, 'fixtures', 'default_layout'))4.13.1Douglas Christopher Wilsonbefore adoption2ac2509
lines 139–151why, one step back139140 app.use(function(req, res){141 res.render('user.tmpl', { user: { name: 'tobi' } });142 });143144 request(app)145 .get('/')146 .expect('<p>tobi</p>', done);147 })148149 describe('when array of paths', function(){150 it('should lookup the file in the path', function(done){151 var app = createApp();tests: use path.join instead of concatenationchainhelenbefore adoptioneece385
lines 152–155why, one step back152 var views = [153 path.join(__dirname, 'fixtures', 'local_layout'),154 path.join(__dirname, 'fixtures', 'default_layout')155 ]4.13.1Douglas Christopher Wilsonbefore adoption2ac2509
lines 156–169why, one step back156157 app.set('views', views);158159 app.use(function(req, res){160 res.render('user.tmpl', { user: { name: 'tobi' } });161 });162163 request(app)164 .get('/')165 .expect('<span>tobi</span>', done);166 })167168 it('should lookup in later paths until found', function(done){169 var app = createApp();tests: use path.join instead of concatenationchainhelenbefore adoptioneece385
lines 170–173why, one step back170 var views = [171 path.join(__dirname, 'fixtures', 'local_layout'),172 path.join(__dirname, 'fixtures', 'default_layout')173 ]4.13.1Douglas Christopher Wilsonbefore adoption2ac2509
lines 174–192why, one step back174175 app.set('views', views);176177 app.use(function(req, res){178 res.render('name.tmpl', { name: 'tobi' });179 });180181 request(app)182 .get('/')183 .expect('<p>tobi</p>', done);184 })185 })186 })187 })188189 describe('.render(name, option)', function(){190 it('should render the template', function(done){191 var app = createApp();192tests: use path.join instead of concatenationchainhelenbefore adoptioneece385
line 193why, one step back193 app.set('views', path.join(__dirname, 'fixtures'))4.13.1Douglas Christopher Wilsonbefore adoption2ac2509
lines 194–208why, one step back194195 var user = { name: 'tobi' };196197 app.use(function(req, res){198 res.render('user.tmpl', { user: user });199 });200201 request(app)202 .get('/')203 .expect('<p>tobi</p>', done);204 })205206 it('should expose app.locals', function(done){207 var app = createApp();208tests: use path.join instead of concatenationchainhelenbefore adoptioneece385
line 209why, one step back209 app.set('views', path.join(__dirname, 'fixtures'))4.13.1Douglas Christopher Wilsonbefore adoption2ac2509
lines 210–223why, one step back210 app.locals.user = { name: 'tobi' };211212 app.use(function(req, res){213 res.render('user.tmpl');214 });215216 request(app)217 .get('/')218 .expect('<p>tobi</p>', done);219 })220221 it('should expose res.locals', function(done){222 var app = createApp();223tests: use path.join instead of concatenationchainhelenbefore adoptioneece385
line 224why, one step back224 app.set('views', path.join(__dirname, 'fixtures'))4.13.1Douglas Christopher Wilsonbefore adoption2ac2509
lines 225–238why, one step back225226 app.use(function(req, res){227 res.locals.user = { name: 'tobi' };228 res.render('user.tmpl');229 });230231 request(app)232 .get('/')233 .expect('<p>tobi</p>', done);234 })235236 it('should give precedence to res.locals over app.locals', function(done){237 var app = createApp();238tests: use path.join instead of concatenationchainhelenbefore adoptioneece385
line 239why, one step back239 app.set('views', path.join(__dirname, 'fixtures'))4.13.1Douglas Christopher Wilsonbefore adoption2ac2509
lines 240–254why, one step back240 app.locals.user = { name: 'tobi' };241242 app.use(function(req, res){243 res.locals.user = { name: 'jane' };244 res.render('user.tmpl', {});245 });246247 request(app)248 .get('/')249 .expect('<p>jane</p>', done);250 })251252 it('should give precedence to res.render() locals over res.locals', function(done){253 var app = createApp();254tests: use path.join instead of concatenationchainhelenbefore adoptioneece385
line 255why, one step back255 app.set('views', path.join(__dirname, 'fixtures'))4.13.1Douglas Christopher Wilsonbefore adoption2ac2509
lines 256–270why, one step back256 var jane = { name: 'jane' };257258 app.use(function(req, res){259 res.locals.user = { name: 'tobi' };260 res.render('user.tmpl', { user: jane });261 });262263 request(app)264 .get('/')265 .expect('<p>jane</p>', done);266 })267268 it('should give precedence to res.render() locals over app.locals', function(done){269 var app = createApp();270tests: use path.join instead of concatenationchainhelenbefore adoptioneece385
line 271why, one step back271 app.set('views', path.join(__dirname, 'fixtures'))4.13.1Douglas Christopher Wilsonbefore adoption2ac2509
lines 272–288why, one step back272 app.locals.user = { name: 'tobi' };273 var jane = { name: 'jane' };274275 app.use(function(req, res){276 res.render('user.tmpl', { user: jane });277 });278279 request(app)280 .get('/')281 .expect('<p>jane</p>', done);282 })283 })284285 describe('.render(name, options, fn)', function(){286 it('should pass the resulting string', function(done){287 var app = createApp();288tests: use path.join instead of concatenationchainhelenbefore adoptioneece385
line 289why, one step back289 app.set('views', path.join(__dirname, 'fixtures'))4.13.1Douglas Christopher Wilsonbefore adoption2ac2509
lines 290–308why, one step back290291 app.use(function(req, res){292 var tobi = { name: 'tobi' };293 res.render('user.tmpl', { user: tobi }, function (err, html) {294 html = html.replace('tobi', 'loki');295 res.end(html);296 });297 });298299 request(app)300 .get('/')301 .expect('<p>loki</p>', done);302 })303 })304305 describe('.render(name, fn)', function(){306 it('should pass the resulting string', function(done){307 var app = createApp();308tests: use path.join instead of concatenationchainhelenbefore adoptioneece385
line 309why, one step back309 app.set('views', path.join(__dirname, 'fixtures'))4.13.1Douglas Christopher Wilsonbefore adoption2ac2509
lines 310–327why, one step back310311 app.use(function(req, res){312 res.locals.user = { name: 'tobi' };313 res.render('user.tmpl', function (err, html) {314 html = html.replace('tobi', 'loki');315 res.end(html);316 });317 });318319 request(app)320 .get('/')321 .expect('<p>loki</p>', done);322 })323324 describe('when an error occurs', function(){325 it('should pass it to the callback', function(done){326 var app = createApp();327tests: use path.join instead of concatenationchainhelenbefore adoptioneece385
line 328why, one step back328 app.set('views', path.join(__dirname, 'fixtures'))4.13.1Douglas Christopher Wilsonbefore adoption2ac2509
lines 329–350why, one step back329330 app.use(function(req, res){331 res.render('user.tmpl', function (err) {332 res.end(err.message);333 });334 });335336 request(app)337 .get('/')338 .expect(/Cannot read property '[^']+' of undefined/, done);339 })340 })341 })342})343344function createApp() {345 var app = express();346347 app.engine('.tmpl', tmpl);348349 return app;350}