app.engine.js
This file
Path
test/app.engine.js
81 lines · 2.1 KiB · JavaScript
Last changed by
lint: add eslint rules that cover editorconfigDouglas Christopher Wilsonbefore adoption56e90e3
History of this fileTake it
The walk stopped after 200 commits: lines older than 43dff4c point at it.
docs: fix GitHub capitalizationPiper Chesterbefore adoption43dff4c
lines 1–49why, one step back12var express = require('../')3 , fs = require('fs');4var path = require('path')56function 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();1819 app.set('views', path.join(__dirname, 'fixtures'))20 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();3940 app.set('views', path.join(__dirname, 'fixtures'))41 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 })lint: add eslint rules that cover editorconfigDouglas Christopher Wilsonbefore adoption56e90e3
line 50why, one step back50docs: fix GitHub capitalizationPiper Chesterbefore adoption43dff4c
lines 51–64why, one step back51 it('should work "view engine" setting', function(done){52 var app = express();5354 app.set('views', path.join(__dirname, 'fixtures'))55 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 })lint: add eslint rules that cover editorconfigDouglas Christopher Wilsonbefore adoption56e90e3
line 65why, one step back65docs: fix GitHub capitalizationPiper Chesterbefore adoption43dff4c
lines 66–81why, one step back66 it('should work "view engine" with leading "."', function(done){67 var app = express();6869 app.set('views', path.join(__dirname, 'fixtures'))70 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})