Skip to content

Commit

Permalink
tests: use path.join instead of concatenation
Browse files Browse the repository at this point in the history
closes #3236
  • Loading branch information
chainhelen authored and dougwilson committed Mar 6, 2017
1 parent 8eb95ae commit eece385
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 43 deletions.
9 changes: 5 additions & 4 deletions test/app.engine.js
Original file line number Diff line number Diff line change
@@ -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){
Expand All @@ -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' };

Expand All @@ -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' };

Expand All @@ -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' };
Expand All @@ -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' };
Expand Down
47 changes: 30 additions & 17 deletions test/app.render.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@

var assert = require('assert')
var express = require('..');
var path = require('path')
var tmpl = require('./support/tmpl');

describe('app', function(){
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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();
});
})
Expand All @@ -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
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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) {
Expand All @@ -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' };
Expand All @@ -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';
Expand All @@ -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();
})
})
Expand Down Expand Up @@ -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' };

Expand All @@ -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) {
Expand All @@ -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' };

Expand Down
Loading

0 comments on commit eece385

Please sign in to comment.