3 var assert = require('assert')
4 var express = require('../')
6 var path = require('path')
8 function render(path, options, fn) {
9 fs.readFile(path, 'utf8', function(err, str){
10 if (err) return fn(err);
11 str = str.replace('{{user.name}}', options.user.name);
16 describe('app', function(){
17 describe('.engine(ext, fn)', function(){
18 it('should map a template engine', function(done){
21 app.set('views', path.join(__dirname, 'fixtures'))
22 app.engine('.html', render);
23 app.locals.user = { name: 'tobi' };
25 app.render('user.html', function(err, str){
26 if (err) return done(err);
27 assert.strictEqual(str, '<p>tobi</p>')
32 it('should throw when the callback is missing', function(){
34 assert.throws(function () {
35 app.engine('.html', null);
36 }, /callback function required/)
39 it('should work without leading "."', function(done){
42 app.set('views', path.join(__dirname, 'fixtures'))
43 app.engine('html', render);
44 app.locals.user = { name: 'tobi' };
46 app.render('user.html', function(err, str){
47 if (err) return done(err);
48 assert.strictEqual(str, '<p>tobi</p>')
53 it('should work "view engine" setting', function(done){
56 app.set('views', path.join(__dirname, 'fixtures'))
57 app.engine('html', render);
58 app.set('view engine', 'html');
59 app.locals.user = { name: 'tobi' };
61 app.render('user', function(err, str){
62 if (err) return done(err);
63 assert.strictEqual(str, '<p>tobi</p>')
68 it('should work "view engine" with leading "."', function(done){
71 app.set('views', path.join(__dirname, 'fixtures'))
72 app.engine('.html', render);
73 app.set('view engine', '.html');
74 app.locals.user = { name: 'tobi' };
76 app.render('user', function(err, str){
77 if (err) return done(err);
78 assert.strictEqual(str, '<p>tobi</p>')