Skip to content
Myr

res.render.js

This file

Path

test/res.render.js

367 lines · 8.9 KiB · JavaScript

Last changed by

fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359

History of this file

Take it

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

Merge tag '4.17.3'Douglas Christopher Wilsonbefore adoption318fd4b

line 1why, one step back
1'use strict'

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

line 2why, one step back
2

Merge tag '4.11.1'Douglas Christopher Wilsonbefore adoption8a5ecd3

line 3why, one step back
3var express = require('..');

fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359

line 4why, one step back
4var path = require('node:path')

Merge tag '4.11.1'Douglas Christopher Wilsonbefore adoption8a5ecd3

lines 5–6why, one step back
5var request = require('supertest');
6var tmpl = require('./support/tmpl');

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

lines 7–10why, one step back
7
8describe('res', function(){9 describe('.render(name)', function(){10 it('should support absolute paths', function(done){

Merge tag '4.11.1'Douglas Christopher Wilsonbefore adoption8a5ecd3

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

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

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

Merge tag '4.15.2'Douglas Christopher Wilsonbefore adoptione5dbb0c

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

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

lines 17–24why, one step back
17 });
1819 request(app)20 .get('/')21 .expect('<p>tobi</p>', done);22 })2324 it('should support absolute paths with "view engine"', function(done){

Merge tag '4.11.1'Douglas Christopher Wilsonbefore adoption8a5ecd3

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

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

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

Merge tag '4.11.1'Douglas Christopher Wilsonbefore adoption8a5ecd3

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

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

lines 29–30why, one step back
29
30 app.use(function(req, res){

Merge tag '4.15.2'Douglas Christopher Wilsonbefore adoptione5dbb0c

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

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

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

Merge tag '4.16.2'Douglas Christopher Wilsonbefore adoption62e12fe

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

Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87

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

Merge tag '4.15.2'Douglas Christopher Wilsonbefore adoptione5dbb0c

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

Merge tag '4.13.1'Douglas Christopher Wilsonbefore adoptionb309b87

lines 60–66why, one step back
60 });
6162 request(app)63 .get('/')64 .expect(500, /No default engine was specified/, done);65 })66

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

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

Merge tag '4.11.1'Douglas Christopher Wilsonbefore adoption8a5ecd3

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

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

line 69why, one step back
69

Merge tag '4.15.2'Douglas Christopher Wilsonbefore adoptione5dbb0c

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

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

lines 71–73why, one step back
71 app.locals.user = { name: 'tobi' };
7273 app.use(function(req, res){

Merge tag '4.11.1'Douglas Christopher Wilsonbefore adoption8a5ecd3

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

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

lines 75–82why, one step back
75 });
7677 request(app)78 .get('/')79 .expect('<p>tobi</p>', done);80 })8182 it('should expose app.locals with `name` property', function(done){

Merge tag '4.11.1'Douglas Christopher Wilsonbefore adoption8a5ecd3

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

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

line 84why, one step back
84

Merge tag '4.15.2'Douglas Christopher Wilsonbefore adoptione5dbb0c

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

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

lines 86–88why, one step back
86 app.locals.name = 'tobi';
8788 app.use(function(req, res){

Merge tag '4.11.1'Douglas Christopher Wilsonbefore adoption8a5ecd3

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

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

lines 90–97why, one step back
90 });
9192 request(app)93 .get('/')94 .expect('<p>tobi</p>', done);95 })9697 it('should support index.<engine>', function(done){

Merge tag '4.11.1'Douglas Christopher Wilsonbefore adoption8a5ecd3

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

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

line 99why, one step back
99

Merge tag '4.15.2'Douglas Christopher Wilsonbefore adoptione5dbb0c

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

Merge tag '4.11.1'Douglas Christopher Wilsonbefore adoption8a5ecd3

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

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

lines 102–113why, one step back
102
103 app.use(function(req, res){104 res.render('blog/post');105 });106107 request(app)108 .get('/')109 .expect('<h1>blog post</h1>', done);110 })111112 describe('when an error occurs', function(){113 it('should next(err)', function(done){

Merge tag '4.11.1'Douglas Christopher Wilsonbefore adoption8a5ecd3

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

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

line 115why, one step back
115

Merge tag '4.15.2'Douglas Christopher Wilsonbefore adoptione5dbb0c

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

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

lines 117–118why, one step back
117
118 app.use(function(req, res){

Merge tag '4.11.1'Douglas Christopher Wilsonbefore adoption8a5ecd3

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

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

lines 120–122why, one step back
120 });
121122 app.use(function(err, req, res, next){

Merge tag '4.15.5'Douglas Christopher Wilsonbefore adoption19c8d64

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

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

lines 124–127why, one step back
124 });
125126 request(app)127 .get('/')

Merge tag '4.15.5'Douglas Christopher Wilsonbefore adoption19c8d64

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

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

lines 129–133why, one step back
129 })
130 })131132 describe('when "view engine" is given', function(){133 it('should render the template', function(done){

Merge tag '4.11.1'Douglas Christopher Wilsonbefore adoption8a5ecd3

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

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

line 135why, one step back
135

Merge tag '4.11.1'Douglas Christopher Wilsonbefore adoption8a5ecd3

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

Merge tag '4.15.2'Douglas Christopher Wilsonbefore adoptione5dbb0c

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

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

lines 138–147why, one step back
138
139 app.use(function(req, res){140 res.render('email');141 });142143 request(app)144 .get('/')145 .expect('<p>This is an email</p>', done);146 })147 })

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

lines 148–150why, one step back
148
149 describe('when "views" is given', function(){150 it('should lookup the file in the path', function(done){

Merge tag '4.11.1'Douglas Christopher Wilsonbefore adoption8a5ecd3

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

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

line 152why, one step back
152

Merge tag '4.15.2'Douglas Christopher Wilsonbefore adoptione5dbb0c

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

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

lines 154–155why, one step back
154
155 app.use(function(req, res){

Merge tag '4.11.1'Douglas Christopher Wilsonbefore adoption8a5ecd3

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–165why, one step back
157 });
158159 request(app)160 .get('/')161 .expect('<p>tobi</p>', done);162 })163164 describe('when array of paths', function(){165 it('should lookup the file in the path', function(done){

Merge tag '4.11.1'Douglas Christopher Wilsonbefore adoption8a5ecd3

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

Merge tag '4.15.2'Douglas Christopher Wilsonbefore adoptione5dbb0c

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

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

lines 171–174why, one step back
171
172 app.set('views', views);173174 app.use(function(req, res){

Merge tag '4.11.1'Douglas Christopher Wilsonbefore adoption8a5ecd3

line 175why, one step back
175 res.render('user.tmpl', { user: { name: 'tobi' } });

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

lines 176–183why, one step back
176 });
177178 request(app)179 .get('/')180 .expect('<span>tobi</span>', done);181 })182183 it('should lookup in later paths until found', function(done){

Merge tag '4.11.1'Douglas Christopher Wilsonbefore adoption8a5ecd3

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

Merge tag '4.15.2'Douglas Christopher Wilsonbefore adoptione5dbb0c

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

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

lines 189–192why, one step back
189
190 app.set('views', views);191192 app.use(function(req, res){

Merge tag '4.11.1'Douglas Christopher Wilsonbefore adoption8a5ecd3

line 193why, one step back
193 res.render('name.tmpl', { name: 'tobi' });

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

lines 194–201why, one step back
194 });
195196 request(app)197 .get('/')198 .expect('<p>tobi</p>', done);199 })200 })201 })

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

lines 202–205why, one step back
202 })
203204 describe('.render(name, option)', function(){205 it('should render the template', function(done){

Merge tag '4.11.1'Douglas Christopher Wilsonbefore adoption8a5ecd3

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

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

line 207why, one step back
207

Merge tag '4.15.2'Douglas Christopher Wilsonbefore adoptione5dbb0c

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

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

lines 209–212why, one step back
209
210 var user = { name: 'tobi' };211212 app.use(function(req, res){

Merge tag '4.11.1'Douglas Christopher Wilsonbefore adoption8a5ecd3

line 213why, one step back
213 res.render('user.tmpl', { user: user });

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

lines 214–221why, one step back
214 });
215216 request(app)217 .get('/')218 .expect('<p>tobi</p>', done);219 })220221 it('should expose app.locals', function(done){

Merge tag '4.11.1'Douglas Christopher Wilsonbefore adoption8a5ecd3

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

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

line 223why, one step back
223

Merge tag '4.15.2'Douglas Christopher Wilsonbefore adoptione5dbb0c

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

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

lines 225–227why, one step back
225 app.locals.user = { name: 'tobi' };
226227 app.use(function(req, res){

Merge tag '4.11.1'Douglas Christopher Wilsonbefore adoption8a5ecd3

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

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

lines 229–236why, one step back
229 });
230231 request(app)232 .get('/')233 .expect('<p>tobi</p>', done);234 })235236 it('should expose res.locals', function(done){

Merge tag '4.11.1'Douglas Christopher Wilsonbefore adoption8a5ecd3

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

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

line 238why, one step back
238

Merge tag '4.15.2'Douglas Christopher Wilsonbefore adoptione5dbb0c

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

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

lines 240–242why, one step back
240
241 app.use(function(req, res){242 res.locals.user = { name: 'tobi' };

Merge tag '4.11.1'Douglas Christopher Wilsonbefore adoption8a5ecd3

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

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

lines 244–251why, one step back
244 });
245246 request(app)247 .get('/')248 .expect('<p>tobi</p>', done);249 })250251 it('should give precedence to res.locals over app.locals', function(done){

Merge tag '4.11.1'Douglas Christopher Wilsonbefore adoption8a5ecd3

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

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

line 253why, one step back
253

Merge tag '4.15.2'Douglas Christopher Wilsonbefore adoptione5dbb0c

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

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

lines 255–258why, one step back
255 app.locals.user = { name: 'tobi' };
256257 app.use(function(req, res){258 res.locals.user = { name: 'jane' };

Merge tag '4.11.1'Douglas Christopher Wilsonbefore adoption8a5ecd3

line 259why, one step back
259 res.render('user.tmpl', {});

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

lines 260–267why, one step back
260 });
261262 request(app)263 .get('/')264 .expect('<p>jane</p>', done);265 })266267 it('should give precedence to res.render() locals over res.locals', function(done){

Merge tag '4.11.1'Douglas Christopher Wilsonbefore adoption8a5ecd3

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

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

line 269why, one step back
269

Merge tag '4.15.2'Douglas Christopher Wilsonbefore adoptione5dbb0c

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

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

lines 271–274why, one step back
271 var jane = { name: 'jane' };
272273 app.use(function(req, res){274 res.locals.user = { name: 'tobi' };

Merge tag '4.11.1'Douglas Christopher Wilsonbefore adoption8a5ecd3

line 275why, one step back
275 res.render('user.tmpl', { user: jane });

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

lines 276–283why, one step back
276 });
277278 request(app)279 .get('/')280 .expect('<p>jane</p>', done);281 })282283 it('should give precedence to res.render() locals over app.locals', function(done){

Merge tag '4.11.1'Douglas Christopher Wilsonbefore adoption8a5ecd3

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

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

line 285why, one step back
285

Merge tag '4.15.2'Douglas Christopher Wilsonbefore adoptione5dbb0c

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

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

lines 287–290why, one step back
287 app.locals.user = { name: 'tobi' };
288 var jane = { name: 'jane' };289290 app.use(function(req, res){

Merge tag '4.11.1'Douglas Christopher Wilsonbefore adoption8a5ecd3

line 291why, one step back
291 res.render('user.tmpl', { user: jane });

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

lines 292–301why, one step back
292 });
293294 request(app)295 .get('/')296 .expect('<p>jane</p>', done);297 })298 })299300 describe('.render(name, options, fn)', function(){301 it('should pass the resulting string', function(done){

Merge tag '4.11.1'Douglas Christopher Wilsonbefore adoption8a5ecd3

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

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

line 303why, one step back
303

Merge tag '4.15.2'Douglas Christopher Wilsonbefore adoptione5dbb0c

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

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

lines 305–307why, one step back
305
306 app.use(function(req, res){307 var tobi = { name: 'tobi' };

Merge tag '4.11.1'Douglas Christopher Wilsonbefore adoption8a5ecd3

line 308why, one step back
308 res.render('user.tmpl', { user: tobi }, function (err, html) {

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

lines 309–321why, one step back
309 html = html.replace('tobi', 'loki');
310 res.end(html);311 });312 });313314 request(app)315 .get('/')316 .expect('<p>loki</p>', done);317 })318 })319320 describe('.render(name, fn)', function(){321 it('should pass the resulting string', function(done){

Merge tag '4.11.1'Douglas Christopher Wilsonbefore adoption8a5ecd3

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

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

line 323why, one step back
323

Merge tag '4.15.2'Douglas Christopher Wilsonbefore adoptione5dbb0c

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

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

lines 325–327why, one step back
325
326 app.use(function(req, res){327 res.locals.user = { name: 'tobi' };

Merge tag '4.11.1'Douglas Christopher Wilsonbefore adoption8a5ecd3

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

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

lines 329–340why, one step back
329 html = html.replace('tobi', 'loki');
330 res.end(html);331 });332 });333334 request(app)335 .get('/')336 .expect('<p>loki</p>', done);337 })338339 describe('when an error occurs', function(){340 it('should pass it to the callback', function(done){

Merge tag '4.11.1'Douglas Christopher Wilsonbefore adoption8a5ecd3

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

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

line 342why, one step back
342

Merge tag '4.15.2'Douglas Christopher Wilsonbefore adoptione5dbb0c

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

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

lines 344–345why, one step back
344
345 app.use(function(req, res){

Merge tag '4.11.1'Douglas Christopher Wilsonbefore adoption8a5ecd3

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

Merge tag '4.15.5'Douglas Christopher Wilsonbefore adoption19c8d64

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

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

lines 350–354why, one step back
350 });
351 });352353 request(app)354 .get('/')

Merge tag '4.15.5'Douglas Christopher Wilsonbefore adoption19c8d64

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

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

lines 356–359why, one step back
356 })
357 })358 })359})

Merge tag '4.11.1'Douglas Christopher Wilsonbefore adoption8a5ecd3

lines 360–367why, one step back
360
361function createApp() {362 var app = express();363364 app.engine('.tmpl', tmpl);365366 return app;367}