diff --git a/History.md b/History.md index 54dafd3b02..fe16da7a40 100644 --- a/History.md +++ b/History.md @@ -1,3 +1,8 @@ +5.x +=== + +This incorporates all changes after 4.15.0 up to 4.15.2. + 5.0.0-alpha.4 / 2017-03-01 ========================== @@ -70,6 +75,22 @@ This is the first Express 5.0 alpha release, based off 4.10.1. * add: - `app.router` is a reference to the base router +4.15.2 / 2017-03-06 +=================== + + * deps: qs@6.4.0 + - Fix regression parsing keys starting with `[` + +4.15.1 / 2017-03-05 +=================== + + * deps: send@0.15.1 + - Fix issue when `Date.parse` does not return `NaN` on invalid date + - Fix strict violation in broken environments + * deps: serve-static@1.12.1 + - Fix issue when `Date.parse` does not return `NaN` on invalid date + - deps: send@0.15.1 + 4.15.0 / 2017-03-01 =================== diff --git a/examples/auth/index.js b/examples/auth/index.js index 1c3ca21751..084fba79a9 100644 --- a/examples/auth/index.js +++ b/examples/auth/index.js @@ -5,6 +5,7 @@ var express = require('../..'); var bodyParser = require('body-parser'); var hash = require('pbkdf2-password')() +var path = require('path'); var session = require('express-session'); var app = module.exports = express(); @@ -12,7 +13,7 @@ var app = module.exports = express(); // config app.set('view engine', 'ejs'); -app.set('views', __dirname + '/views'); +app.set('views', path.join(__dirname, 'views')); // middleware diff --git a/examples/downloads/index.js b/examples/downloads/index.js index 6ab6ba0213..e6f3fa9db6 100644 --- a/examples/downloads/index.js +++ b/examples/downloads/index.js @@ -3,6 +3,7 @@ */ var express = require('../../'); +var path = require('path'); var app = module.exports = express(); app.get('/', function(req, res){ @@ -16,10 +17,9 @@ app.get('/', function(req, res){ // /files/* is accessed via req.params[0] // but here we name it :file app.get('/files/:file(*)', function(req, res, next){ - var file = req.params.file; - var path = __dirname + '/files/' + file; + var filePath = path.join(__dirname, 'files', req.params.file); - res.download(path, function(err){ + res.download(filePath, function (err) { if (!err) return; // file sent if (err && err.status !== 404) return next(err); // non-404 error // file for download not found diff --git a/examples/ejs/index.js b/examples/ejs/index.js index bf78a9cc80..b868bdd7cb 100644 --- a/examples/ejs/index.js +++ b/examples/ejs/index.js @@ -3,6 +3,7 @@ */ var express = require('../../'); +var path = require('path'); var app = module.exports = express(); @@ -21,7 +22,11 @@ app.engine('.html', require('ejs').__express); // Optional since express defaults to CWD/views -app.set('views', __dirname + '/views'); +app.set('views', path.join(__dirname, 'views')); + +// Path to our public directory + +app.use(express.static(path.join(__dirname + 'public'))); // Without this you would need to // supply the extension to res.render() diff --git a/examples/jade/public/stylesheets/style.css b/examples/ejs/public/stylesheets/style.css similarity index 100% rename from examples/jade/public/stylesheets/style.css rename to examples/ejs/public/stylesheets/style.css diff --git a/examples/ejs/views/header.html b/examples/ejs/views/header.html index 8dbeb8d3c0..4396bc444f 100644 --- a/examples/ejs/views/header.html +++ b/examples/ejs/views/header.html @@ -2,12 +2,7 @@ - <%= title %> - + <%= title %> + diff --git a/examples/error-pages/index.js b/examples/error-pages/index.js index d1219689f2..790f6e30df 100644 --- a/examples/error-pages/index.js +++ b/examples/error-pages/index.js @@ -3,12 +3,13 @@ */ var express = require('../../'); +var path = require('path'); var app = module.exports = express(); var logger = require('morgan'); var silent = 'test' == process.env.NODE_ENV; // general config -app.set('views', __dirname + '/views'); +app.set('views', path.join(__dirname, 'views')); app.set('view engine', 'ejs'); // our custom "verbose errors" setting diff --git a/examples/jade/index.js b/examples/jade/index.js deleted file mode 100644 index 738b382d26..0000000000 --- a/examples/jade/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** - * Module dependencies. - */ - -var express = require('../../lib/express'); - -// Path to our public directory - -var pub = __dirname + '/public'; - -// setup middleware - -var app = express(); -app.use(express.static(pub)); - -// Optional since express defaults to CWD/views - -app.set('views', __dirname + '/views'); - -// Set our default template engine to "jade" -// which prevents the need for extensions -// (although you can still mix and match) -app.set('view engine', 'jade'); - -function User(name, email) { - this.name = name; - this.email = email; -} - -// Dummy users -var users = [ - new User('tj', 'tj@vision-media.ca') - , new User('ciaran', 'ciaranj@gmail.com') - , new User('aaron', 'aaron.heckmann+github@gmail.com') -]; - -app.get('/', function(req, res){ - res.render('users', { users: users }); -}); - -// change this to a better error handler in your code -// sending stacktrace to users in production is not good -app.use(function(err, req, res, next) { - res.send(err.stack); -}); - -/* istanbul ignore next */ -if (!module.parent) { - app.listen(3000); - console.log('Express started on port 3000'); -} diff --git a/examples/jade/views/header.jade b/examples/jade/views/header.jade deleted file mode 100644 index 6c42929d83..0000000000 --- a/examples/jade/views/header.jade +++ /dev/null @@ -1,3 +0,0 @@ -head - title Jade Example - link(rel="stylesheet", href="/stylesheets/style.css") \ No newline at end of file diff --git a/examples/jade/views/layout.jade b/examples/jade/views/layout.jade deleted file mode 100644 index 300cdc7847..0000000000 --- a/examples/jade/views/layout.jade +++ /dev/null @@ -1,5 +0,0 @@ -doctype html -html - include header - body - block content diff --git a/examples/jade/views/users/index.jade b/examples/jade/views/users/index.jade deleted file mode 100644 index feb7623fa3..0000000000 --- a/examples/jade/views/users/index.jade +++ /dev/null @@ -1,8 +0,0 @@ - -extends ../layout - -block content - h1 Users - #users - for user in users - include user \ No newline at end of file diff --git a/examples/jade/views/users/user.jade b/examples/jade/views/users/user.jade deleted file mode 100644 index 9e603298cb..0000000000 --- a/examples/jade/views/users/user.jade +++ /dev/null @@ -1,3 +0,0 @@ -.user - h2= user.name - .email= user.email \ No newline at end of file diff --git a/examples/markdown/index.js b/examples/markdown/index.js index 430628701f..df8c195fb4 100644 --- a/examples/markdown/index.js +++ b/examples/markdown/index.js @@ -6,6 +6,7 @@ var escapeHtml = require('escape-html'); var express = require('../..'); var fs = require('fs'); var marked = require('marked'); +var path = require('path'); var app = module.exports = express(); @@ -21,7 +22,7 @@ app.engine('md', function(path, options, fn){ }); }); -app.set('views', __dirname + '/views'); +app.set('views', path.join(__dirname, 'views')); // make it the default so we dont need .md app.set('view engine', 'md'); diff --git a/examples/mvc/index.js b/examples/mvc/index.js index bf7f726e30..c5e2678697 100644 --- a/examples/mvc/index.js +++ b/examples/mvc/index.js @@ -4,6 +4,7 @@ var express = require('../..'); var logger = require('morgan'); +var path = require('path'); var session = require('express-session'); var bodyParser = require('body-parser'); var methodOverride = require('method-override'); @@ -17,7 +18,7 @@ var app = module.exports = express(); app.set('view engine', 'jade'); // set views for error and 404 pages -app.set('views', __dirname + '/views'); +app.set('views', path.join(__dirname, 'views')); // define a custom res.message() method // which stores messages in the session @@ -34,7 +35,7 @@ app.response.message = function(msg){ if (!module.parent) app.use(logger('dev')); // serve static files -app.use(express.static(__dirname + '/public')); +app.use(express.static(path.join(__dirname, 'public'))); // session support app.use(session({ diff --git a/examples/mvc/lib/boot.js b/examples/mvc/lib/boot.js index a0ca6ec37b..422330dc06 100644 --- a/examples/mvc/lib/boot.js +++ b/examples/mvc/lib/boot.js @@ -4,23 +4,26 @@ var express = require('../../..'); var fs = require('fs'); +var path = require('path'); module.exports = function(parent, options){ + var dir = path.join(__dirname, '..', 'controllers'); var verbose = options.verbose; - fs.readdirSync(__dirname + '/../controllers').forEach(function(name){ - if (!fs.statSync(__dirname + '/../controllers/' + name).isDirectory()) return; + fs.readdirSync(dir).forEach(function(name){ + var file = path.join(dir, name) + if (!fs.statSync(file).isDirectory()) return; verbose && console.log('\n %s:', name); - var obj = require('./../controllers/' + name); + var obj = require(file); var name = obj.name || name; var prefix = obj.prefix || ''; var app = express(); var handler; var method; - var path; + var url; // allow specifying the view engine if (obj.engine) app.set('view engine', obj.engine); - app.set('views', __dirname + '/../controllers/' + name + '/views'); + app.set('views', path.join(__dirname, '..', 'controllers', name, 'views')); // generate routes based // on the exported methods @@ -31,27 +34,27 @@ module.exports = function(parent, options){ switch (key) { case 'show': method = 'get'; - path = '/' + name + '/:' + name + '_id'; + url = '/' + name + '/:' + name + '_id'; break; case 'list': method = 'get'; - path = '/' + name + 's'; + url = '/' + name + 's'; break; case 'edit': method = 'get'; - path = '/' + name + '/:' + name + '_id/edit'; + url = '/' + name + '/:' + name + '_id/edit'; break; case 'update': method = 'put'; - path = '/' + name + '/:' + name + '_id'; + url = '/' + name + '/:' + name + '_id'; break; case 'create': method = 'post'; - path = '/' + name; + url = '/' + name; break; case 'index': method = 'get'; - path = '/'; + url = '/'; break; default: /* istanbul ignore next */ @@ -60,15 +63,15 @@ module.exports = function(parent, options){ // setup handler = obj[key]; - path = prefix + path; + url = prefix + url; // before middleware support if (obj.before) { - app[method](path, obj.before, handler); - verbose && console.log(' %s %s -> before -> %s', method.toUpperCase(), path, key); + app[method](url, obj.before, handler); + verbose && console.log(' %s %s -> before -> %s', method.toUpperCase(), url, key); } else { - app[method](path, handler); - verbose && console.log(' %s %s -> %s', method.toUpperCase(), path, key); + app[method](url, handler); + verbose && console.log(' %s %s -> %s', method.toUpperCase(), url, key); } } diff --git a/examples/route-separation/index.js b/examples/route-separation/index.js index 3d93d5cfd9..c6605ada6c 100644 --- a/examples/route-separation/index.js +++ b/examples/route-separation/index.js @@ -3,6 +3,7 @@ */ var express = require('../..'); +var path = require('path'); var app = express(); var logger = require('morgan'); var cookieParser = require('cookie-parser'); @@ -17,7 +18,7 @@ module.exports = app; // Config app.set('view engine', 'jade'); -app.set('views', __dirname + '/views'); +app.set('views', path.join(__dirname, 'views')); /* istanbul ignore next */ if (!module.parent) { @@ -27,7 +28,7 @@ if (!module.parent) { app.use(methodOverride('_method')); app.use(cookieParser()); app.use(bodyParser.urlencoded({ extended: true })); -app.use(express.static(__dirname + '/public')); +app.use(express.static(path.join(__dirname, 'public'))); // General diff --git a/examples/search/index.js b/examples/search/index.js index 5775eb0ece..f34041771a 100644 --- a/examples/search/index.js +++ b/examples/search/index.js @@ -7,6 +7,7 @@ */ var express = require('../..'); +var path = require('path'); var redis = require('redis'); var db = redis.createClient(); @@ -15,8 +16,7 @@ var db = redis.createClient(); var app = express(); -app.set('view engine', 'jade'); -app.set('views', __dirname); +app.use(express.static(path.join(__dirname, 'public'))); // populate search @@ -26,14 +26,6 @@ db.sadd('ferret', 'jane'); db.sadd('cat', 'manny'); db.sadd('cat', 'luna'); -/** - * GET the search page. - */ - -app.get('/', function(req, res){ - res.render('search'); -}); - /** * GET search for :query. */ @@ -54,7 +46,7 @@ app.get('/search/:query?', function(req, res, next){ */ app.get('/client.js', function(req, res){ - res.sendFile(__dirname + '/client.js'); + res.sendFile(path.join(__dirname, 'client.js')); }); /* istanbul ignore next */ diff --git a/examples/search/client.js b/examples/search/public/client.js similarity index 100% rename from examples/search/client.js rename to examples/search/public/client.js diff --git a/examples/search/public/index.html b/examples/search/public/index.html new file mode 100644 index 0000000000..4a5540fdf3 --- /dev/null +++ b/examples/search/public/index.html @@ -0,0 +1,20 @@ + + + + + Search example + + + +

Search

+

Try searching for "ferret" or "cat".

+ +
+  
+
+
diff --git a/examples/search/search.jade b/examples/search/search.jade
deleted file mode 100644
index 37d77e434c..0000000000
--- a/examples/search/search.jade
+++ /dev/null
@@ -1,15 +0,0 @@
-doctype
-html
-  head
-    title Search example
-    style.
-      body {
-        font: 14px "Helvetica Neue", Helvetica;
-        padding: 50px;
-      }
-  body
-    h2 Search
-    p Try searching for "ferret" or "cat".
-    input(type='search')
-    pre
-    script(src='client.js')
diff --git a/lib/application.js b/lib/application.js
index 2406222866..eb52e47903 100644
--- a/lib/application.js
+++ b/lib/application.js
@@ -258,9 +258,9 @@ app.route = function route(path) {
  *
  * By default will `require()` the engine based on the
  * file extension. For example if you try to render
- * a "foo.jade" file Express will invoke the following internally:
+ * a "foo.ejs" file Express will invoke the following internally:
  *
- *     app.engine('jade', require('jade').__express);
+ *     app.engine('ejs', require('ejs').__express);
  *
  * For engines that do not provide `.__express` out of the box,
  * or if you wish to "map" a different extension to the template engine
diff --git a/package.json b/package.json
index 60abd540ca..ffd613debd 100644
--- a/package.json
+++ b/package.json
@@ -47,11 +47,11 @@
     "path-is-absolute": "1.0.1",
     "path-to-regexp": "0.1.7",
     "proxy-addr": "~1.1.3",
-    "qs": "6.3.1",
+    "qs": "6.4.0",
     "range-parser": "~1.2.0",
     "router": "~1.3.0",
-    "send": "0.15.0",
-    "serve-static": "1.12.0",
+    "send": "0.15.1",
+    "serve-static": "1.12.1",
     "setprototypeof": "1.0.3",
     "statuses": "~1.3.1",
     "type-is": "~1.6.14",
@@ -60,7 +60,7 @@
   },
   "devDependencies": {
     "after": "0.8.2",
-    "body-parser": "1.17.0",
+    "body-parser": "1.17.1",
     "cookie-parser": "~1.4.3",
     "ejs": "2.5.6",
     "express-session": "1.15.1",
diff --git a/test/app.engine.js b/test/app.engine.js
index 88311b2f6d..6d1ee1cacb 100644
--- a/test/app.engine.js
+++ b/test/app.engine.js
@@ -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' };
diff --git a/test/app.param.js b/test/app.param.js
index 7996995f88..3e2500e202 100644
--- a/test/app.param.js
+++ b/test/app.param.js
@@ -28,9 +28,8 @@ describe('app', function(){
 
       request(app)
       .get('/user/123')
-      .end(function(err, res){
-        res.text.should.equal('123');
-
+      .expect(200, '123', function (err) {
+        if (err) return done(err)
         request(app)
         .get('/post/123')
         .expect('123', done);
diff --git a/test/app.render.js b/test/app.render.js
index c9737b7a06..729b1c97cc 100644
--- a/test/app.render.js
+++ b/test/app.render.js
@@ -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('

tobi

'); 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('

tobi

'); 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.', 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' }; diff --git a/test/app.router.js b/test/app.router.js index 1ceafacfb9..7b1033536c 100644 --- a/test/app.router.js +++ b/test/app.router.js @@ -539,8 +539,8 @@ describe('app.router', function(){ request(app) .get('/user/10') - .end(function(err, res){ - res.statusCode.should.equal(200); + .expect(200, function (err) { + if (err) return done(err) request(app) .get('/user/tj') .expect(404, done); diff --git a/test/req.signedCookies.js b/test/req.signedCookies.js index 111a0f77df..73880b01b4 100644 --- a/test/req.signedCookies.js +++ b/test/req.signedCookies.js @@ -28,11 +28,7 @@ describe('req', function(){ request(app) .get('/') .set('Cookie', cookie) - .end(function(err, res){ - if (err) return done(err); - res.body.should.eql({ obj: { foo: 'bar' } }); - done(); - }); + .expect(200, { obj: { foo: 'bar' } }, done) }); }) }) diff --git a/test/res.clearCookie.js b/test/res.clearCookie.js index 92c9d049f0..4822057e92 100644 --- a/test/res.clearCookie.js +++ b/test/res.clearCookie.js @@ -13,11 +13,8 @@ describe('res', function(){ request(app) .get('/') - .end(function(err, res){ - var val = 'sid=; Path=/; Expires=Thu, 01 Jan 1970 00:00:00 GMT'; - res.header['set-cookie'].should.eql([val]); - done(); - }) + .expect('Set-Cookie', 'sid=; Path=/; Expires=Thu, 01 Jan 1970 00:00:00 GMT') + .expect(200, done) }) }) @@ -31,11 +28,8 @@ describe('res', function(){ request(app) .get('/') - .end(function(err, res){ - var val = 'sid=; Path=/admin; Expires=Thu, 01 Jan 1970 00:00:00 GMT'; - res.header['set-cookie'].should.eql([val]); - done(); - }) + .expect('Set-Cookie', 'sid=; Path=/admin; Expires=Thu, 01 Jan 1970 00:00:00 GMT') + .expect(200, done) }) }) }) diff --git a/test/res.cookie.js b/test/res.cookie.js index 543af99dcd..4eeaaf094a 100644 --- a/test/res.cookie.js +++ b/test/res.cookie.js @@ -16,11 +16,8 @@ describe('res', function(){ request(app) .get('/') - .end(function(err, res){ - var val = ['user=' + encodeURIComponent('j:{"name":"tobi"}') + '; Path=/']; - res.headers['set-cookie'].should.eql(val); - done(); - }) + .expect('Set-Cookie', 'user=j%3A%7B%22name%22%3A%22tobi%22%7D; Path=/') + .expect(200, done) }) }) @@ -34,11 +31,8 @@ describe('res', function(){ request(app) .get('/') - .end(function(err, res){ - var val = ['name=tobi; Path=/']; - res.headers['set-cookie'].should.eql(val); - done(); - }) + .expect('Set-Cookie', 'name=tobi; Path=/') + .expect(200, done) }) it('should allow multiple calls', function(done){ @@ -72,11 +66,8 @@ describe('res', function(){ request(app) .get('/') - .end(function(err, res){ - var val = ['name=tobi; Path=/; HttpOnly; Secure']; - res.headers['set-cookie'].should.eql(val); - done(); - }) + .expect('Set-Cookie', 'name=tobi; Path=/; HttpOnly; Secure') + .expect(200, done) }) describe('maxAge', function(){ @@ -178,11 +169,8 @@ describe('res', function(){ request(app) .get('/') - .end(function(err, res){ - var val = ['name=s%3Atobi.xJjV2iZ6EI7C8E5kzwbfA9PVLl1ZR07UTnuTgQQ4EnQ; Path=/']; - res.headers['set-cookie'].should.eql(val); - done(); - }) + .expect('Set-Cookie', 'name=s%3Atobi.xJjV2iZ6EI7C8E5kzwbfA9PVLl1ZR07UTnuTgQQ4EnQ; Path=/') + .expect(200, done) }) }) }) diff --git a/test/res.render.js b/test/res.render.js index d4d2a7616d..2e3a16f137 100644 --- a/test/res.render.js +++ b/test/res.render.js @@ -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.', 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) {