parent
8eb95ae579
commit
eece3850bc
@ -1,6 +1,7 @@
|
||||
|
||||
var express = require('../')
|
||||
, fs = require('fs');
|
||||
var path = require('path')
|
||||
|
||||
function render(path, options, fn) {
|
||||
fs.readFile(path, 'utf8', function(err, str){
|
||||
@ -15,7 +16,7 @@ describe('app', function(){
|
||||
it('should map a template engine', function(done){
|
||||
var app = express();
|
||||
|
||||
app.set('views', __dirname + '/fixtures');
|
||||
app.set('views', path.join(__dirname, 'fixtures'))
|
||||
app.engine('.html', render);
|
||||
app.locals.user = { name: 'tobi' };
|
||||
|
||||
@ -36,7 +37,7 @@ describe('app', function(){
|
||||
it('should work without leading "."', function(done){
|
||||
var app = express();
|
||||
|
||||
app.set('views', __dirname + '/fixtures');
|
||||
app.set('views', path.join(__dirname, 'fixtures'))
|
||||
app.engine('html', render);
|
||||
app.locals.user = { name: 'tobi' };
|
||||
|
||||
@ -50,7 +51,7 @@ describe('app', function(){
|
||||
it('should work "view engine" setting', function(done){
|
||||
var app = express();
|
||||
|
||||
app.set('views', __dirname + '/fixtures');
|
||||
app.set('views', path.join(__dirname, 'fixtures'))
|
||||
app.engine('html', render);
|
||||
app.set('view engine', 'html');
|
||||
app.locals.user = { name: 'tobi' };
|
||||
@ -65,7 +66,7 @@ describe('app', function(){
|
||||
it('should work "view engine" with leading "."', function(done){
|
||||
var app = express();
|
||||
|
||||
app.set('views', __dirname + '/fixtures');
|
||||
app.set('views', path.join(__dirname, 'fixtures'))
|
||||
app.engine('.html', render);
|
||||
app.set('view engine', '.html');
|
||||
app.locals.user = { name: 'tobi' };
|
||||
|
@ -1,5 +1,7 @@
|
||||
|
||||
var assert = require('assert')
|
||||
var express = require('..');
|
||||
var path = require('path')
|
||||
var tmpl = require('./support/tmpl');
|
||||
|
||||
describe('app', function(){
|
||||
@ -9,7 +11,7 @@ describe('app', function(){
|
||||
|
||||
app.locals.user = { name: 'tobi' };
|
||||
|
||||
app.render(__dirname + '/fixtures/user.tmpl', function (err, str) {
|
||||
app.render(path.join(__dirname, 'fixtures', 'user.tmpl'), function (err, str) {
|
||||
if (err) return done(err);
|
||||
str.should.equal('<p>tobi</p>');
|
||||
done();
|
||||
@ -22,7 +24,7 @@ describe('app', function(){
|
||||
app.set('view engine', 'tmpl');
|
||||
app.locals.user = { name: 'tobi' };
|
||||
|
||||
app.render(__dirname + '/fixtures/user', function(err, str){
|
||||
app.render(path.join(__dirname, 'fixtures', 'user'), function (err, str) {
|
||||
if (err) return done(err);
|
||||
str.should.equal('<p>tobi</p>');
|
||||
done();
|
||||
@ -32,7 +34,7 @@ describe('app', function(){
|
||||
it('should expose app.locals', function(done){
|
||||
var app = createApp();
|
||||
|
||||
app.set('views', __dirname + '/fixtures');
|
||||
app.set('views', path.join(__dirname, 'fixtures'))
|
||||
app.locals.user = { name: 'tobi' };
|
||||
|
||||
app.render('user.tmpl', function (err, str) {
|
||||
@ -45,7 +47,7 @@ describe('app', function(){
|
||||
it('should support index.<engine>', function(done){
|
||||
var app = createApp();
|
||||
|
||||
app.set('views', __dirname + '/fixtures');
|
||||
app.set('views', path.join(__dirname, 'fixtures'))
|
||||
app.set('view engine', 'tmpl');
|
||||
|
||||
app.render('blog/post', function (err, str) {
|
||||
@ -80,9 +82,10 @@ describe('app', function(){
|
||||
it('should provide a helpful error', function(done){
|
||||
var app = createApp();
|
||||
|
||||
app.set('views', __dirname + '/fixtures');
|
||||
app.set('views', path.join(__dirname, 'fixtures'))
|
||||
app.render('rawr.tmpl', function (err) {
|
||||
err.message.should.equal('Failed to lookup view "rawr.tmpl" in views directory "' + __dirname + '/fixtures"');
|
||||
assert.ok(err)
|
||||
assert.equal(err.message, 'Failed to lookup view "rawr.tmpl" in views directory "' + path.join(__dirname, 'fixtures') + '"')
|
||||
done();
|
||||
});
|
||||
})
|
||||
@ -92,7 +95,7 @@ describe('app', function(){
|
||||
it('should invoke the callback', function(done){
|
||||
var app = createApp();
|
||||
|
||||
app.set('views', __dirname + '/fixtures');
|
||||
app.set('views', path.join(__dirname, 'fixtures'))
|
||||
|
||||
app.render('user.tmpl', function (err, str) {
|
||||
// nextTick to prevent cyclic
|
||||
@ -108,7 +111,7 @@ describe('app', function(){
|
||||
it('should render the template', function(done){
|
||||
var app = createApp();
|
||||
|
||||
app.set('views', __dirname + '/fixtures');
|
||||
app.set('views', path.join(__dirname, 'fixtures'))
|
||||
|
||||
app.render('email.tmpl', function (err, str) {
|
||||
if (err) return done(err);
|
||||
@ -123,7 +126,7 @@ describe('app', function(){
|
||||
var app = createApp();
|
||||
|
||||
app.set('view engine', 'tmpl');
|
||||
app.set('views', __dirname + '/fixtures');
|
||||
app.set('views', path.join(__dirname, 'fixtures'))
|
||||
|
||||
app.render('email', function(err, str){
|
||||
if (err) return done(err);
|
||||
@ -137,7 +140,7 @@ describe('app', function(){
|
||||
it('should lookup the file in the path', function(done){
|
||||
var app = createApp();
|
||||
|
||||
app.set('views', __dirname + '/fixtures/default_layout');
|
||||
app.set('views', path.join(__dirname, 'fixtures', 'default_layout'))
|
||||
app.locals.user = { name: 'tobi' };
|
||||
|
||||
app.render('user.tmpl', function (err, str) {
|
||||
@ -150,7 +153,10 @@ describe('app', function(){
|
||||
describe('when array of paths', function(){
|
||||
it('should lookup the file in the path', function(done){
|
||||
var app = createApp();
|
||||
var views = [__dirname + '/fixtures/local_layout', __dirname + '/fixtures/default_layout'];
|
||||
var views = [
|
||||
path.join(__dirname, 'fixtures', 'local_layout'),
|
||||
path.join(__dirname, 'fixtures', 'default_layout')
|
||||
]
|
||||
|
||||
app.set('views', views);
|
||||
app.locals.user = { name: 'tobi' };
|
||||
@ -164,7 +170,10 @@ describe('app', function(){
|
||||
|
||||
it('should lookup in later paths until found', function(done){
|
||||
var app = createApp();
|
||||
var views = [__dirname + '/fixtures/local_layout', __dirname + '/fixtures/default_layout'];
|
||||
var views = [
|
||||
path.join(__dirname, 'fixtures', 'local_layout'),
|
||||
path.join(__dirname, 'fixtures', 'default_layout')
|
||||
]
|
||||
|
||||
app.set('views', views);
|
||||
app.locals.name = 'tobi';
|
||||
@ -178,13 +187,17 @@ describe('app', function(){
|
||||
|
||||
it('should error if file does not exist', function(done){
|
||||
var app = createApp();
|
||||
var views = [__dirname + '/fixtures/local_layout', __dirname + '/fixtures/default_layout'];
|
||||
var views = [
|
||||
path.join(__dirname, 'fixtures', 'local_layout'),
|
||||
path.join(__dirname, 'fixtures', 'default_layout')
|
||||
]
|
||||
|
||||
app.set('views', views);
|
||||
app.locals.name = 'tobi';
|
||||
|
||||
app.render('pet.tmpl', function (err, str) {
|
||||
err.message.should.equal('Failed to lookup view "pet.tmpl" in views directories "' + __dirname + '/fixtures/local_layout" or "' + __dirname + '/fixtures/default_layout"');
|
||||
assert.ok(err)
|
||||
assert.equal(err.message, 'Failed to lookup view "pet.tmpl" in views directories "' + views[0] + '" or "' + views[1] + '"')
|
||||
done();
|
||||
})
|
||||
})
|
||||
@ -281,7 +294,7 @@ describe('app', function(){
|
||||
it('should render the template', function(done){
|
||||
var app = createApp();
|
||||
|
||||
app.set('views', __dirname + '/fixtures');
|
||||
app.set('views', path.join(__dirname, 'fixtures'))
|
||||
|
||||
var user = { name: 'tobi' };
|
||||
|
||||
@ -295,7 +308,7 @@ describe('app', function(){
|
||||
it('should expose app.locals', function(done){
|
||||
var app = createApp();
|
||||
|
||||
app.set('views', __dirname + '/fixtures');
|
||||
app.set('views', path.join(__dirname, 'fixtures'))
|
||||
app.locals.user = { name: 'tobi' };
|
||||
|
||||
app.render('user.tmpl', {}, function (err, str) {
|
||||
@ -308,7 +321,7 @@ describe('app', function(){
|
||||
it('should give precedence to app.render() locals', function(done){
|
||||
var app = createApp();
|
||||
|
||||
app.set('views', __dirname + '/fixtures');
|
||||
app.set('views', path.join(__dirname, 'fixtures'))
|
||||
app.locals.user = { name: 'tobi' };
|
||||
var jane = { name: 'jane' };
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
|
||||
var express = require('..');
|
||||
var path = require('path')
|
||||
var request = require('supertest');
|
||||
var tmpl = require('./support/tmpl');
|
||||
|
||||
@ -11,7 +12,7 @@ describe('res', function(){
|
||||
app.locals.user = { name: 'tobi' };
|
||||
|
||||
app.use(function(req, res){
|
||||
res.render(__dirname + '/fixtures/user.tmpl');
|
||||
res.render(path.join(__dirname, 'fixtures', 'user.tmpl'))
|
||||
});
|
||||
|
||||
request(app)
|
||||
@ -26,7 +27,7 @@ describe('res', function(){
|
||||
app.set('view engine', 'tmpl');
|
||||
|
||||
app.use(function(req, res){
|
||||
res.render(__dirname + '/fixtures/user');
|
||||
res.render(path.join(__dirname, 'fixtures', 'user'))
|
||||
});
|
||||
|
||||
request(app)
|
||||
@ -40,7 +41,7 @@ describe('res', function(){
|
||||
app.locals.user = { name: 'tobi' };
|
||||
|
||||
app.use(function(req, res){
|
||||
res.render(__dirname + '/fixtures/user');
|
||||
res.render(path.join(__dirname, 'fixtures', 'user'))
|
||||
});
|
||||
|
||||
request(app)
|
||||
@ -51,7 +52,7 @@ describe('res', function(){
|
||||
it('should expose app.locals', function(done){
|
||||
var app = createApp();
|
||||
|
||||
app.set('views', __dirname + '/fixtures');
|
||||
app.set('views', path.join(__dirname, 'fixtures'))
|
||||
app.locals.user = { name: 'tobi' };
|
||||
|
||||
app.use(function(req, res){
|
||||
@ -66,7 +67,7 @@ describe('res', function(){
|
||||
it('should expose app.locals with `name` property', function(done){
|
||||
var app = createApp();
|
||||
|
||||
app.set('views', __dirname + '/fixtures');
|
||||
app.set('views', path.join(__dirname, 'fixtures'))
|
||||
app.locals.name = 'tobi';
|
||||
|
||||
app.use(function(req, res){
|
||||
@ -81,7 +82,7 @@ describe('res', function(){
|
||||
it('should support index.<engine>', function(done){
|
||||
var app = createApp();
|
||||
|
||||
app.set('views', __dirname + '/fixtures');
|
||||
app.set('views', path.join(__dirname, 'fixtures'))
|
||||
app.set('view engine', 'tmpl');
|
||||
|
||||
app.use(function(req, res){
|
||||
@ -97,7 +98,7 @@ describe('res', function(){
|
||||
it('should next(err)', function(done){
|
||||
var app = createApp();
|
||||
|
||||
app.set('views', __dirname + '/fixtures');
|
||||
app.set('views', path.join(__dirname, 'fixtures'))
|
||||
|
||||
app.use(function(req, res){
|
||||
res.render('user.tmpl');
|
||||
@ -118,7 +119,7 @@ describe('res', function(){
|
||||
var app = createApp();
|
||||
|
||||
app.set('view engine', 'tmpl');
|
||||
app.set('views', __dirname + '/fixtures');
|
||||
app.set('views', path.join(__dirname, 'fixtures'))
|
||||
|
||||
app.use(function(req, res){
|
||||
res.render('email');
|
||||
@ -134,7 +135,7 @@ describe('res', function(){
|
||||
it('should lookup the file in the path', function(done){
|
||||
var app = createApp();
|
||||
|
||||
app.set('views', __dirname + '/fixtures/default_layout');
|
||||
app.set('views', path.join(__dirname, 'fixtures', 'default_layout'))
|
||||
|
||||
app.use(function(req, res){
|
||||
res.render('user.tmpl', { user: { name: 'tobi' } });
|
||||
@ -148,7 +149,10 @@ describe('res', function(){
|
||||
describe('when array of paths', function(){
|
||||
it('should lookup the file in the path', function(done){
|
||||
var app = createApp();
|
||||
var views = [__dirname + '/fixtures/local_layout', __dirname + '/fixtures/default_layout'];
|
||||
var views = [
|
||||
path.join(__dirname, 'fixtures', 'local_layout'),
|
||||
path.join(__dirname, 'fixtures', 'default_layout')
|
||||
]
|
||||
|
||||
app.set('views', views);
|
||||
|
||||
@ -163,7 +167,10 @@ describe('res', function(){
|
||||
|
||||
it('should lookup in later paths until found', function(done){
|
||||
var app = createApp();
|
||||
var views = [__dirname + '/fixtures/local_layout', __dirname + '/fixtures/default_layout'];
|
||||
var views = [
|
||||
path.join(__dirname, 'fixtures', 'local_layout'),
|
||||
path.join(__dirname, 'fixtures', 'default_layout')
|
||||
]
|
||||
|
||||
app.set('views', views);
|
||||
|
||||
@ -183,7 +190,7 @@ describe('res', function(){
|
||||
it('should render the template', function(done){
|
||||
var app = createApp();
|
||||
|
||||
app.set('views', __dirname + '/fixtures');
|
||||
app.set('views', path.join(__dirname, 'fixtures'))
|
||||
|
||||
var user = { name: 'tobi' };
|
||||
|
||||
@ -199,7 +206,7 @@ describe('res', function(){
|
||||
it('should expose app.locals', function(done){
|
||||
var app = createApp();
|
||||
|
||||
app.set('views', __dirname + '/fixtures');
|
||||
app.set('views', path.join(__dirname, 'fixtures'))
|
||||
app.locals.user = { name: 'tobi' };
|
||||
|
||||
app.use(function(req, res){
|
||||
@ -214,7 +221,7 @@ describe('res', function(){
|
||||
it('should expose res.locals', function(done){
|
||||
var app = createApp();
|
||||
|
||||
app.set('views', __dirname + '/fixtures');
|
||||
app.set('views', path.join(__dirname, 'fixtures'))
|
||||
|
||||
app.use(function(req, res){
|
||||
res.locals.user = { name: 'tobi' };
|
||||
@ -229,7 +236,7 @@ describe('res', function(){
|
||||
it('should give precedence to res.locals over app.locals', function(done){
|
||||
var app = createApp();
|
||||
|
||||
app.set('views', __dirname + '/fixtures');
|
||||
app.set('views', path.join(__dirname, 'fixtures'))
|
||||
app.locals.user = { name: 'tobi' };
|
||||
|
||||
app.use(function(req, res){
|
||||
@ -245,7 +252,7 @@ describe('res', function(){
|
||||
it('should give precedence to res.render() locals over res.locals', function(done){
|
||||
var app = createApp();
|
||||
|
||||
app.set('views', __dirname + '/fixtures');
|
||||
app.set('views', path.join(__dirname, 'fixtures'))
|
||||
var jane = { name: 'jane' };
|
||||
|
||||
app.use(function(req, res){
|
||||
@ -261,7 +268,7 @@ describe('res', function(){
|
||||
it('should give precedence to res.render() locals over app.locals', function(done){
|
||||
var app = createApp();
|
||||
|
||||
app.set('views', __dirname + '/fixtures');
|
||||
app.set('views', path.join(__dirname, 'fixtures'))
|
||||
app.locals.user = { name: 'tobi' };
|
||||
var jane = { name: 'jane' };
|
||||
|
||||
@ -279,7 +286,7 @@ describe('res', function(){
|
||||
it('should pass the resulting string', function(done){
|
||||
var app = createApp();
|
||||
|
||||
app.set('views', __dirname + '/fixtures');
|
||||
app.set('views', path.join(__dirname, 'fixtures'))
|
||||
|
||||
app.use(function(req, res){
|
||||
var tobi = { name: 'tobi' };
|
||||
@ -299,7 +306,7 @@ describe('res', function(){
|
||||
it('should pass the resulting string', function(done){
|
||||
var app = createApp();
|
||||
|
||||
app.set('views', __dirname + '/fixtures');
|
||||
app.set('views', path.join(__dirname, 'fixtures'))
|
||||
|
||||
app.use(function(req, res){
|
||||
res.locals.user = { name: 'tobi' };
|
||||
@ -318,7 +325,7 @@ describe('res', function(){
|
||||
it('should pass it to the callback', function(done){
|
||||
var app = createApp();
|
||||
|
||||
app.set('views', __dirname + '/fixtures');
|
||||
app.set('views', path.join(__dirname, 'fixtures'))
|
||||
|
||||
app.use(function(req, res){
|
||||
res.render('user.tmpl', function (err) {
|
||||
|
@ -613,7 +613,7 @@ describe('res', function(){
|
||||
var app = express();
|
||||
|
||||
app.use(function(req, res){
|
||||
res.sendfile(__dirname + '/fixtures/user.html');
|
||||
res.sendfile(path.join(__dirname, '/fixtures/user.html'))
|
||||
});
|
||||
|
||||
request(app)
|
||||
@ -718,7 +718,7 @@ describe('res', function(){
|
||||
, calls = 0;
|
||||
|
||||
app.use(function(req, res){
|
||||
res.sendfile(__dirname + '/fixtures/name.txt');
|
||||
res.sendfile(path.join(__dirname, '/fixtures/name.txt'))
|
||||
});
|
||||
|
||||
request(app)
|
||||
|
Loading…
Reference in New Issue
Block a user