Skip to content
Myr

app.render.js

This file

Path

test/app.render.js

304 lines · 7.9 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–3why, one step back
2var express = require('..');
3var tmpl = require('./support/tmpl');

Fix req.protocol for proxy-direct connectionsAshley Strebbefore adoptiona28b7a8

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

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

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

Fix req.protocol for proxy-direct connectionsAshley Strebbefore adoptiona28b7a8

lines 9–11why, one step back
9
10 app.locals.user = { name: 'tobi' };11

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

line 12why, one step back
12 app.render(__dirname + '/fixtures/user.tmpl', function (err, str) {

Fix req.protocol for proxy-direct connectionsAshley Strebbefore adoptiona28b7a8

lines 13–19why, one step back
13 if (err) return done(err);
14 str.should.equal('<p>tobi</p>');15 done();16 })17 })1819 it('should support absolute paths with "view engine"', function(done){

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

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

Fix req.protocol for proxy-direct connectionsAshley Strebbefore adoptiona28b7a8

line 21why, one step back
21

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

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

Fix req.protocol for proxy-direct connectionsAshley Strebbefore adoptiona28b7a8

lines 23–32why, one step back
23 app.locals.user = { name: 'tobi' };
2425 app.render(__dirname + '/fixtures/user', function(err, str){26 if (err) return done(err);27 str.should.equal('<p>tobi</p>');28 done();29 })30 })3132 it('should expose app.locals', function(done){

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

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

Fix req.protocol for proxy-direct connectionsAshley Strebbefore adoptiona28b7a8

lines 34–37why, one step back
34
35 app.set('views', __dirname + '/fixtures');36 app.locals.user = { name: 'tobi' };37

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

line 38why, one step back
38 app.render('user.tmpl', function (err, str) {

Fix req.protocol for proxy-direct connectionsAshley Strebbefore adoptiona28b7a8

lines 39–45why, one step back
39 if (err) return done(err);
40 str.should.equal('<p>tobi</p>');41 done();42 })43 })4445 it('should support index.<engine>', function(done){

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

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

Fix req.protocol for proxy-direct connectionsAshley Strebbefore adoptiona28b7a8

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

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

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

Fix req.protocol for proxy-direct connectionsAshley Strebbefore adoptiona28b7a8

line 50why, one step back
50

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

line 51why, one step back
51 app.render('blog/post', function (err, str) {

Fix req.protocol for proxy-direct connectionsAshley Strebbefore adoptiona28b7a8

lines 52–80why, one step back
52 if (err) return done(err);
53 str.should.equal('<h1>blog post</h1>');54 done();55 })56 })5758 it('should handle render error throws', function(done){59 var app = express();6061 function View(name, options){62 this.name = name;63 this.path = 'fale';64 }6566 View.prototype.render = function(options, fn){67 throw new Error('err!');68 };6970 app.set('view', View);7172 app.render('something', function(err, str){73 err.should.be.ok;74 err.message.should.equal('err!');75 done();76 })77 })7879 describe('when the file does not exist', function(){80 it('should provide a helpful error', function(done){

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

lines 81–82why, one step back
81 var app = createApp();
82

Fix req.protocol for proxy-direct connectionsAshley Strebbefore adoptiona28b7a8

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

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

lines 84–85why, one step back
84 app.render('rawr.tmpl', function (err) {
85 err.message.should.equal('Failed to lookup view "rawr.tmpl" in views directory "' + __dirname + '/fixtures"');

Fix req.protocol for proxy-direct connectionsAshley Strebbefore adoptiona28b7a8

lines 86–92why, one step back
86 done();
87 });88 })89 })9091 describe('when an error occurs', function(){92 it('should invoke the callback', function(done){

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

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

Fix req.protocol for proxy-direct connectionsAshley Strebbefore adoptiona28b7a8

lines 94–96why, one step back
94
95 app.set('views', __dirname + '/fixtures');96

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

line 97why, one step back
97 app.render('user.tmpl', function (err, str) {

Fix req.protocol for proxy-direct connectionsAshley Strebbefore adoptiona28b7a8

lines 98–108why, one step back
98 // nextTick to prevent cyclic
99 process.nextTick(function(){100 err.message.should.match(/Cannot read property 'name' of undefined/);101 done();102 });103 })104 })105 })106107 describe('when an extension is given', function(){108 it('should render the template', function(done){

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

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

Fix req.protocol for proxy-direct connectionsAshley Strebbefore adoptiona28b7a8

lines 110–112why, one step back
110
111 app.set('views', __dirname + '/fixtures');112

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

line 113why, one step back
113 app.render('email.tmpl', function (err, str) {

Fix req.protocol for proxy-direct connectionsAshley Strebbefore adoptiona28b7a8

lines 114–122why, one step back
114 if (err) return done(err);
115 str.should.equal('<p>This is an email</p>');116 done();117 })118 })119 })120121 describe('when "view engine" is given', function(){122 it('should render the template', 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

line 124why, one step back
124

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

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

Fix req.protocol for proxy-direct connectionsAshley Strebbefore adoptiona28b7a8

lines 126–223why, one step back
126 app.set('views', __dirname + '/fixtures');
127128 app.render('email', function(err, str){129 if (err) return done(err);130 str.should.equal('<p>This is an email</p>');131 done();132 })133 })134 })135136 describe('when a "view" constructor is given', function(){137 it('should create an instance of it', function(done){138 var app = express();139140 function View(name, options){141 this.name = name;142 this.path = 'path is required by application.js as a signal of success even though it is not used there.';143 }144145 View.prototype.render = function(options, fn){146 fn(null, 'abstract engine');147 };148149 app.set('view', View);150151 app.render('something', function(err, str){152 if (err) return done(err);153 str.should.equal('abstract engine');154 done();155 })156 })157 })158159 describe('caching', function(){160 it('should always lookup view without cache', function(done){161 var app = express();162 var count = 0;163164 function View(name, options){165 this.name = name;166 this.path = 'fake';167 count++;168 }169170 View.prototype.render = function(options, fn){171 fn(null, 'abstract engine');172 };173174 app.set('view cache', false);175 app.set('view', View);176177 app.render('something', function(err, str){178 if (err) return done(err);179 count.should.equal(1);180 str.should.equal('abstract engine');181 app.render('something', function(err, str){182 if (err) return done(err);183 count.should.equal(2);184 str.should.equal('abstract engine');185 done();186 })187 })188 })189190 it('should cache with "view cache" setting', function(done){191 var app = express();192 var count = 0;193194 function View(name, options){195 this.name = name;196 this.path = 'fake';197 count++;198 }199200 View.prototype.render = function(options, fn){201 fn(null, 'abstract engine');202 };203204 app.set('view cache', true);205 app.set('view', View);206207 app.render('something', function(err, str){208 if (err) return done(err);209 count.should.equal(1);210 str.should.equal('abstract engine');211 app.render('something', function(err, str){212 if (err) return done(err);213 count.should.equal(1);214 str.should.equal('abstract engine');215 done();216 })217 })218 })219 })220 })221222 describe('.render(name, options, fn)', function(){223 it('should render the template', function(done){

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

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

Fix req.protocol for proxy-direct connectionsAshley Strebbefore adoptiona28b7a8

lines 225–229why, one step back
225
226 app.set('views', __dirname + '/fixtures');227228 var user = { name: 'tobi' };229

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

line 230why, one step back
230 app.render('user.tmpl', { user: user }, function (err, str) {

Fix req.protocol for proxy-direct connectionsAshley Strebbefore adoptiona28b7a8

lines 231–237why, one step back
231 if (err) return done(err);
232 str.should.equal('<p>tobi</p>');233 done();234 })235 })236237 it('should expose app.locals', function(done){

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

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

Fix req.protocol for proxy-direct connectionsAshley Strebbefore adoptiona28b7a8

lines 239–242why, one step back
239
240 app.set('views', __dirname + '/fixtures');241 app.locals.user = { name: 'tobi' };242

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

line 243why, one step back
243 app.render('user.tmpl', {}, function (err, str) {

Fix req.protocol for proxy-direct connectionsAshley Strebbefore adoptiona28b7a8

lines 244–250why, one step back
244 if (err) return done(err);
245 str.should.equal('<p>tobi</p>');246 done();247 })248 })249250 it('should give precedence to app.render() locals', function(done){

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

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

Fix req.protocol for proxy-direct connectionsAshley Strebbefore adoptiona28b7a8

lines 252–256why, one step back
252
253 app.set('views', __dirname + '/fixtures');254 app.locals.user = { name: 'tobi' };255 var jane = { name: 'jane' };256

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

line 257why, one step back
257 app.render('user.tmpl', { user: jane }, function (err, str) {

Fix req.protocol for proxy-direct connectionsAshley Strebbefore adoptiona28b7a8

lines 258–296why, one step back
258 if (err) return done(err);
259 str.should.equal('<p>jane</p>');260 done();261 })262 })263264 describe('caching', function(){265 it('should cache with cache option', function(done){266 var app = express();267 var count = 0;268269 function View(name, options){270 this.name = name;271 this.path = 'fake';272 count++;273 }274275 View.prototype.render = function(options, fn){276 fn(null, 'abstract engine');277 };278279 app.set('view cache', false);280 app.set('view', View);281282 app.render('something', {cache: true}, function(err, str){283 if (err) return done(err);284 count.should.equal(1);285 str.should.equal('abstract engine');286 app.render('something', {cache: true}, function(err, str){287 if (err) return done(err);288 count.should.equal(1);289 str.should.equal('abstract engine');290 done();291 })292 })293 })294 })295 })296})

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

lines 297–304why, one step back
297
298function createApp() {299 var app = express();300301 app.engine('.tmpl', tmpl);302303 return app;304}