Skip to content
Myr

app.engine.js

This file

Path

test/app.engine.js

83 lines · 2.2 KiB · JavaScript

Last changed by

fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359

History of this file

Take it

The walk stopped after 200 commits: lines older than 2027b87 point at it.

fix(deps): cookie@0.7.0Josh Bukerbefore adoption2027b87

lines 1–2why, one step back
1'use strict'
2

fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359

line 3why, one step back
3var assert = require('node:assert')

fix(deps): cookie@0.7.0Josh Bukerbefore adoption2027b87

line 4why, one step back
4var express = require('../')

fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359

lines 5–6why, one step back
5 , fs = require('node:fs');
6var path = require('node:path')

fix(deps): cookie@0.7.0Josh Bukerbefore adoption2027b87

lines 7–83why, one step back
7
8function 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);27 assert.strictEqual(str, '<p>tobi</p>')28 done();29 })30 })3132 it('should throw when the callback is missing', function(){33 var app = express();34 assert.throws(function () {35 app.engine('.html', null);36 }, /callback function required/)37 })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);48 assert.strictEqual(str, '<p>tobi</p>')49 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);63 assert.strictEqual(str, '<p>tobi</p>')64 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);78 assert.strictEqual(str, '<p>tobi</p>')79 done();80 })81 })82 })83})