app.engine.js
This file
Path
test/app.engine.js
83 lines · 2.2 KiB · JavaScript
Last changed by
Merge tag '4.17.3'Douglas Christopher Wilsonbefore adoption318fd4b
History of this fileTake it
The walk stopped after 200 commits: lines older than 454c4b2 point at it.
Merge tag '4.17.3'Douglas Christopher Wilsonbefore adoption318fd4b
line 1why, one step back1'use strict'Merge tag '3.15.2'Douglas Christopher Wilsonbefore adoption454c4b2
line 2why, one step back2Merge tag '4.17.3'Douglas Christopher Wilsonbefore adoption318fd4b
line 3why, one step back3var assert = require('assert')Merge tag '3.15.2'Douglas Christopher Wilsonbefore adoption454c4b2
lines 4–5why, one step back4var express = require('../')5 , fs = require('fs');Merge tag '4.15.2'Douglas Christopher Wilsonbefore adoptione5dbb0c
line 6why, one step back6var path = require('path')Merge tag '3.15.2'Douglas Christopher Wilsonbefore adoption454c4b2
lines 7–20why, one step back78function 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);12 fn(null, str);13 });14}1516describe('app', function(){17 describe('.engine(ext, fn)', function(){18 it('should map a template engine', function(done){19 var app = express();20Merge tag '4.15.2'Douglas Christopher Wilsonbefore adoptione5dbb0c
line 21why, one step back21 app.set('views', path.join(__dirname, 'fixtures'))Merge tag '3.15.2'Douglas Christopher Wilsonbefore adoption454c4b2
lines 22–26why, one step back22 app.engine('.html', render);23 app.locals.user = { name: 'tobi' };2425 app.render('user.html', function(err, str){26 if (err) return done(err);Merge tag '4.17.3'Douglas Christopher Wilsonbefore adoption318fd4b
line 27why, one step back27 assert.strictEqual(str, '<p>tobi</p>')Merge tag '3.15.2'Douglas Christopher Wilsonbefore adoption454c4b2
lines 28–33why, one step back28 done();29 })30 })3132 it('should throw when the callback is missing', function(){33 var app = express();Merge tag '4.17.3'Douglas Christopher Wilsonbefore adoption318fd4b
line 34why, one step back34 assert.throws(function () {Merge tag '3.15.2'Douglas Christopher Wilsonbefore adoption454c4b2
line 35why, one step back35 app.engine('.html', null);Merge tag '4.17.3'Douglas Christopher Wilsonbefore adoption318fd4b
line 36why, one step back36 }, /callback function required/)Merge tag '3.15.2'Douglas Christopher Wilsonbefore adoption454c4b2
lines 37–41why, one step back37 })3839 it('should work without leading "."', function(done){40 var app = express();41Merge tag '4.15.2'Douglas Christopher Wilsonbefore adoptione5dbb0c
line 42why, one step back42 app.set('views', path.join(__dirname, 'fixtures'))Merge tag '3.15.2'Douglas Christopher Wilsonbefore adoption454c4b2
lines 43–47why, one step back43 app.engine('html', render);44 app.locals.user = { name: 'tobi' };4546 app.render('user.html', function(err, str){47 if (err) return done(err);Merge tag '4.17.3'Douglas Christopher Wilsonbefore adoption318fd4b
line 48why, one step back48 assert.strictEqual(str, '<p>tobi</p>')Merge tag '3.15.2'Douglas Christopher Wilsonbefore adoption454c4b2
lines 49–51why, one step back49 done();50 })51 })Merge tag '4.15.4'Douglas Christopher Wilsonbefore adoptionc319fe2
line 52why, one step back52Merge tag '3.15.2'Douglas Christopher Wilsonbefore adoption454c4b2
lines 53–55why, one step back53 it('should work "view engine" setting', function(done){54 var app = express();55Merge tag '4.15.2'Douglas Christopher Wilsonbefore adoptione5dbb0c
line 56why, one step back56 app.set('views', path.join(__dirname, 'fixtures'))Merge tag '3.15.2'Douglas Christopher Wilsonbefore adoption454c4b2
lines 57–62why, one step back57 app.engine('html', render);58 app.set('view engine', 'html');59 app.locals.user = { name: 'tobi' };6061 app.render('user', function(err, str){62 if (err) return done(err);Merge tag '4.17.3'Douglas Christopher Wilsonbefore adoption318fd4b
line 63why, one step back63 assert.strictEqual(str, '<p>tobi</p>')Merge tag '3.15.2'Douglas Christopher Wilsonbefore adoption454c4b2
lines 64–66why, one step back64 done();65 })66 })Merge tag '4.15.4'Douglas Christopher Wilsonbefore adoptionc319fe2
line 67why, one step back67Merge tag '3.15.2'Douglas Christopher Wilsonbefore adoption454c4b2
lines 68–70why, one step back68 it('should work "view engine" with leading "."', function(done){69 var app = express();70Merge tag '4.15.2'Douglas Christopher Wilsonbefore adoptione5dbb0c
line 71why, one step back71 app.set('views', path.join(__dirname, 'fixtures'))Merge tag '3.15.2'Douglas Christopher Wilsonbefore adoption454c4b2
lines 72–77why, one step back72 app.engine('.html', render);73 app.set('view engine', '.html');74 app.locals.user = { name: 'tobi' };7576 app.render('user', function(err, str){77 if (err) return done(err);Merge tag '4.17.3'Douglas Christopher Wilsonbefore adoption318fd4b
line 78why, one step back78 assert.strictEqual(str, '<p>tobi</p>')Merge tag '3.15.2'Douglas Christopher Wilsonbefore adoption454c4b2
lines 79–83why, one step back79 done();80 })81 })82 })83})