ejs tests
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Tj Holowaychuk · committed by Tj Holowaychuk · parent 29ef828 · Browse files · 6 files·+116 added−95 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
6 files+116 added−95 removed
- tests:+19 added−1 removed
- other:+97 added−94 removed
Provenance
- Commit
3b6e96e- Tree
58eaaf3- Author
Tj Holowaychuk <tj@vision-media.ca>- Committer
Tj Holowaychuk <tj@vision-media.ca>- Parent
29ef828
6 files changed+116 added−95 removed
deleted:examples/content-negotiation/app.js-54 removed
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
/** * Module dependencies. */
var express = require('../../');
// expose the app for require()ingvar app = module.exports = express();
var users = [ { name: 'tobi' } , { name: 'loki' } , { name: 'jane' }];
function provides(type) { return function(req, res, next){ if (req.accepts(type)) return next(); // invoking next() with "route" will // skip passed all remaining middleware // for this route (if any). next('route'); }}
// curl http://localhost:3000/users -H "Accept: application/json"
app.get('/users', provides('json'), function(req, res){ res.send(users);});
// curl http://localhost:3000/users -H "Accept: text/html"
app.get('/users', provides('html'), function(req, res){ res.send('<ul>' + users.map(function(user){ return '<li>' + user.name + '</li>'; }).join('\n') + '</ul>');});
// curl http://localhost:3000/users -H "Accept: text/plain"
app.get('/users', function(req, res, next){ res.type('txt'); res.send(users.map(function(user){ return user.name; }).join(', '));});
// not being require()dif (!module.parent) { app.listen(3000); console.log('Express server listening on port 3000');}added:examples/content-negotiation/index.js+54 added
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
/** * Module dependencies. */
var express = require('../../');
// expose the app for require()ingvar app = module.exports = express();
var users = [ { name: 'tobi' } , { name: 'loki' } , { name: 'jane' }];
function provides(type) { return function(req, res, next){ if (req.accepts(type)) return next(); // invoking next() with "route" will // skip passed all remaining middleware // for this route (if any). next('route'); }}
// curl http://localhost:3000/users -H "Accept: application/json"
app.get('/users', provides('json'), function(req, res){ res.send(users);});
// curl http://localhost:3000/users -H "Accept: text/html"
app.get('/users', provides('html'), function(req, res){ res.send('<ul>' + users.map(function(user){ return '<li>' + user.name + '</li>'; }).join('\n') + '</ul>');});
// curl http://localhost:3000/users -H "Accept: text/plain"
app.get('/users', function(req, res, next){ res.type('txt'); res.send(users.map(function(user){ return user.name; }).join(', '));});
// not being require()dif (!module.parent) { app.listen(3000); console.log('Express server listening on port 3000');}deleted:examples/ejs/app.js-40 removed
12345678910111213141516171819202122232425262728293031323334353637383940
/** * Module dependencies. */
var express = require('../../') , app = express();
// Register ejs as .html. If we did// not call this, we would need to// name our views foo.ejs instead// of foo.html. The __express method// is simply a function that engines// use to hook into the Express view// system
app.engine('.html', require('ejs').__express);
// Optional since express defaults to CWD/views
app.set('views', __dirname + '/views');
// Without this you would need to// supply the extension to res.render()// ex: res.render('users.html').app.set('view engine', 'html');
// Dummy usersvar users = [ { name: 'tj', email: 'tj@sencha.com' } , { name: 'ciaran', email: 'ciaranj@gmail.com' } , { name: 'aaron', email: 'aaron.heckmann+github@gmail.com' }];
app.get('/', function(req, res){ res.render('users', { users: users });});
app.listen(3000);console.log('Express app started on port 3000');No newline at end of fileadded:examples/ejs/index.js+43 added
12345678910111213141516171819202122232425262728293031323334353637383940414243
/** * Module dependencies. */
var express = require('../../');
var app = module.exports = express();
// Register ejs as .html. If we did// not call this, we would need to// name our views foo.ejs instead// of foo.html. The __express method// is simply a function that engines// use to hook into the Express view// system
app.engine('.html', require('ejs').__express);
// Optional since express defaults to CWD/views
app.set('views', __dirname + '/views');
// Without this you would need to// supply the extension to res.render()// ex: res.render('users.html').app.set('view engine', 'html');
// Dummy usersvar users = [ { name: 'tj', email: 'tj@sencha.com' } , { name: 'ciaran', email: 'ciaranj@gmail.com' } , { name: 'aaron', email: 'aaron.heckmann+github@gmail.com' }];
app.get('/', function(req, res){ res.render('users', { users: users });});
if (!module.parent) { app.listen(3000); console.log('Express app started on port 3000');}No newline at end of filemodified:test/acceptance/content-negotiation.js+1 added-1 removed
1233456747 unmodified lines
var request = require('../support/http') , app = require('../../examples/content-negotiation/app'); , app = require('../../examples/content-negotiation');
describe('content-negotiation', function(){ describe('GET /users', function(){ it('should support json', function(done){47 unmodified linesadded:test/acceptance/ejs.js+18 added
123456789101112131415161718
var request = require('../support/http') , app = require('../../examples/ejs');
describe('ejs', function(){ describe('GET /', function(){ it('should respond with html', function(done){ request(app) .get('/') .end(function(res){ res.should.have.status(200); res.should.have.header('Content-Type', 'text.html; charset=utf-8'); res.body.should.equal(''); done(); }); }) })})No newline at end of file