Skip to content
Myr

res.render.js

This file

Path

test/res.render.js

266 lines · 6.1 KiB · JavaScript

Last changed by

tests: run render tests with internal template engineDouglas Christopher Wilsonbefore adoption9182451

History of this file

Take it

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

Fix req.protocol for proxy-direct connectionsAshley Strebbefore adoptiona28b7a8

line 1why, one step back
1

tests: run render tests with internal template engineDouglas Christopher Wilsonbefore adoption9182451

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

Fix req.protocol for proxy-direct connectionsAshley Strebbefore adoptiona28b7a8

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

tests: run render tests with internal template engineDouglas Christopher Wilsonbefore adoption9182451

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

Fix req.protocol for proxy-direct connectionsAshley Strebbefore adoptiona28b7a8

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

tests: run render tests with internal template engineDouglas Christopher Wilsonbefore adoption9182451

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

Fix req.protocol for proxy-direct connectionsAshley Strebbefore adoptiona28b7a8

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){

tests: run render tests with internal template engineDouglas Christopher Wilsonbefore adoption9182451

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

Fix req.protocol for proxy-direct connectionsAshley Strebbefore adoptiona28b7a8

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

tests: run render tests with internal template engineDouglas Christopher Wilsonbefore adoption9182451

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

Fix req.protocol for proxy-direct connectionsAshley Strebbefore adoptiona28b7a8

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){

tests: run render tests with internal template engineDouglas Christopher Wilsonbefore adoption9182451

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

Fix req.protocol for proxy-direct connectionsAshley Strebbefore adoptiona28b7a8

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){

tests: run render tests with internal template engineDouglas Christopher Wilsonbefore adoption9182451

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

Fix req.protocol for proxy-direct connectionsAshley Strebbefore adoptiona28b7a8

lines 45–52why, one step back
45 });
4647 request(app)48 .get('/')49 .expect('<p>tobi</p>', done);50 })51 52 it('should support index.<engine>', function(done){

tests: run render tests with internal template engineDouglas Christopher Wilsonbefore adoption9182451

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

Fix req.protocol for proxy-direct connectionsAshley Strebbefore adoptiona28b7a8

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

tests: run render tests with internal template engineDouglas Christopher Wilsonbefore adoption9182451

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

Fix req.protocol for proxy-direct connectionsAshley Strebbefore adoptiona28b7a8

lines 57–68why, one step back
57
58 app.use(function(req, res){59 res.render('blog/post');60 });6162 request(app)63 .get('/')64 .expect('<h1>blog post</h1>', done);65 })6667 describe('when an error occurs', function(){68 it('should next(err)', function(done){

tests: run render tests with internal template engineDouglas Christopher Wilsonbefore adoption9182451

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

Fix req.protocol for proxy-direct connectionsAshley Strebbefore adoptiona28b7a8

lines 70–73why, one step back
70
71 app.set('views', __dirname + '/fixtures');7273 app.use(function(req, res){

tests: run render tests with internal template engineDouglas Christopher Wilsonbefore adoption9182451

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

Fix req.protocol for proxy-direct connectionsAshley Strebbefore adoptiona28b7a8

lines 75–88why, one step back
75 });
7677 app.use(function(err, req, res, next){78 res.end(err.message);79 });8081 request(app)82 .get('/')83 .expect(/Cannot read property 'name' of undefined/, done);84 })85 })8687 describe('when "view engine" is given', function(){88 it('should render the template', function(done){

tests: run render tests with internal template engineDouglas Christopher Wilsonbefore adoption9182451

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

Fix req.protocol for proxy-direct connectionsAshley Strebbefore adoptiona28b7a8

line 90why, one step back
90

tests: run render tests with internal template engineDouglas Christopher Wilsonbefore adoption9182451

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

Fix req.protocol for proxy-direct connectionsAshley Strebbefore adoptiona28b7a8

lines 92–106why, one step back
92 app.set('views', __dirname + '/fixtures');
9394 app.use(function(req, res){95 res.render('email');96 });9798 request(app)99 .get('/')100 .expect('<p>This is an email</p>', done);101 })102 })103 })104105 describe('.render(name, option)', function(){106 it('should render the template', function(done){

tests: run render tests with internal template engineDouglas Christopher Wilsonbefore adoption9182451

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

Fix req.protocol for proxy-direct connectionsAshley Strebbefore adoptiona28b7a8

lines 108–113why, one step back
108
109 app.set('views', __dirname + '/fixtures');110111 var user = { name: 'tobi' };112113 app.use(function(req, res){

tests: run render tests with internal template engineDouglas Christopher Wilsonbefore adoption9182451

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

Fix req.protocol for proxy-direct connectionsAshley Strebbefore adoptiona28b7a8

lines 115–122why, one step back
115 });
116117 request(app)118 .get('/')119 .expect('<p>tobi</p>', done);120 })121122 it('should expose app.locals', function(done){

tests: run render tests with internal template engineDouglas Christopher Wilsonbefore adoption9182451

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

Fix req.protocol for proxy-direct connectionsAshley Strebbefore adoptiona28b7a8

lines 124–128why, one step back
124
125 app.set('views', __dirname + '/fixtures');126 app.locals.user = { name: 'tobi' };127128 app.use(function(req, res){

tests: run render tests with internal template engineDouglas Christopher Wilsonbefore adoption9182451

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

Fix req.protocol for proxy-direct connectionsAshley Strebbefore adoptiona28b7a8

lines 130–137why, one step back
130 });
131132 request(app)133 .get('/')134 .expect('<p>tobi</p>', done);135 })136137 it('should expose res.locals', function(done){

tests: run render tests with internal template engineDouglas Christopher Wilsonbefore adoption9182451

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

Fix req.protocol for proxy-direct connectionsAshley Strebbefore adoptiona28b7a8

lines 139–143why, one step back
139
140 app.set('views', __dirname + '/fixtures');141142 app.use(function(req, res){143 res.locals.user = { name: 'tobi' };

tests: run render tests with internal template engineDouglas Christopher Wilsonbefore adoption9182451

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

Fix req.protocol for proxy-direct connectionsAshley Strebbefore adoptiona28b7a8

lines 145–152why, one step back
145 });
146147 request(app)148 .get('/')149 .expect('<p>tobi</p>', done);150 })151152 it('should give precedence to res.locals over app.locals', function(done){

tests: run render tests with internal template engineDouglas Christopher Wilsonbefore adoption9182451

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

Fix req.protocol for proxy-direct connectionsAshley Strebbefore adoptiona28b7a8

lines 154–159why, one step back
154
155 app.set('views', __dirname + '/fixtures');156 app.locals.user = { name: 'tobi' };157158 app.use(function(req, res){159 res.locals.user = { name: 'jane' };

tests: run render tests with internal template engineDouglas Christopher Wilsonbefore adoption9182451

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

Fix req.protocol for proxy-direct connectionsAshley Strebbefore adoptiona28b7a8

lines 161–168why, one step back
161 });
162163 request(app)164 .get('/')165 .expect('<p>jane</p>', done);166 })167168 it('should give precedence to res.render() locals over res.locals', function(done){

tests: run render tests with internal template engineDouglas Christopher Wilsonbefore adoption9182451

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

Fix req.protocol for proxy-direct connectionsAshley Strebbefore adoptiona28b7a8

lines 170–175why, one step back
170
171 app.set('views', __dirname + '/fixtures');172 var jane = { name: 'jane' };173174 app.use(function(req, res){175 res.locals.user = { name: 'tobi' };

tests: run render tests with internal template engineDouglas Christopher Wilsonbefore adoption9182451

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

Fix req.protocol for proxy-direct connectionsAshley Strebbefore adoptiona28b7a8

lines 177–184why, one step back
177 });
178179 request(app)180 .get('/')181 .expect('<p>jane</p>', done);182 })183184 it('should give precedence to res.render() locals over app.locals', function(done){

tests: run render tests with internal template engineDouglas Christopher Wilsonbefore adoption9182451

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

Fix req.protocol for proxy-direct connectionsAshley Strebbefore adoptiona28b7a8

lines 186–191why, one step back
186
187 app.set('views', __dirname + '/fixtures');188 app.locals.user = { name: 'tobi' };189 var jane = { name: 'jane' };190191 app.use(function(req, res){

tests: run render tests with internal template engineDouglas Christopher Wilsonbefore adoption9182451

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

Fix req.protocol for proxy-direct connectionsAshley Strebbefore adoptiona28b7a8

lines 193–202why, one step back
193 });
194195 request(app)196 .get('/')197 .expect('<p>jane</p>', done);198 })199 })200201 describe('.render(name, options, fn)', function(){202 it('should pass the resulting string', function(done){

tests: run render tests with internal template engineDouglas Christopher Wilsonbefore adoption9182451

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

Fix req.protocol for proxy-direct connectionsAshley Strebbefore adoptiona28b7a8

lines 204–208why, one step back
204
205 app.set('views', __dirname + '/fixtures');206207 app.use(function(req, res){208 var tobi = { name: 'tobi' };

tests: run render tests with internal template engineDouglas Christopher Wilsonbefore adoption9182451

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

Fix req.protocol for proxy-direct connectionsAshley Strebbefore adoptiona28b7a8

lines 210–222why, one step back
210 html = html.replace('tobi', 'loki');
211 res.end(html);212 });213 });214215 request(app)216 .get('/')217 .expect('<p>loki</p>', done);218 })219 })220221 describe('.render(name, fn)', function(){222 it('should pass the resulting string', function(done){

tests: run render tests with internal template engineDouglas Christopher Wilsonbefore adoption9182451

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

Fix req.protocol for proxy-direct connectionsAshley Strebbefore adoptiona28b7a8

lines 224–228why, one step back
224
225 app.set('views', __dirname + '/fixtures');226227 app.use(function(req, res){228 res.locals.user = { name: 'tobi' };

tests: run render tests with internal template engineDouglas Christopher Wilsonbefore adoption9182451

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

Fix req.protocol for proxy-direct connectionsAshley Strebbefore adoptiona28b7a8

lines 230–241why, one step back
230 html = html.replace('tobi', 'loki');
231 res.end(html);232 });233 });234235 request(app)236 .get('/')237 .expect('<p>loki</p>', done);238 })239240 describe('when an error occurs', function(){241 it('should pass it to the callback', function(done){

tests: run render tests with internal template engineDouglas Christopher Wilsonbefore adoption9182451

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

Fix req.protocol for proxy-direct connectionsAshley Strebbefore adoptiona28b7a8

lines 243–246why, one step back
243
244 app.set('views', __dirname + '/fixtures');245246 app.use(function(req, res){

tests: run render tests with internal template engineDouglas Christopher Wilsonbefore adoption9182451

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

Fix req.protocol for proxy-direct connectionsAshley Strebbefore adoptiona28b7a8

lines 248–258why, one step back
248 res.end(err.message);
249 });250 });251252 request(app)253 .get('/')254 .expect(/Cannot read property 'name' of undefined/, done);255 })256 })257 })258})

tests: run render tests with internal template engineDouglas Christopher Wilsonbefore adoption9182451

lines 259–266why, one step back
259
260function createApp() {261 var app = express();262263 app.engine('.tmpl', tmpl);264265 return app;266}