Skip to content
Myr

res.render.js

This file

Path

test/res.render.js

366 lines · 8.9 KiB · JavaScript

Last changed by

Improve error message when autoloading invalid view engineDouglas Christopher Wilsonbefore adoption80f1ea9

History of this file

Take it

The walk stopped after 200 commits: lines older than dd2b897 point at it.

examples: comment the usage of process.nextTickMuhammad Saqibbefore adoptiondd2b897

lines 1–2why, one step back
1
2var express = require('..');

tests: use path.join instead of concatenationchainhelenbefore adoptioneece385

line 3why, one step back
3var path = require('path')

examples: comment the usage of process.nextTickMuhammad Saqibbefore adoptiondd2b897

lines 4–14why, one step back
4var 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 back
15 res.render(path.join(__dirname, 'fixtures', 'user.tmpl'))

examples: comment the usage of process.nextTickMuhammad Saqibbefore adoptiondd2b897

lines 16–29why, one step back
16 });
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 back
30 res.render(path.join(__dirname, 'fixtures', 'user'))

examples: comment the usage of process.nextTickMuhammad Saqibbefore adoptiondd2b897

lines 31–37why, one step back
31 });
3233 request(app)34 .get('/')35 .expect('<p>tobi</p>', done);36 })37

Improve error message when autoloading invalid view engineDouglas Christopher Wilsonbefore adoption80f1ea9

lines 38–51why, one step back
38 it('should error without "view engine" set and file extension to a non-engine module', function (done) {
39 var app = createApp()4041 app.locals.user = { name: 'tobi' }4243 app.use(function (req, res) {44 res.render(path.join(__dirname, 'fixtures', 'broken.send'))45 })4647 request(app)48 .get('/')49 .expect(500, /does not provide a view engine/, done)50 })51

examples: comment the usage of process.nextTickMuhammad Saqibbefore adoptiondd2b897

lines 52–57why, one step back
52 it('should error without "view engine" set and no file extension', function (done) {
53 var app = createApp();5455 app.locals.user = { name: 'tobi' };5657 app.use(function(req, res){

tests: use path.join instead of concatenationchainhelenbefore adoptioneece385

line 58why, one step back
58 res.render(path.join(__dirname, 'fixtures', 'user'))

examples: comment the usage of process.nextTickMuhammad Saqibbefore adoptiondd2b897

lines 59–68why, one step back
59 });
6061 request(app)62 .get('/')63 .expect(500, /No default engine was specified/, done);64 })6566 it('should expose app.locals', function(done){67 var app = createApp();68

tests: use path.join instead of concatenationchainhelenbefore adoptioneece385

line 69why, one step back
69 app.set('views', path.join(__dirname, 'fixtures'))

examples: comment the usage of process.nextTickMuhammad Saqibbefore adoptiondd2b897

lines 70–83why, one step back
70 app.locals.user = { name: 'tobi' };
7172 app.use(function(req, res){73 res.render('user.tmpl');74 });7576 request(app)77 .get('/')78 .expect('<p>tobi</p>', done);79 })8081 it('should expose app.locals with `name` property', function(done){82 var app = createApp();83

tests: use path.join instead of concatenationchainhelenbefore adoptioneece385

line 84why, one step back
84 app.set('views', path.join(__dirname, 'fixtures'))

examples: comment the usage of process.nextTickMuhammad Saqibbefore adoptiondd2b897

lines 85–98why, one step back
85 app.locals.name = 'tobi';
8687 app.use(function(req, res){88 res.render('name.tmpl');89 });9091 request(app)92 .get('/')93 .expect('<p>tobi</p>', done);94 })9596 it('should support index.<engine>', function(done){97 var app = createApp();98

tests: use path.join instead of concatenationchainhelenbefore adoptioneece385

line 99why, one step back
99 app.set('views', path.join(__dirname, 'fixtures'))

examples: comment the usage of process.nextTickMuhammad Saqibbefore adoptiondd2b897

lines 100–114why, one step back
100 app.set('view engine', 'tmpl');
101102 app.use(function(req, res){103 res.render('blog/post');104 });105106 request(app)107 .get('/')108 .expect('<h1>blog post</h1>', done);109 })110111 describe('when an error occurs', function(){112 it('should next(err)', function(done){113 var app = createApp();114

tests: use path.join instead of concatenationchainhelenbefore adoptioneece385

line 115why, one step back
115 app.set('views', path.join(__dirname, 'fixtures'))

examples: comment the usage of process.nextTickMuhammad Saqibbefore adoptiondd2b897

lines 116–121why, one step back
116
117 app.use(function(req, res){118 res.render('user.tmpl');119 });120121 app.use(function(err, req, res, next){

tests: check render error without engine-specific messageKunal Pathakbefore adoption19a2eeb

line 122why, one step back
122 res.status(500).send('got error: ' + err.name)

examples: comment the usage of process.nextTickMuhammad Saqibbefore adoptiondd2b897

lines 123–126why, one step back
123 });
124125 request(app)126 .get('/')

tests: check render error without engine-specific messageKunal Pathakbefore adoption19a2eeb

line 127why, one step back
127 .expect(500, 'got error: RenderError', done)

examples: comment the usage of process.nextTickMuhammad Saqibbefore adoptiondd2b897

lines 128–135why, one step back
128 })
129 })130131 describe('when "view engine" is given', function(){132 it('should render the template', function(done){133 var app = createApp();134135 app.set('view engine', 'tmpl');

tests: use path.join instead of concatenationchainhelenbefore adoptioneece385

line 136why, one step back
136 app.set('views', path.join(__dirname, 'fixtures'))

examples: comment the usage of process.nextTickMuhammad Saqibbefore adoptiondd2b897

lines 137–151why, one step back
137
138 app.use(function(req, res){139 res.render('email');140 });141142 request(app)143 .get('/')144 .expect('<p>This is an email</p>', done);145 })146 })147148 describe('when "views" is given', function(){149 it('should lookup the file in the path', function(done){150 var app = createApp();151

tests: use path.join instead of concatenationchainhelenbefore adoptioneece385

line 152why, one step back
152 app.set('views', path.join(__dirname, 'fixtures', 'default_layout'))

examples: comment the usage of process.nextTickMuhammad Saqibbefore adoptiondd2b897

lines 153–165why, one step back
153
154 app.use(function(req, res){155 res.render('user.tmpl', { user: { name: 'tobi' } });156 });157158 request(app)159 .get('/')160 .expect('<p>tobi</p>', done);161 })162163 describe('when array of paths', function(){164 it('should lookup the file in the path', function(done){165 var app = createApp();

tests: use path.join instead of concatenationchainhelenbefore adoptioneece385

lines 166–169why, one step back
166 var views = [
167 path.join(__dirname, 'fixtures', 'local_layout'),168 path.join(__dirname, 'fixtures', 'default_layout')169 ]

examples: comment the usage of process.nextTickMuhammad Saqibbefore adoptiondd2b897

lines 170–183why, one step back
170
171 app.set('views', views);172173 app.use(function(req, res){174 res.render('user.tmpl', { user: { name: 'tobi' } });175 });176177 request(app)178 .get('/')179 .expect('<span>tobi</span>', done);180 })181182 it('should lookup in later paths until found', function(done){183 var app = createApp();

tests: use path.join instead of concatenationchainhelenbefore adoptioneece385

lines 184–187why, one step back
184 var views = [
185 path.join(__dirname, 'fixtures', 'local_layout'),186 path.join(__dirname, 'fixtures', 'default_layout')187 ]

examples: comment the usage of process.nextTickMuhammad Saqibbefore adoptiondd2b897

lines 188–206why, one step back
188
189 app.set('views', views);190191 app.use(function(req, res){192 res.render('name.tmpl', { name: 'tobi' });193 });194195 request(app)196 .get('/')197 .expect('<p>tobi</p>', done);198 })199 })200 })201 })202203 describe('.render(name, option)', function(){204 it('should render the template', function(done){205 var app = createApp();206

tests: use path.join instead of concatenationchainhelenbefore adoptioneece385

line 207why, one step back
207 app.set('views', path.join(__dirname, 'fixtures'))

examples: comment the usage of process.nextTickMuhammad Saqibbefore adoptiondd2b897

lines 208–222why, one step back
208
209 var user = { name: 'tobi' };210211 app.use(function(req, res){212 res.render('user.tmpl', { user: user });213 });214215 request(app)216 .get('/')217 .expect('<p>tobi</p>', done);218 })219220 it('should expose app.locals', function(done){221 var app = createApp();222

tests: use path.join instead of concatenationchainhelenbefore adoptioneece385

line 223why, one step back
223 app.set('views', path.join(__dirname, 'fixtures'))

examples: comment the usage of process.nextTickMuhammad Saqibbefore adoptiondd2b897

lines 224–237why, one step back
224 app.locals.user = { name: 'tobi' };
225226 app.use(function(req, res){227 res.render('user.tmpl');228 });229230 request(app)231 .get('/')232 .expect('<p>tobi</p>', done);233 })234235 it('should expose res.locals', function(done){236 var app = createApp();237

tests: use path.join instead of concatenationchainhelenbefore adoptioneece385

line 238why, one step back
238 app.set('views', path.join(__dirname, 'fixtures'))

examples: comment the usage of process.nextTickMuhammad Saqibbefore adoptiondd2b897

lines 239–252why, one step back
239
240 app.use(function(req, res){241 res.locals.user = { name: 'tobi' };242 res.render('user.tmpl');243 });244245 request(app)246 .get('/')247 .expect('<p>tobi</p>', done);248 })249250 it('should give precedence to res.locals over app.locals', function(done){251 var app = createApp();252

tests: use path.join instead of concatenationchainhelenbefore adoptioneece385

line 253why, one step back
253 app.set('views', path.join(__dirname, 'fixtures'))

examples: comment the usage of process.nextTickMuhammad Saqibbefore adoptiondd2b897

lines 254–268why, one step back
254 app.locals.user = { name: 'tobi' };
255256 app.use(function(req, res){257 res.locals.user = { name: 'jane' };258 res.render('user.tmpl', {});259 });260261 request(app)262 .get('/')263 .expect('<p>jane</p>', done);264 })265266 it('should give precedence to res.render() locals over res.locals', function(done){267 var app = createApp();268

tests: use path.join instead of concatenationchainhelenbefore adoptioneece385

line 269why, one step back
269 app.set('views', path.join(__dirname, 'fixtures'))

examples: comment the usage of process.nextTickMuhammad Saqibbefore adoptiondd2b897

lines 270–284why, one step back
270 var jane = { name: 'jane' };
271272 app.use(function(req, res){273 res.locals.user = { name: 'tobi' };274 res.render('user.tmpl', { user: jane });275 });276277 request(app)278 .get('/')279 .expect('<p>jane</p>', done);280 })281282 it('should give precedence to res.render() locals over app.locals', function(done){283 var app = createApp();284

tests: use path.join instead of concatenationchainhelenbefore adoptioneece385

line 285why, one step back
285 app.set('views', path.join(__dirname, 'fixtures'))

examples: comment the usage of process.nextTickMuhammad Saqibbefore adoptiondd2b897

lines 286–302why, one step back
286 app.locals.user = { name: 'tobi' };
287 var jane = { name: 'jane' };288289 app.use(function(req, res){290 res.render('user.tmpl', { user: jane });291 });292293 request(app)294 .get('/')295 .expect('<p>jane</p>', done);296 })297 })298299 describe('.render(name, options, fn)', function(){300 it('should pass the resulting string', function(done){301 var app = createApp();302

tests: use path.join instead of concatenationchainhelenbefore adoptioneece385

line 303why, one step back
303 app.set('views', path.join(__dirname, 'fixtures'))

examples: comment the usage of process.nextTickMuhammad Saqibbefore adoptiondd2b897

lines 304–322why, one step back
304
305 app.use(function(req, res){306 var tobi = { name: 'tobi' };307 res.render('user.tmpl', { user: tobi }, function (err, html) {308 html = html.replace('tobi', 'loki');309 res.end(html);310 });311 });312313 request(app)314 .get('/')315 .expect('<p>loki</p>', done);316 })317 })318319 describe('.render(name, fn)', function(){320 it('should pass the resulting string', function(done){321 var app = createApp();322

tests: use path.join instead of concatenationchainhelenbefore adoptioneece385

line 323why, one step back
323 app.set('views', path.join(__dirname, 'fixtures'))

examples: comment the usage of process.nextTickMuhammad Saqibbefore adoptiondd2b897

lines 324–341why, one step back
324
325 app.use(function(req, res){326 res.locals.user = { name: 'tobi' };327 res.render('user.tmpl', function (err, html) {328 html = html.replace('tobi', 'loki');329 res.end(html);330 });331 });332333 request(app)334 .get('/')335 .expect('<p>loki</p>', done);336 })337338 describe('when an error occurs', function(){339 it('should pass it to the callback', function(done){340 var app = createApp();341

tests: use path.join instead of concatenationchainhelenbefore adoptioneece385

line 342why, one step back
342 app.set('views', path.join(__dirname, 'fixtures'))

examples: comment the usage of process.nextTickMuhammad Saqibbefore adoptiondd2b897

lines 343–345why, one step back
343
344 app.use(function(req, res){345 res.render('user.tmpl', function (err) {

tests: check render error without engine-specific messageKunal Pathakbefore adoption19a2eeb

lines 346–348why, one step back
346 if (err) {
347 res.status(500).send('got error: ' + err.name)348 }

examples: comment the usage of process.nextTickMuhammad Saqibbefore adoptiondd2b897

lines 349–353why, one step back
349 });
350 });351352 request(app)353 .get('/')

tests: check render error without engine-specific messageKunal Pathakbefore adoption19a2eeb

line 354why, one step back
354 .expect(500, 'got error: RenderError', done)

examples: comment the usage of process.nextTickMuhammad Saqibbefore adoptiondd2b897

lines 355–366why, one step back
355 })
356 })357 })358})359360function createApp() {361 var app = express();362363 app.engine('.tmpl', tmpl);364365 return app;366}