app.engine.js
This file
Path
test/app.engine.js
81 lines · 2.1 KiB · JavaScript
Last changed by
tests: use path.join instead of concatenationchainhelenbefore adoptioneece385
History of this fileTake it
The walk stopped after 200 commits: lines older than 2ac2509 point at it.
4.13.1Douglas Christopher Wilsonbefore adoption2ac2509
lines 1–3why, one step back12var express = require('../')3 , fs = require('fs');tests: use path.join instead of concatenationchainhelenbefore adoptioneece385
line 4why, one step back4var path = require('path')4.13.1Douglas Christopher Wilsonbefore adoption2ac2509
lines 5–18why, one step back56function render(path, options, fn) {7 fs.readFile(path, 'utf8', function(err, str){8 if (err) return fn(err);9 str = str.replace('{{user.name}}', options.user.name);10 fn(null, str);11 });12}1314describe('app', function(){15 describe('.engine(ext, fn)', function(){16 it('should map a template engine', function(done){17 var app = express();18tests: use path.join instead of concatenationchainhelenbefore adoptioneece385
line 19why, one step back19 app.set('views', path.join(__dirname, 'fixtures'))4.13.1Douglas Christopher Wilsonbefore adoption2ac2509
lines 20–39why, one step back20 app.engine('.html', render);21 app.locals.user = { name: 'tobi' };2223 app.render('user.html', function(err, str){24 if (err) return done(err);25 str.should.equal('<p>tobi</p>');26 done();27 })28 })2930 it('should throw when the callback is missing', function(){31 var app = express();32 (function(){33 app.engine('.html', null);34 }).should.throw('callback function required');35 })3637 it('should work without leading "."', function(done){38 var app = express();39tests: use path.join instead of concatenationchainhelenbefore adoptioneece385
line 40why, one step back40 app.set('views', path.join(__dirname, 'fixtures'))4.13.1Douglas Christopher Wilsonbefore adoption2ac2509
lines 41–53why, one step back41 app.engine('html', render);42 app.locals.user = { name: 'tobi' };4344 app.render('user.html', function(err, str){45 if (err) return done(err);46 str.should.equal('<p>tobi</p>');47 done();48 })49 })50 51 it('should work "view engine" setting', function(done){52 var app = express();53tests: use path.join instead of concatenationchainhelenbefore adoptioneece385
line 54why, one step back54 app.set('views', path.join(__dirname, 'fixtures'))4.13.1Douglas Christopher Wilsonbefore adoption2ac2509
lines 55–68why, one step back55 app.engine('html', render);56 app.set('view engine', 'html');57 app.locals.user = { name: 'tobi' };5859 app.render('user', function(err, str){60 if (err) return done(err);61 str.should.equal('<p>tobi</p>');62 done();63 })64 })65 66 it('should work "view engine" with leading "."', function(done){67 var app = express();68tests: use path.join instead of concatenationchainhelenbefore adoptioneece385
line 69why, one step back69 app.set('views', path.join(__dirname, 'fixtures'))4.13.1Douglas Christopher Wilsonbefore adoption2ac2509
lines 70–81why, one step back70 app.engine('.html', render);71 app.set('view engine', '.html');72 app.locals.user = { name: 'tobi' };7374 app.render('user', function(err, str){75 if (err) return done(err);76 str.should.equal('<p>tobi</p>');77 done();78 })79 })80 })81})