Skip to content
Myr

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 file

Take 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 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');

deps: qs@1.2.2Douglas Christopher Wilsonbefore adoptionad3ca25

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();

deps: qs@1.2.2Douglas Christopher Wilsonbefore adoptionad3ca25

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');

deps: qs@1.2.2Douglas Christopher Wilsonbefore adoptionad3ca25

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();

deps: qs@1.2.2Douglas Christopher Wilsonbefore adoptionad3ca25

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');

deps: qs@1.2.2Douglas Christopher Wilsonbefore adoptionad3ca25

lines 27–37why, 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 })3637 it('should expose app.locals', function(done){

Merge tag '3.18.6'Douglas Christopher Wilsonbefore adoption4aa2801

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

deps: qs@1.2.2Douglas Christopher Wilsonbefore adoptionad3ca25

lines 39–43why, one step back
39
40 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 back
44 res.render('user.tmpl');

deps: qs@1.2.2Douglas Christopher Wilsonbefore adoptionad3ca25

lines 45–52why, one step back
45 });
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 back
53 var app = createApp();

deps: qs@1.2.2Douglas Christopher Wilsonbefore adoptionad3ca25

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

deps: qs@1.2.2Douglas Christopher Wilsonbefore adoptionad3ca25

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

deps: qs@1.2.2Douglas Christopher Wilsonbefore adoptionad3ca25

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

Merge tag '3.18.6'Douglas Christopher Wilsonbefore adoption4aa2801

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

deps: qs@1.2.2Douglas Christopher Wilsonbefore adoptionad3ca25

lines 72–83why, one step back
72
73 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 back
84 var app = createApp();

deps: qs@1.2.2Douglas Christopher Wilsonbefore adoptionad3ca25

lines 85–88why, one step back
85
86 app.set('views', __dirname + '/fixtures');8788 app.use(function(req, res){

Merge tag '3.18.6'Douglas Christopher Wilsonbefore adoption4aa2801

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

deps: qs@1.2.2Douglas Christopher Wilsonbefore adoptionad3ca25

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

deps: qs@1.2.2Douglas Christopher Wilsonbefore adoptionad3ca25

line 105why, one step back
105

Merge tag '3.18.6'Douglas Christopher Wilsonbefore adoption4aa2801

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

deps: qs@1.2.2Douglas Christopher Wilsonbefore adoptionad3ca25

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

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

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

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

lines 127–135why, one step back
127 });
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 back
136 var app = createApp();

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

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

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

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

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

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

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

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

deps: qs@1.2.2Douglas Christopher Wilsonbefore adoptionad3ca25

lines 171–176why, one step back
171
172 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 back
177 res.render('user.tmpl', { user: user });

deps: qs@1.2.2Douglas Christopher Wilsonbefore adoptionad3ca25

lines 178–185why, one step back
178 });
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 back
186 var app = createApp();

deps: qs@1.2.2Douglas Christopher Wilsonbefore adoptionad3ca25

lines 187–191why, one step back
187
188 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 back
192 res.render('user.tmpl');

deps: qs@1.2.2Douglas Christopher Wilsonbefore adoptionad3ca25

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

deps: qs@1.2.2Douglas Christopher Wilsonbefore adoptionad3ca25

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

deps: qs@1.2.2Douglas Christopher Wilsonbefore adoptionad3ca25

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

deps: qs@1.2.2Douglas Christopher Wilsonbefore adoptionad3ca25

lines 217–222why, one step back
217
218 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 back
223 res.render('user.tmpl', {});

deps: qs@1.2.2Douglas Christopher Wilsonbefore adoptionad3ca25

lines 224–231why, one step back
224 });
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 back
232 var app = createApp();

deps: qs@1.2.2Douglas Christopher Wilsonbefore adoptionad3ca25

lines 233–238why, one step back
233
234 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 back
239 res.render('user.tmpl', { user: jane });

deps: qs@1.2.2Douglas Christopher Wilsonbefore adoptionad3ca25

lines 240–247why, one step back
240 });
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 back
248 var app = createApp();

deps: qs@1.2.2Douglas Christopher Wilsonbefore adoptionad3ca25

lines 249–254why, one step back
249
250 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 back
255 res.render('user.tmpl', { user: jane });

deps: qs@1.2.2Douglas Christopher Wilsonbefore adoptionad3ca25

lines 256–265why, one step back
256 });
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 back
266 var app = createApp();

deps: qs@1.2.2Douglas Christopher Wilsonbefore adoptionad3ca25

lines 267–271why, one step back
267
268 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 back
272 res.render('user.tmpl', { user: tobi }, function (err, html) {

deps: qs@1.2.2Douglas Christopher Wilsonbefore adoptionad3ca25

lines 273–285why, one step back
273 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 back
286 var app = createApp();

deps: qs@1.2.2Douglas Christopher Wilsonbefore adoptionad3ca25

lines 287–291why, one step back
287
288 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 back
292 res.render('user.tmpl', function (err, html) {

deps: qs@1.2.2Douglas Christopher Wilsonbefore adoptionad3ca25

lines 293–304why, one step back
293 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 back
305 var app = createApp();

deps: qs@1.2.2Douglas Christopher Wilsonbefore adoptionad3ca25

lines 306–309why, one step back
306
307 app.set('views', __dirname + '/fixtures');308309 app.use(function(req, res){

Merge tag '3.18.6'Douglas Christopher Wilsonbefore adoption4aa2801

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

deps: qs@1.2.2Douglas Christopher Wilsonbefore adoptionad3ca25

lines 311–321why, one step back
311 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 back
322
323function createApp() {324 var app = express();325326 app.engine('.tmpl', tmpl);327328 return app;329}