Skip to content
Myr

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 file

Take 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 back
1
2var express = require('../')3 , fs = require('fs');

tests: use path.join instead of concatenationchainhelenbefore adoptioneece385

line 4why, one step back
4var path = require('path')

4.13.1Douglas Christopher Wilsonbefore adoption2ac2509

lines 5–18why, one step back
5
6function 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();18

tests: use path.join instead of concatenationchainhelenbefore adoptioneece385

line 19why, one step back
19 app.set('views', path.join(__dirname, 'fixtures'))

4.13.1Douglas Christopher Wilsonbefore adoption2ac2509

lines 20–39why, one step back
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();39

tests: use path.join instead of concatenationchainhelenbefore adoptioneece385

line 40why, one step back
40 app.set('views', path.join(__dirname, 'fixtures'))

4.13.1Douglas Christopher Wilsonbefore adoption2ac2509

lines 41–53why, one step back
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 })50 51 it('should work "view engine" setting', function(done){52 var app = express();53

tests: use path.join instead of concatenationchainhelenbefore adoptioneece385

line 54why, one step back
54 app.set('views', path.join(__dirname, 'fixtures'))

4.13.1Douglas Christopher Wilsonbefore adoption2ac2509

lines 55–68why, one step back
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 })65 66 it('should work "view engine" with leading "."', function(done){67 var app = express();68

tests: use path.join instead of concatenationchainhelenbefore adoptioneece385

line 69why, one step back
69 app.set('views', path.join(__dirname, 'fixtures'))

4.13.1Douglas Christopher Wilsonbefore adoption2ac2509

lines 70–81why, one step back
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})