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 fileTake 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 back1tests: run render tests with internal template engineDouglas Christopher Wilsonbefore adoption9182451
lines 2–4why, one step back2var 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 back56describe('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 back9 var app = createApp();Fix req.protocol for proxy-direct connectionsAshley Strebbefore adoptiona28b7a8
lines 10–13why, one step back1011 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 back14 res.render(__dirname + '/fixtures/user.tmpl');Fix req.protocol for proxy-direct connectionsAshley Strebbefore adoptiona28b7a8
lines 15–22why, one step back15 });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 back23 var app = createApp();Fix req.protocol for proxy-direct connectionsAshley Strebbefore adoptiona28b7a8
lines 24–25why, one step back2425 app.locals.user = { name: 'tobi' };tests: run render tests with internal template engineDouglas Christopher Wilsonbefore adoption9182451
line 26why, one step back26 app.set('view engine', 'tmpl');Fix req.protocol for proxy-direct connectionsAshley Strebbefore adoptiona28b7a8
lines 27–37why, one step back2728 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 back38 var app = createApp();Fix req.protocol for proxy-direct connectionsAshley Strebbefore adoptiona28b7a8
lines 39–43why, one step back3940 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 back44 res.render('user.tmpl');Fix req.protocol for proxy-direct connectionsAshley Strebbefore adoptiona28b7a8
lines 45–52why, one step back45 });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 back53 var app = createApp();Fix req.protocol for proxy-direct connectionsAshley Strebbefore adoptiona28b7a8
lines 54–55why, one step back5455 app.set('views', __dirname + '/fixtures');tests: run render tests with internal template engineDouglas Christopher Wilsonbefore adoption9182451
line 56why, one step back56 app.set('view engine', 'tmpl');Fix req.protocol for proxy-direct connectionsAshley Strebbefore adoptiona28b7a8
lines 57–68why, one step back5758 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 back69 var app = createApp();Fix req.protocol for proxy-direct connectionsAshley Strebbefore adoptiona28b7a8
lines 70–73why, one step back7071 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 back74 res.render('user.tmpl');Fix req.protocol for proxy-direct connectionsAshley Strebbefore adoptiona28b7a8
lines 75–88why, one step back75 });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 back89 var app = createApp();Fix req.protocol for proxy-direct connectionsAshley Strebbefore adoptiona28b7a8
line 90why, one step back90tests: run render tests with internal template engineDouglas Christopher Wilsonbefore adoption9182451
line 91why, one step back91 app.set('view engine', 'tmpl');Fix req.protocol for proxy-direct connectionsAshley Strebbefore adoptiona28b7a8
lines 92–106why, one step back92 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 back107 var app = createApp();Fix req.protocol for proxy-direct connectionsAshley Strebbefore adoptiona28b7a8
lines 108–113why, one step back108109 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 back114 res.render('user.tmpl', { user: user });Fix req.protocol for proxy-direct connectionsAshley Strebbefore adoptiona28b7a8
lines 115–122why, one step back115 });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 back123 var app = createApp();Fix req.protocol for proxy-direct connectionsAshley Strebbefore adoptiona28b7a8
lines 124–128why, one step back124125 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 back129 res.render('user.tmpl');Fix req.protocol for proxy-direct connectionsAshley Strebbefore adoptiona28b7a8
lines 130–137why, one step back130 });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 back138 var app = createApp();Fix req.protocol for proxy-direct connectionsAshley Strebbefore adoptiona28b7a8
lines 139–143why, one step back139140 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 back144 res.render('user.tmpl');Fix req.protocol for proxy-direct connectionsAshley Strebbefore adoptiona28b7a8
lines 145–152why, one step back145 });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 back153 var app = createApp();Fix req.protocol for proxy-direct connectionsAshley Strebbefore adoptiona28b7a8
lines 154–159why, one step back154155 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 back160 res.render('user.tmpl', {});Fix req.protocol for proxy-direct connectionsAshley Strebbefore adoptiona28b7a8
lines 161–168why, one step back161 });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 back169 var app = createApp();Fix req.protocol for proxy-direct connectionsAshley Strebbefore adoptiona28b7a8
lines 170–175why, one step back170171 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 back176 res.render('user.tmpl', { user: jane });Fix req.protocol for proxy-direct connectionsAshley Strebbefore adoptiona28b7a8
lines 177–184why, one step back177 });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 back185 var app = createApp();Fix req.protocol for proxy-direct connectionsAshley Strebbefore adoptiona28b7a8
lines 186–191why, one step back186187 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 back192 res.render('user.tmpl', { user: jane });Fix req.protocol for proxy-direct connectionsAshley Strebbefore adoptiona28b7a8
lines 193–202why, one step back193 });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 back203 var app = createApp();Fix req.protocol for proxy-direct connectionsAshley Strebbefore adoptiona28b7a8
lines 204–208why, one step back204205 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 back209 res.render('user.tmpl', { user: tobi }, function (err, html) {Fix req.protocol for proxy-direct connectionsAshley Strebbefore adoptiona28b7a8
lines 210–222why, one step back210 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 back223 var app = createApp();Fix req.protocol for proxy-direct connectionsAshley Strebbefore adoptiona28b7a8
lines 224–228why, one step back224225 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 back229 res.render('user.tmpl', function (err, html) {Fix req.protocol for proxy-direct connectionsAshley Strebbefore adoptiona28b7a8
lines 230–241why, one step back230 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 back242 var app = createApp();Fix req.protocol for proxy-direct connectionsAshley Strebbefore adoptiona28b7a8
lines 243–246why, one step back243244 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 back247 res.render('user.tmpl', function (err) {Fix req.protocol for proxy-direct connectionsAshley Strebbefore adoptiona28b7a8
lines 248–258why, one step back248 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 back259260function createApp() {261 var app = express();262263 app.engine('.tmpl', tmpl);264265 return app;266}