app.engine.js
This file
Path
test/app.engine.js
83 lines · 2.2 KiB · JavaScript
Last changed by
tests: use strict modeDouglas Christopher Wilsonbefore adoptiona659137
History of this fileTake it
The walk stopped after 200 commits: lines older than 76bf96e point at it.
tests: use strict modeDouglas Christopher Wilsonbefore adoptiona659137
line 1why, one step back1'use strict'deps: finalhandler@1.1.1Douglas Christopher Wilsonbefore adoption76bf96e
line 2why, one step back2tests: remove global dependency on shouldDouglas Christopher Wilsonbefore adoptionbd4fdfe
line 3why, one step back3var assert = require('assert')deps: finalhandler@1.1.1Douglas Christopher Wilsonbefore adoption76bf96e
lines 4–26why, one step back4var express = require('../')5 , fs = require('fs');6var path = require('path')78function 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();2021 app.set('views', path.join(__dirname, 'fixtures'))22 app.engine('.html', render);23 app.locals.user = { name: 'tobi' };2425 app.render('user.html', function(err, str){26 if (err) return done(err);tests: remove global dependency on shouldDouglas Christopher Wilsonbefore adoptionbd4fdfe
line 27why, one step back27 assert.strictEqual(str, '<p>tobi</p>')deps: finalhandler@1.1.1Douglas Christopher Wilsonbefore adoption76bf96e
lines 28–33why, one step back28 done();29 })30 })3132 it('should throw when the callback is missing', function(){33 var app = express();tests: remove global dependency on shouldDouglas Christopher Wilsonbefore adoptionbd4fdfe
line 34why, one step back34 assert.throws(function () {deps: finalhandler@1.1.1Douglas Christopher Wilsonbefore adoption76bf96e
line 35why, one step back35 app.engine('.html', null);tests: remove global dependency on shouldDouglas Christopher Wilsonbefore adoptionbd4fdfe
line 36why, one step back36 }, /callback function required/)deps: finalhandler@1.1.1Douglas Christopher Wilsonbefore adoption76bf96e
lines 37–47why, one step back37 })3839 it('should work without leading "."', function(done){40 var app = express();4142 app.set('views', path.join(__dirname, 'fixtures'))43 app.engine('html', render);44 app.locals.user = { name: 'tobi' };4546 app.render('user.html', function(err, str){47 if (err) return done(err);tests: remove global dependency on shouldDouglas Christopher Wilsonbefore adoptionbd4fdfe
line 48why, one step back48 assert.strictEqual(str, '<p>tobi</p>')deps: finalhandler@1.1.1Douglas Christopher Wilsonbefore adoption76bf96e
lines 49–62why, one step back49 done();50 })51 })5253 it('should work "view engine" setting', function(done){54 var app = express();5556 app.set('views', path.join(__dirname, 'fixtures'))57 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);tests: remove global dependency on shouldDouglas Christopher Wilsonbefore adoptionbd4fdfe
line 63why, one step back63 assert.strictEqual(str, '<p>tobi</p>')deps: finalhandler@1.1.1Douglas Christopher Wilsonbefore adoption76bf96e
lines 64–77why, one step back64 done();65 })66 })6768 it('should work "view engine" with leading "."', function(done){69 var app = express();7071 app.set('views', path.join(__dirname, 'fixtures'))72 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);tests: remove global dependency on shouldDouglas Christopher Wilsonbefore adoptionbd4fdfe
line 78why, one step back78 assert.strictEqual(str, '<p>tobi</p>')deps: finalhandler@1.1.1Douglas Christopher Wilsonbefore adoption76bf96e
lines 79–83why, one step back79 done();80 })81 })82 })83})