Skip to content
Myr

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 file

Take it

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

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

line 1why, one step back
1

Merge tag '3.18.6'Douglas Christopher Wilsonbefore adoption4aa2801

lines 2–4why, one step back
2var express = require('..');
3var request = require('supertest');4var tmpl = require('./support/tmpl');

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 5–8why, one step back
5
6describe('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 back
9 var app = createApp();

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 10–13why, one step back
10
11 app.locals.user = { name: 'tobi' };1213 app.use(function(req, res){

Merge tag '3.18.6'Douglas Christopher Wilsonbefore adoption4aa2801

line 14why, one step back
14 res.render(__dirname + '/fixtures/user.tmpl');

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 15–22why, one step back
15 });
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 back
23 var app = createApp();

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 24–25why, one step back
24
25 app.locals.user = { name: 'tobi' };

Merge tag '3.18.6'Douglas Christopher Wilsonbefore adoption4aa2801

line 26why, one step back
26 app.set('view engine', 'tmpl');

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 27–36why, one step back
27
28 app.use(function(req, res){29 res.render(__dirname + '/fixtures/user');30 });3132 request(app)33 .get('/')34 .expect('<p>tobi</p>', done);35 })36

tests: add test for rendering extensionless file without view engineDouglas Christopher Wilsonbefore adoption0634e7e

lines 37–50why, one step back
37 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 })50

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

line 51why, one step back
51 it('should expose app.locals', function(done){

Merge tag '3.18.6'Douglas Christopher Wilsonbefore adoption4aa2801

line 52why, one step back
52 var app = createApp();

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 53–57why, one step back
53
54 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 back
58 res.render('user.tmpl');

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 59–66why, one step back
59 });
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 back
67 var app = createApp();

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 68–72why, one step back
68
69 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 back
73 res.render('name.tmpl');

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 74–81why, one step back
74 });
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 back
82 var app = createApp();

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 83–84why, one step back
83
84 app.set('views', __dirname + '/fixtures');

Merge tag '3.18.6'Douglas Christopher Wilsonbefore adoption4aa2801

line 85why, one step back
85 app.set('view engine', 'tmpl');

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 86–97why, one step back
86
87 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 back
98 var app = createApp();

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 99–102why, one step back
99
100 app.set('views', __dirname + '/fixtures');101102 app.use(function(req, res){

Merge tag '3.18.6'Douglas Christopher Wilsonbefore adoption4aa2801

line 103why, one step back
103 res.render('user.tmpl');

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 104–117why, one step back
104 });
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 back
118 var app = createApp();

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

line 119why, one step back
119

Merge tag '3.18.6'Douglas Christopher Wilsonbefore adoption4aa2801

line 120why, one step back
120 app.set('view engine', 'tmpl');

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 121–131why, one step back
121 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 back
132
133 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 back
135 var app = createApp();

Add support for app.set('views', array)Douglas Christopher Wilsonbefore adoption6614352

lines 136–139why, one step back
136
137 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 back
140 res.render('user.tmpl', { user: { name: 'tobi' } });

Add support for app.set('views', array)Douglas Christopher Wilsonbefore adoption6614352

lines 141–149why, one step back
141 });
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 back
150 var app = createApp();

Add support for app.set('views', array)Douglas Christopher Wilsonbefore adoption6614352

lines 151–155why, one step back
151 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 back
156 res.render('user.tmpl', { user: { name: 'tobi' } });

Add support for app.set('views', array)Douglas Christopher Wilsonbefore adoption6614352

lines 157–164why, one step back
157 });
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 back
165 var app = createApp();

Add support for app.set('views', array)Douglas Christopher Wilsonbefore adoption6614352

lines 166–170why, one step back
166 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 back
171 res.render('name.tmpl', { name: 'tobi' });

Add support for app.set('views', array)Douglas Christopher Wilsonbefore adoption6614352

lines 172–179why, one step back
172 });
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 back
180 })
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 back
184 var app = createApp();

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 185–190why, one step back
185
186 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 back
191 res.render('user.tmpl', { user: user });

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 192–199why, one step back
192 });
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 back
200 var app = createApp();

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 201–205why, one step back
201
202 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 back
206 res.render('user.tmpl');

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 207–214why, one step back
207 });
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 back
215 var app = createApp();

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 216–220why, one step back
216
217 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 back
221 res.render('user.tmpl');

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 222–229why, one step back
222 });
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 back
230 var app = createApp();

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 231–236why, one step back
231
232 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 back
237 res.render('user.tmpl', {});

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 238–245why, one step back
238 });
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 back
246 var app = createApp();

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 247–252why, one step back
247
248 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 back
253 res.render('user.tmpl', { user: jane });

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 254–261why, one step back
254 });
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 back
262 var app = createApp();

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 263–268why, one step back
263
264 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 back
269 res.render('user.tmpl', { user: jane });

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 270–279why, one step back
270 });
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 back
280 var app = createApp();

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 281–285why, one step back
281
282 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 back
286 res.render('user.tmpl', { user: tobi }, function (err, html) {

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 287–299why, one step back
287 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 back
300 var app = createApp();

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 301–305why, one step back
301
302 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 back
306 res.render('user.tmpl', function (err, html) {

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 307–318why, one step back
307 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 back
319 var app = createApp();

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 320–323why, one step back
320
321 app.set('views', __dirname + '/fixtures');322323 app.use(function(req, res){

Merge tag '3.18.6'Douglas Christopher Wilsonbefore adoption4aa2801

line 324why, one step back
324 res.render('user.tmpl', function (err) {

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 325–335why, one step back
325 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 back
336
337function createApp() {338 var app = express();339340 app.engine('.tmpl', tmpl);341342 return app;343}