tests: use path.join instead of concatenation
Before adoption: this commit came in with the history the project adopted, so no landing records it.
closes #3236
authored by chainhelen · committed by Douglas Christopher Wilson · parent 8eb95ae · Browse files · 4 files·+64 added−43 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
4 files+64 added−43 removed
- tests:+64 added−43 removed
Provenance
- Commit
eece385- Tree
1b71375- Author
chainhelen <chainhelen@gmail.com>- Committer
Douglas Christopher Wilson <doug@somethingdoug.com>- Parent
8eb95ae
4 files changed+64 added−43 removed
modified:test/app.engine.js+5 added-4 removed
123456786 unmodified lines1516171818192021222312 unmodified lines363738393940414243445 unmodified lines505152535354555657586 unmodified lines656667686869707172738 unmodified lines
var express = require('../') , fs = require('fs');var path = require('path')
function render(path, options, fn) { fs.readFile(path, 'utf8', function(err, str){ if (err) return fn(err);6 unmodified lines describe('.engine(ext, fn)', 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' };
app.render('user.html', function(err, str){12 unmodified lines
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' };
app.render('user.html', function(err, str){5 unmodified lines 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' };
6 unmodified lines 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' };
8 unmodified linesmodified:test/app.render.js+30 added-17 removed
1 2+var assert = require('assert')3 var express = require('..');4+var path = require('path')5 var tmpl = require('./support/tmpl');6 7 describe('app', function(){8 describe('.render(name, fn)', function(){1 unmodified line10 var app = createApp();11 12 app.locals.user = { name: 'tobi' };13 12- app.render(__dirname + '/fixtures/user.tmpl', function (err, str) {14+ app.render(path.join(__dirname, 'fixtures', 'user.tmpl'), function (err, str) {15 if (err) return done(err);16 str.should.equal('<p>tobi</p>');17 done();18 })4 unmodified lines23 24 app.set('view engine', 'tmpl');25 app.locals.user = { name: 'tobi' };26 25- app.render(__dirname + '/fixtures/user', function(err, str){27+ app.render(path.join(__dirname, 'fixtures', 'user'), function (err, str) {28 if (err) return done(err);29 str.should.equal('<p>tobi</p>');30 done();31 })1 unmodified line33 34 it('should expose app.locals', function(done){35 var app = createApp();36 35- app.set('views', __dirname + '/fixtures');37+ app.set('views', path.join(__dirname, 'fixtures'))38 app.locals.user = { name: 'tobi' };39 40 app.render('user.tmpl', function (err, str) {41 if (err) return done(err);4 unmodified lines46 47 it('should support index.<engine>', function(done){48 var app = createApp();49 48- app.set('views', __dirname + '/fixtures');50+ app.set('views', path.join(__dirname, 'fixtures'))51 app.set('view engine', 'tmpl');52 53 app.render('blog/post', function (err, str) {54 if (err) return done(err);26 unmodified lines81 describe('when the file does not exist', function(){82 it('should provide a helpful error', function(done){83 var app = createApp();84 83- app.set('views', __dirname + '/fixtures');85+ app.set('views', path.join(__dirname, 'fixtures'))86 app.render('rawr.tmpl', function (err) {85- err.message.should.equal('Failed to lookup view "rawr.tmpl" in views directory "' + __dirname + '/fixtures"');87+ assert.ok(err)88+ assert.equal(err.message, 'Failed to lookup view "rawr.tmpl" in views directory "' + path.join(__dirname, 'fixtures') + '"')89 done();90 });91 })92 })1 unmodified line94 describe('when an error occurs', function(){95 it('should invoke the callback', function(done){96 var app = createApp();97 95- app.set('views', __dirname + '/fixtures');98+ app.set('views', path.join(__dirname, 'fixtures'))99 100 app.render('user.tmpl', function (err, str) {101 // nextTick to prevent cyclic102 process.nextTick(function(){7 unmodified lines110 describe('when an extension is given', function(){111 it('should render the template', function(done){112 var app = createApp();113 111- app.set('views', __dirname + '/fixtures');114+ app.set('views', path.join(__dirname, 'fixtures'))115 116 app.render('email.tmpl', function (err, str) {117 if (err) return done(err);118 str.should.equal('<p>This is an email</p>');6 unmodified lines125 it('should render the template', function(done){126 var app = createApp();127 128 app.set('view engine', 'tmpl');126- app.set('views', __dirname + '/fixtures');129+ app.set('views', path.join(__dirname, 'fixtures'))130 131 app.render('email', function(err, str){132 if (err) return done(err);133 str.should.equal('<p>This is an email</p>');5 unmodified lines139 describe('when "views" is given', function(){140 it('should lookup the file in the path', function(done){141 var app = createApp();142 140- app.set('views', __dirname + '/fixtures/default_layout');143+ app.set('views', path.join(__dirname, 'fixtures', 'default_layout'))144 app.locals.user = { name: 'tobi' };145 146 app.render('user.tmpl', function (err, str) {147 if (err) return done(err);4 unmodified lines152 153 describe('when array of paths', function(){154 it('should lookup the file in the path', function(done){155 var app = createApp();153- var views = [__dirname + '/fixtures/local_layout', __dirname + '/fixtures/default_layout'];156+ var views = [157+ path.join(__dirname, 'fixtures', 'local_layout'),158+ path.join(__dirname, 'fixtures', 'default_layout')159+ ]160 161 app.set('views', views);162 app.locals.user = { name: 'tobi' };163 5 unmodified lines169 })170 171 it('should lookup in later paths until found', function(done){172 var app = createApp();167- var views = [__dirname + '/fixtures/local_layout', __dirname + '/fixtures/default_layout'];173+ var views = [174+ path.join(__dirname, 'fixtures', 'local_layout'),175+ path.join(__dirname, 'fixtures', 'default_layout')176+ ]177 178 app.set('views', views);179 app.locals.name = 'tobi';180 5 unmodified lines186 })187 188 it('should error if file does not exist', function(done){189 var app = createApp();181- var views = [__dirname + '/fixtures/local_layout', __dirname + '/fixtures/default_layout'];190+ var views = [191+ path.join(__dirname, 'fixtures', 'local_layout'),192+ path.join(__dirname, 'fixtures', 'default_layout')193+ ]194 195 app.set('views', views);196 app.locals.name = 'tobi';197 198 app.render('pet.tmpl', function (err, str) {187- err.message.should.equal('Failed to lookup view "pet.tmpl" in views directories "' + __dirname + '/fixtures/local_layout" or "' + __dirname + '/fixtures/default_layout"');199+ assert.ok(err)200+ assert.equal(err.message, 'Failed to lookup view "pet.tmpl" in views directories "' + views[0] + '" or "' + views[1] + '"')201 done();202 })203 })204 })88 unmodified lines293 describe('.render(name, options, fn)', function(){294 it('should render the template', function(done){295 var app = createApp();296 284- app.set('views', __dirname + '/fixtures');297+ app.set('views', path.join(__dirname, 'fixtures'))298 299 var user = { name: 'tobi' };300 301 app.render('user.tmpl', { user: user }, function (err, str) {5 unmodified lines307 308 it('should expose app.locals', function(done){309 var app = createApp();310 298- app.set('views', __dirname + '/fixtures');311+ app.set('views', path.join(__dirname, 'fixtures'))312 app.locals.user = { name: 'tobi' };313 314 app.render('user.tmpl', {}, function (err, str) {315 if (err) return done(err);4 unmodified lines320 321 it('should give precedence to app.render() locals', function(done){322 var app = createApp();323 311- app.set('views', __dirname + '/fixtures');324+ app.set('views', path.join(__dirname, 'fixtures'))325 app.locals.user = { name: 'tobi' };326 var jane = { name: 'jane' };327 328 app.render('user.tmpl', { user: jane }, function (err, str) {47 unmodified linesmodified:test/res.render.js+27 added-20 removed
1 2 var express = require('..');3+var path = require('path')4 var request = require('supertest');5 var tmpl = require('./support/tmpl');6 7 describe('res', function(){3 unmodified lines11 12 app.locals.user = { name: 'tobi' };13 14 app.use(function(req, res){14- res.render(__dirname + '/fixtures/user.tmpl');15+ res.render(path.join(__dirname, 'fixtures', 'user.tmpl'))16 });17 18 request(app)19 .get('/')6 unmodified lines26 app.locals.user = { name: 'tobi' };27 app.set('view engine', 'tmpl');28 29 app.use(function(req, res){29- res.render(__dirname + '/fixtures/user');30+ res.render(path.join(__dirname, 'fixtures', 'user'))31 });32 33 request(app)34 .get('/')5 unmodified lines40 41 app.locals.user = { name: 'tobi' };42 43 app.use(function(req, res){43- res.render(__dirname + '/fixtures/user');44+ res.render(path.join(__dirname, 'fixtures', 'user'))45 });46 47 request(app)48 .get('/')2 unmodified lines51 52 it('should expose app.locals', function(done){53 var app = createApp();54 54- app.set('views', __dirname + '/fixtures');55+ app.set('views', path.join(__dirname, 'fixtures'))56 app.locals.user = { name: 'tobi' };57 58 app.use(function(req, res){59 res.render('user.tmpl');6 unmodified lines66 67 it('should expose app.locals with `name` property', function(done){68 var app = createApp();69 69- app.set('views', __dirname + '/fixtures');70+ app.set('views', path.join(__dirname, 'fixtures'))71 app.locals.name = 'tobi';72 73 app.use(function(req, res){74 res.render('name.tmpl');6 unmodified lines81 82 it('should support index.<engine>', function(done){83 var app = createApp();84 84- app.set('views', __dirname + '/fixtures');85+ app.set('views', path.join(__dirname, 'fixtures'))86 app.set('view engine', 'tmpl');87 88 app.use(function(req, res){89 res.render('blog/post');7 unmodified lines97 describe('when an error occurs', function(){98 it('should next(err)', function(done){99 var app = createApp();100 100- app.set('views', __dirname + '/fixtures');101+ app.set('views', path.join(__dirname, 'fixtures'))102 103 app.use(function(req, res){104 res.render('user.tmpl');105 });12 unmodified lines118 it('should render the template', function(done){119 var app = createApp();120 121 app.set('view engine', 'tmpl');121- app.set('views', __dirname + '/fixtures');122+ app.set('views', path.join(__dirname, 'fixtures'))123 124 app.use(function(req, res){125 res.render('email');126 });7 unmodified lines134 describe('when "views" is given', function(){135 it('should lookup the file in the path', function(done){136 var app = createApp();137 137- app.set('views', __dirname + '/fixtures/default_layout');138+ app.set('views', path.join(__dirname, 'fixtures', 'default_layout'))139 140 app.use(function(req, res){141 res.render('user.tmpl', { user: { name: 'tobi' } });142 });5 unmodified lines148 149 describe('when array of paths', function(){150 it('should lookup the file in the path', function(done){151 var app = createApp();151- var views = [__dirname + '/fixtures/local_layout', __dirname + '/fixtures/default_layout'];152+ var views = [153+ path.join(__dirname, 'fixtures', 'local_layout'),154+ path.join(__dirname, 'fixtures', 'default_layout')155+ ]156 157 app.set('views', views);158 159 app.use(function(req, res){6 unmodified lines166 })167 168 it('should lookup in later paths until found', function(done){169 var app = createApp();166- var views = [__dirname + '/fixtures/local_layout', __dirname + '/fixtures/default_layout'];170+ var views = [171+ path.join(__dirname, 'fixtures', 'local_layout'),172+ path.join(__dirname, 'fixtures', 'default_layout')173+ ]174 175 app.set('views', views);176 177 app.use(function(req, res){11 unmodified lines189 describe('.render(name, option)', function(){190 it('should render the template', function(done){191 var app = createApp();192 186- app.set('views', __dirname + '/fixtures');193+ app.set('views', path.join(__dirname, 'fixtures'))194 195 var user = { name: 'tobi' };196 197 app.use(function(req, res){7 unmodified lines205 206 it('should expose app.locals', function(done){207 var app = createApp();208 202- app.set('views', __dirname + '/fixtures');209+ app.set('views', path.join(__dirname, 'fixtures'))210 app.locals.user = { name: 'tobi' };211 212 app.use(function(req, res){213 res.render('user.tmpl');6 unmodified lines220 221 it('should expose res.locals', function(done){222 var app = createApp();223 217- app.set('views', __dirname + '/fixtures');224+ app.set('views', path.join(__dirname, 'fixtures'))225 226 app.use(function(req, res){227 res.locals.user = { name: 'tobi' };228 res.render('user.tmpl');6 unmodified lines235 236 it('should give precedence to res.locals over app.locals', function(done){237 var app = createApp();238 232- app.set('views', __dirname + '/fixtures');239+ app.set('views', path.join(__dirname, 'fixtures'))240 app.locals.user = { name: 'tobi' };241 242 app.use(function(req, res){243 res.locals.user = { name: 'jane' };7 unmodified lines251 252 it('should give precedence to res.render() locals over res.locals', function(done){253 var app = createApp();254 248- app.set('views', __dirname + '/fixtures');255+ app.set('views', path.join(__dirname, 'fixtures'))256 var jane = { name: 'jane' };257 258 app.use(function(req, res){259 res.locals.user = { name: 'tobi' };7 unmodified lines267 268 it('should give precedence to res.render() locals over app.locals', function(done){269 var app = createApp();270 264- app.set('views', __dirname + '/fixtures');271+ app.set('views', path.join(__dirname, 'fixtures'))272 app.locals.user = { name: 'tobi' };273 var jane = { name: 'jane' };274 275 app.use(function(req, res){9 unmodified lines285 describe('.render(name, options, fn)', function(){286 it('should pass the resulting string', function(done){287 var app = createApp();288 282- app.set('views', __dirname + '/fixtures');289+ app.set('views', path.join(__dirname, 'fixtures'))290 291 app.use(function(req, res){292 var tobi = { name: 'tobi' };293 res.render('user.tmpl', { user: tobi }, function (err, html) {11 unmodified lines305 describe('.render(name, fn)', function(){306 it('should pass the resulting string', function(done){307 var app = createApp();308 302- app.set('views', __dirname + '/fixtures');309+ app.set('views', path.join(__dirname, 'fixtures'))310 311 app.use(function(req, res){312 res.locals.user = { name: 'tobi' };313 res.render('user.tmpl', function (err, html) {10 unmodified lines324 describe('when an error occurs', function(){325 it('should pass it to the callback', function(done){326 var app = createApp();327 321- app.set('views', __dirname + '/fixtures');328+ app.set('views', path.join(__dirname, 'fixtures'))329 330 app.use(function(req, res){331 res.render('user.tmpl', function (err) {332 res.end(err.message);18 unmodified linesmodified:test/res.sendFile.js+2 added-2 removed
611 unmodified lines612 it('should transfer the file', function(done){613 var app = express();614 615 app.use(function(req, res){616- res.sendfile(__dirname + '/fixtures/user.html');616+ res.sendfile(path.join(__dirname, '/fixtures/user.html'))617 });618 619 request(app)620 .get('/')96 unmodified lines717 var app = express()718 , calls = 0;719 720 app.use(function(req, res){721- res.sendfile(__dirname + '/fixtures/name.txt');721+ res.sendfile(path.join(__dirname, '/fixtures/name.txt'))722 });723 724 request(app)725 .get('/')30 unmodified lines