Skip to content
Myr

Merge branch 'integration'

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 · parents 6368ab4, 73caacb · Browse files · 44 files+823 added−325 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

44 files+823 added−325 removed

  • tests:+559 added−0 removed
  • other:+264 added−325 removed

44 files+823 added−325 removed

modified:examples/auth/views/login.ejs+1 added-1 removed
1<h1>Login</h1>2<%- message %>3Try accessing <a href="/restricted">/restricted</a>.3Try accessing <a href="/restricted">/restricted</a>, then authenticate with "tj" and "foobar".4<form method="post" action="/login">5 <p>6 <label>Username:</label>7 <input type="text" name="username">
9 unmodified lines
modified:examples/auth/app.js+26 added-33 removed
deleted:examples/blog/middleware/locals.js-31 removed
modified:examples/blog/models/post.js+3 added-3 removed
15 unmodified lines
16 fn();17};1819Post.prototype.validate = function(fn){20 if (!this.title) return fn(new Error('_title_ required'));21 if (!this.body) return fn(new Error('_body_ required'));20 if (!this.title) return fn(new Error('title required'));21 if (!this.body) return fn(new Error('body required'));22 if (this.body.length < 10) {23 return fn(new Error(24 '_body_ should be at least **10** characters long, was only _' + this.title.length + '_'));24 'body should be at least **10** characters long, was only ' + this.title.length));25 }26 fn();27};28
39 unmodified lines
modified:examples/blog/public/style.css+6 added-8 removed
modified:examples/blog/routes/post.js+7 added-6 removed
40 unmodified lines
41 * Save a post.42 */4344 app.post('/post', function(req, res){45 var data = req.body.post45 var data = req.body.post || {}46 , post = new Post(data.title, data.body);4747 48 post.validate(function(err){49 if (err) {50 req.flash('error', err.message);50 req.session.error = err.message;51 return res.redirect('back');52 }5354 post.save(function(err){55 req.flash('info', 'Successfully created post _%s_', post.title);55 req.session.message = 'Successfully created the post.';56 res.redirect('/post/' + post.id);57 }); 58 });59 });
21 unmodified lines
81 app.put('/post/:post', function(req, res, next){82 var post = req.post;83 post.validate(function(err){84 if (err) {85 req.flash('error', err.message);85 req.session.error = err.message;86 return res.redirect('back');87 }8889 post.update(req.body.post, function(err){90 if (err) return next(err);90 req.flash('info', 'Successfully updated post');91 req.session.message = 'Successfully updated post';92 res.redirect('back');93 });94 });95 });
1 unmodified line
modified:examples/blog/views/post/form.jade+19 added-17 removed
1extends ../layout23block content2- if (post.title)3 h1 Editing #{post.title}4- else5 h1 New Post4 if post.title5 h1 Editing #{post.title}6 else7 h1 New Post87!= messages()9 include ../messages109form#post(action=base + '/post' + (post.title ? '/' + post.id : ''), method='post')10 - if (post.title)11 input(type='hidden', name='_method', value='put')12 p13 label(for='post[title]') Title:14 input(type='text', name='post[title]', value=post.title)15 p16 label(for='post[body]') Body:17 textarea(name='post[body]')= post.body || ''18 p19 input(type='submit', value=post.title ? 'Update' : 'Create')20 11 form#post(action='/post' + (post.title ? '/' + post.id : ''), method='post')12 if post.title13 input(type='hidden', name='_method', value='put')14 p15 label(for='post[title]') Title:16 input(type='text', name='post[title]', value=post.title)17 p18 label(for='post[body]') Body:19 textarea(name='post[body]')= post.body || ''20 p21 input(type='submit', value=post.title ? 'Update' : 'Create')22
modified:examples/blog/views/post/index.jade+18 added-16 removed
1.post2 // title3 h24 = post.title5 a.edit(href=base + '/post/' + post.id + '/edit') Edit6 7 // flash messages8 != messages()9 10 // dates11 p.date.created Created at #{post.createdAt}12 - if (post.updatedAt)13 p.date.updated Updated at #{post.updatedAt}14 15 // body16 pre.body= post.body1extends ../layout23block content4 .post5 // title6 h27 = post.title8 a.edit(href='/post/' + post.id + '/edit') Edit9 10 include ../messages11 12 // dates13 p.date.created Created at #{post.createdAt}14 if post.updatedAt15 p.date.updated Updated at #{post.updatedAt}16 17 // body18 pre.body= post.body
modified:examples/blog/views/index.jade+20 added-17 removed
1h1 Blog1extends layout23!= messages()3block content4 h1 Blog56 if count7 p Display all #{count} post(s)5- if (count)6 p Display all #{count} post(s)7 #posts!= partial('post', posts)8- else9 p 10 | It looks like you have no posts!11 p12 | Click13 a(href=base + '/post/add') here 14 | to create a post. Login15 | as16 em "admin" 17 | and18 em "express"19 | .8 #posts9 each post in posts10 include post/index11 else12 p 13 | It looks like you have no posts!14 p15 | Click16 a(href='/post/add') here 17 | to create a post. Login18 | as19 em "admin" 20 | and21 em "express"22 | .
modified:examples/blog/views/layout.jade+3 added-2 removed
1!!! 52html3 head4 title Blog5 link(rel='stylesheet', href=base + '/style.css')5 link(rel='stylesheet', href='/style.css')6 body7 #container!= body7 #container8 block content
added:examples/blog/views/messages.jade+6 added
12if error3 p.error= error45if message6 p.message= message
modified:examples/blog/app.js+17 added-4 removed
2 unmodified lines
3 * Module dependencies.4 */56var express = require('../../')7 , app = express();7 , app = module.exports = express();89// config1011app.set('views', __dirname + '/views');12app.set('view engine', 'jade');1314// middleware1516app.configure(function(){16app.configure('development',function(){17 app.use(express.logger('dev'));18})1920app.configure(function(){21 app.use(express.bodyParser());22 app.use(express.methodOverride());23 app.use(express.cookieParser('keyboard cat'));24 app.use(express.session());22 app.use(require('./middleware/locals'));23 app.use(messages());25 app.use(app.router);26 app.use(express.static(__dirname + '/public'));27 app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));28});2930// Locals3132app.locals.use(function(req, res){33 // expose "error" and "message" to all34 // views that are rendered.35 res.locals.error = req.session.error || '';36 res.locals.message = req.session.message || '';37 // remove them so they're not displayed on subsequent renders38 delete req.session.error;39 delete req.session.message;40});4142// Routes4344require('./routes/site')(app);45require('./routes/post')(app);
5 unmodified lines
modified:examples/cookies/app.js+7 added-4 removed
2 unmodified lines
3 * Module dependencies.4 */56var express = require('../../')7 , app = express();7 , app = module.exports = express();8910// add favicon() before logger() so11// GET /favicon.ico requests are not
2 unmodified lines
14// call next()15app.use(express.favicon());1617// custom log format18if ('test' != process.env.NODE_ENV)18app.use(express.logger(':method :url'));19 app.use(express.logger(':method :url'));2021// parses request cookies, populating22// req.cookies and req.signedCookies23// when the secret is passed, used
23 unmodified lines
47 if (req.body.remember) res.cookie('remember', 1, { maxAge: minute });48 res.redirect('back');49});5051if (!module.parent){50app.listen(3000);51console.log('Express started on port 3000');52 app.listen(3000);53 console.log('Express started on port 3000');54}
modified:examples/downloads/app.js+9 added-7 removed
2 unmodified lines
3 * Module dependencies.4 */56var express = require('../../')7 , app = express();7 , app = module.exports = express();89app.get('/', function(req, res){10 res.send('<ul>'11 + '<li>Download <a href="/files/amazing.txt">amazing.txt</a>.</li>'
14 unmodified lines
26// below our routes, you will be able to27// "intercept" errors, otherwise Connect28// will respond with 500 "Internal Server Error".29app.use(function(err, req, res, next){30 // log all errors31 console.error(err.stack);3233 // special-case 404s30 // special-case 404s,31 // remember you could32 // render a 404 template here33 if (404 == err.status) {34 res.statusCode = 404;35 res.send('Cant find that file, sorry!');36 } else {37 next(err);38 }39});4041if (!module.parent) {41app.listen(3000);42console.log('Express started on port 3000');42 app.listen(3000);43 console.log('Express started on port 3000');44}
modified:examples/error/app.js+9 added-5 removed
2 unmodified lines
3 * Module dependencies.4 */56var express = require('../../')7 , app = express();7 , app = module.exports = express();89if ('test' != process.env.NODE_ENV)9app.use(express.logger('dev'));10 app.use(express.logger('dev'));11app.use(app.router);1213// the error handler is strategically14// placed *below* the app.router; if it
8 unmodified lines
23// in different orders etc.2425function error(err, req, res, next) {26 // log it27 if ('test' != process.env.NODE_ENV)26 console.error(err.stack);28 console.error(err.stack);2930 // respond with 500 "Internal Server Error".31 res.send(500);32}
9 unmodified lines
42 next(new Error('oh no!'));43 });44});4546if (!module.parent) {44app.listen(3000);45console.log('app listening on port 3000');47 app.listen(3000);48 console.log('Express started on port 3000');49}
modified:examples/error-pages/app.js+8 added-5 removed
2 unmodified lines
3 * Module dependencies.4 */56var express = require('../../')7 , app = express();7 , app = module.exports = express()8 , silent = 'test' == process.env.NODE_ENV;910app.set('views', __dirname + '/views');11app.set('view engine', 'jade');1213app.use(express.favicon());13app.use(express.logger('dev'));1415silent || app.use(express.logger('dev'));1617// "app.router" positions our routes 18// above the middleware defined below,19// this means that Express will attempt20// to match & call routes _before_ continuing
12 unmodified lines
3334app.use(function(req, res, next){35 // respond with html page36 if (req.accepts('html')) {35 console.log('test');37 res.status(404);38 res.render('404', { url: req.url });39 return;40 }
47 unmodified lines
88app.get('/500', function(req, res, next){89 next(new Error('keyboard cat!'));90});9192if (!module.parent) {91app.listen(3000);92console.log('Express app started on port 3000');93 app.listen(3000);94 silent || console.log('Express started on port 3000');95}
deleted:examples/flash/views/index.ejs-3 removed
1<h1>Flash Message Example</h1>2<p>on page <%- page %></p>3<%- messages() %>
deleted:examples/flash/views/layout.ejs-5 removed
1<html>2 <body>3 <%- body %>4 </body>5</html>
deleted:examples/flash/app.js-46 removed
12/**3 * Module dependencies.4 */56var express = require('../../lib/express');78// App with session support910var app = express.createServer(11 express.cookieParser()12 , express.session({ secret: 'keyboard cat' })13);1415// View settings1617app.set('views', __dirname + '/views');18app.set('view engine', 'ejs');1920app.dynamicHelpers({21 // express-messages is a dynamicHelper that22 // renders the flash messages to HTML for you23 // $ npm install express-messages24 messages: require('express-messages')25});2627app.dynamicHelpers({28 // Another dynamic helper example. Since dynamic29 // helpers resolve at view rendering time, we can30 // "inject" the "page" local variable per request31 // providing us with the request url.32 page: function(req, res){33 return req.url;34 } 35});3637app.get('/', function(req, res){38 // Not very realistic notifications but illustrates usage39 req.flash('info', 'email queued');40 req.flash('info', 'email sent');41 req.flash('error', 'delivery failed');42 res.render('index');43});4445app.listen(3000);46console.log('Express app started on port 3000');
modified:examples/form/app.js+6 added-8 removed
12// Expose modules in ./support for demo purposes3require.paths.unshift(__dirname + '/../../support');41/**2 * Module dependencies.3 */49var express = require('../../lib/express');5var express = require('../../');611var app = express.createServer();7var app = module.exports = express();89// Here we use the bodyDecoder middleware10// to parse urlencoded request bodies11// which populates req.body
60 unmodified lines
72 req.flash('info', 'Updated ' + req.body.name);73 res.redirect('/?name=' + req.body.name);74});7576if (!module.parent) {80app.listen(3000);81console.log('Express app started on port 3000');77 app.listen(3000);78 console.log('Express started on port 3000');79}
modified:examples/format/app.js+8 added-7 removed
1 unmodified line
2/**3 * Module dependencies.4 */56var express = require('../../lib/express');6var express = require('../../');78var app = express.createServer();8var app = module.exports = express();910// Fake items1112var items = [
31 unmodified lines
44 var xml = ''45 + '<items>'46 + '<item>' + item.name + '</item>'47 + '</items>';48 res.contentType('.xml');49 res.send(xml);48 res.type('xml').send(xml);49 break;50 case 'html':51 default:52 // By default send some hmtl
7 unmodified lines
60});6162// Middleware6365app.use(express.errorHandler({ showStack: true }));64app.use(express.errorHandler());6566if (!module.parent) {67app.listen(3000);68console.log('Express app started on port 3000');67 app.listen(3000);68 silent || console.log('Express started on port 3000');69}
modified:examples/github/views/index.jade+14 added-8 removed
12extends layout34block content1- each user in users2 .user3 h2= user.name4 p.summary5 | <a href="http://github.com/#{user.name}">#{user.name}</a> has6 | <strong>#{user.repos.length}</strong> repositories 7 | with a total of <strong>#{user.totalWatchers}</strong> watchers.8 table#repos!= partial('repo', user.repos)5 each user in users6 .user7 h2= user.name8 p.summary9 | <a href="http://github.com/#{user.name}">#{user.name}</a> has10 | <strong>#{user.repos.length}</strong> repositories 11 | with a total of <strong>#{user.totalWatchers}</strong> watchers.12 table#repos13 for repo in user.repos14 include repo
modified:examples/github/views/layout.jade+2 added-1 removed
2 unmodified lines
3 head4 title Github Example5 link(rel="stylesheet", href="/style.css")6 body7 #container!= body7 #container8 block content
modified:examples/github/app.js+1 added-1 removed
4 unmodified lines
56var express = require('../../lib/express')7 , http = require('http');89var app = express.createServer();9var app = express();1011// Expose our views1213app.set('views', __dirname + '/views');
100 unmodified lines
modified:examples/helloworld/app.js+3 added-2 removed
1 unmodified line
2/**3 * Module dependencies.4 */56var express = require('../../lib/express');6var express = require('../../');78var app = express.createServer();8var app = express();910app.get('/', function(req, res){11 res.send('Hello World');12});1314app.listen(3000);15console.log('Express started on port 3000');
modified:examples/markdown/app.js+29 added-22 removed
1 unmodified line
2/**3 * Module dependencies.4 */56var express = require('../../lib/express')7 , md = require('node-markdown').Markdown;6var express = require('../../')7 , fs = require('fs')8 , md = require('github-flavored-markdown').parse;99var app = express.createServer();10var app = module.exports = express();1111// register .md so that markdown may comply12// with the express view system by implementing13// a .compile() method12// register .md as an engine in express view system1315app.register('.md', {16 compile: function(str, options){17 var html = md(str);18 return function(locals){19 return html.replace(/\{([^}]+)\}/g, function(_, name){20 return locals[name];21 });22 };23 }24});14app.engine('md', function(path, options, fn){15 fs.readFile(path, 'utf8', function(err, str){16 if (err) return fn(err);17 try{18 var html = md(str);19 html = html.replace(/\{([^}]+)\}/g, function(_, name){20 return options[name];21 })22 fn(null,html)23 } catch(e){24 fn(e)25 }26 })27})2826// Optional since express defaults to CWD/views2729app.set('views', __dirname + '/views');30app.set('view engine', 'md');3132app.get('/', function(req, res){32 res.render('index', { layout: false, title: 'Markdown Example' });33});33 res.render('index', { title: 'Markdown Example' });34})3536app.get('/fail', function(req, res){37 res.render('missing', { title: 'Markdown Example' });38})3940if (!module.parent) {35app.listen(3000);36console.log('Express app started on port 3000');41 app.listen(3000);42 console.log('Express started on port 3000');43}
deleted:examples/mounting/app.js-23 removed
1/**2 * Module dependencies.3 */45var express = require('../../lib/express')6 , blog = require('../blog/app');78var app = express.createServer();910app.use(express.cookieParser());11app.use(express.session({ secret: 'keyboard cat' }));1213// mount the blog. the blog app is written using the "base"14// local variable, allowing its urls to adjust to wherever15// we wish to mount it.16app.use('/blog', blog);1718app.get('/', function(req, res){19 res.send('Visit <a href="/blog">/blog</a>');20});2122app.listen(3000);23console.log('Server listening on port 3000');
modified:examples/multipart/app.js+19 added-29 removed
1 unmodified line
2/**3 * Module dependencies.4 */56var express = require('../../lib/express')7 , form = require('connect-form');6var express = require('../../')7 , format = require('util').format;89var app = express.createServer(10 // connect-form (http://github.com/visionmedia/connect-form)11 // middleware uses the formidable middleware to parse urlencoded12 // and multipart form data13 form({ keepExtensions: true })14);9var app = module.exports = express()1011// bodyParser in connect 2.x uses node-formidable to parse 12// the multipart form data.13app.use(express.bodyParser())1415app.get('/', function(req, res){16 res.send('<form method="post" enctype="multipart/form-data">'17 + '<p>Title: <input type="text" name="title" /></p>'18 + '<p>Image: <input type="file" name="image" /></p>'19 + '<p><input type="submit" value="Upload" /></p>'20 + '</form>');21});2223app.post('/', function(req, res, next){2425 // connect-form adds the req.form object26 // we can (optionally) define onComplete, passing27 // the exception (if any) fields parsed, and files parsed28 req.form.complete(function(err, fields, files){29 if (err) {30 next(err);31 } else {32 console.log('\nuploaded %s to %s'33 , files.image.filename34 , files.image.path);35 res.redirect('back');36 }37 });25 // the uploaded file can be found as `req.files.image` and the26 // title field as `req.body.title`2739 // We can add listeners for several form40 // events such as "progress"41 req.form.on('progress', function(bytesReceived, bytesExpected){42 var percent = (bytesReceived / bytesExpected * 100) | 0;43 process.stdout.write('Uploading: %' + percent + '\r');44 });28 res.send(format('\nuploaded %s (%d Kb) to %s as %s'29 , req.files.image.name30 , (req.files.image.size / 1024) << 0 31 , req.files.image.path32 , req.body.title));33});3435if (!module.parent) {47app.listen(3000);48console.log('Express app started on port 3000');36 app.listen(3000);37 console.log('Express started on port 3000');38}
modified:examples/params/app.js+14 added-5 removed
1 unmodified line
2/**3 * Module dependencies.4 */56var express = require('../../lib/express')7 , app = express.createServer();6var express = require('../../')7 , app = module.exports = express();89// Faux database1011var users = [
5 unmodified lines
17];1819// Convert :to and :from to integers2021app.param(['to', 'from'], function(n){ return parseInt(n, 10); });21app.param(['to', 'from'], function(req, res, next, num, name){ 22 req.params[name] = num = parseInt(num, 10);23 if( isNaN(num) ){24 next(new Error('failed to parseInt '+num));25 } else {26 next();27 }28});2930// Load user by id3132app.param('user', function(req, res, next, id){
30 unmodified lines
63 , names = users.map(function(user){ return user.name; });64 res.send('users ' + names.slice(from, to).join(', '));65});6667if (!module.parent) {60app.listen(3000);61console.log('Express application listening on port 3000');68 app.listen(3000);69 console.log('Express started on port 3000');70}
modified:examples/resource/app.js+6 added-4 removed
1 unmodified line
2/**3 * Module dependencies.4 */56var express = require('../../lib/express');6var express = require('../../');78var app = express.createServer();8var app = module.exports = express();910// Ad-hoc example resource method1112app.resource = function(path, obj) {
71 unmodified lines
84 , '</ul>'85 ].join('\n')); 86});8788if (!module.parent) {88app.listen(3000);89console.log('Express app started on port 3000');89 app.listen(3000);90 console.log('Express started on port 3000');91}
added:test/acceptance/auth.js+93 added
1var app = require('../../examples/auth/app')2 , request = require('../support/http');34function redirects(to,fn){5 return function(res){6 res.statusCode.should.equal(302)7 res.headers.should.have.property('location').match(to);8 fn()9 }10}1112function getCookie(res) {13 return res.headers['set-cookie'][0].split(';')[0];14}1516describe('auth', function(){17 var cookie;1819 describe('GET /',function(){20 it('should redirect to /login', function(done){21 request(app)22 .get('/')23 .end(redirects(/\/login$/,done))24 })25 })2627 describe('GET /restricted (w/o cookie)',function(){28 it('should redirect to /login', function(done){29 request(app)30 .get('/restricted')31 .end(redirects(/\/login$/,done))32 })33 })3435 describe('POST /login', function(){36 it('should fail without proper credentials', function(done){37 request(app)38 .post('/login')39 .set('content-type','application/x-www-form-urlencoded')40 .write('&username=not-tj&password=foobar')41 .end(redirects(/\/login$/,done))42 })4344 it('should authenticate', function(done){45 request(app)46 .post('/login')47 .set('content-type', 'application/x-www-form-urlencoded')48 .write('username=tj&password=foobar')49 .end(function(res){50 res.statusCode.should.equal(302);51 cookie = getCookie(res);52 request(app)53 .get('/login')54 .set('Cookie', cookie)55 .end(function(res){56 res.body.should.include('Authenticated as tj');57 done();58 })59 })60 })61 })6263 describe('GET /restricted (w. cookie)',function(){64 it('should respond with 200', function(done){65 request(app)66 .get('/restricted')67 .set('Cookie', cookie)68 .expect(200, done);69 })70 })7172 describe('GET /logout',function(){73 it('should respond with 302 and clear cookie',function(done){74 request(app)75 .get('/logout')76 .set('Cookie', cookie)77 .end(function(res){78 res.statusCode.should.equal(302);79 res.headers.should.not.have.property('set-cookie')80 done();81 })82 })83 })8485 describe('GET /restricted (w. expired cookie)',function(){86 it('should respond with 302',function(done){87 request(app)88 .get('/restricted')89 .set('Cookie', cookie)90 .expect(302, done)91 })92 })93})
added:test/acceptance/blog.js+78 added
1var app = require('../../examples/blog/app')2 , request = require('../support/http');34var authorization = 'Basic ' + Buffer('admin:express').toString('base64');56function redirects(to,fn){7 return function(res){8 res.statusCode.should.equal(302)9 res.headers.should.have.property('location').match(to);10 fn()11 }12}1314describe('blog', function(){15 describe('GET /', function(){16 it('should have no posts', function(done){17 request(app)18 .get('/')19 .expect(/you have no posts/, done)20 })21 })2223 describe('GET /post/add', function(){24 it('should require auth', function(done){25 request(app)26 .get('/post/add')27 .expect(401, done)28 })2930 it('should login', function(done){31 request(app)32 .get('/post/add')33 .set('Authorization', authorization)34 .expect(/<h1>New Post<\/h1>/, done)35 })36 })3738 describe('POST /post', function(){39 it('should require auth', function(done){40 request(app)41 .post('/post')42 .expect(401, done)43 })4445 it('should redirect to / with no title or body', function(done){46 request(app)47 .post('/post')48 .set('Authorization', authorization)49 .end(redirects(/\/$/, done))50 })5152 it('should redirect to / with no body', function(done){53 request(app)54 .post('/post')55 .set('Authorization', authorization)56 .set('Content-Type', 'application/x-www-form-urlencoded')57 .write('post[title]=Kittens')58 .end(redirects(/\/$/, done))59 })6061 it('should redirect to /post/:post when successful', function(done){62 request(app)63 .post('/post')64 .set('Authorization', authorization)65 .set('Content-Type', 'application/x-www-form-urlencoded')66 .write('post[title]=Kittens&post[body]=In+very+large+baskets')67 .end(redirects(/\/post\/\d+$/, done))68 })69 })7071 describe('GET /', function(){72 it('should now list 1 post',function(done){73 request(app)74 .get('/')75 .expect(/Display all 1 post/, done)76 })77 })78})
added:test/acceptance/cookies.js+33 added
1var app = require('../../examples/cookies/app')2 , request = require('../support/http');34describe('cookies', function(){5 describe('GET /', function(){6 it('should have a form', function(done){7 request(app)8 .get('/')9 .expect(/<form/,done)10 })11 it('should respond with no cookies', function(done){12 request(app)13 .get('/')14 .end(function(res){15 res.headers.should.not.have.property('set-cookie')16 done()17 })18 })19 })2021 describe('POST /', function(){22 it('should set a cookie', function(done){23 request(app)24 .post('/')25 .set('Content-Type','application/x-www-form-urlencoded')26 .write('remember=1')27 .end(function(res){28 res.headers.should.have.property('set-cookie')29 done()30 })31 })32 })33})
added:test/acceptance/downloads.js+32 added
1var app = require('../../examples/downloads/app')2 , request = require('../support/http');34describe('downloads', function(){5 describe('GET /', function(){6 it('should have a link to amazing.txt', function(done){7 request(app)8 .get('/')9 .expect(/href="\/files\/amazing.txt"/,done)10 })11 })1213 describe('GET /files/amazing.txt', function(){14 it('should have a download header', function(done){15 request(app)16 .get('/files/amazing.txt')17 .end(function(res){18 res.should.have.property('statusCode',200)19 res.headers.should.have.property('content-disposition', 'attachment; filename="amazing.txt"')20 done()21 })22 })23 })2425 describe('GET /files/missing.txt', function(){26 it('should respond with 404', function(done){27 request(app)28 .get('/files/missing.txt')29 .expect(404,done)30 })31 })32})
added:test/acceptance/error-pages.js+101 added
1var app = require('../../examples/error-pages/app')2 , request = require('../support/http');34describe('error-pages', function(){5 describe('GET /', function(){6 it('should respond with page list', function(done){7 request(app)8 .get('/')9 .expect(/Pages Example/,done)10 })11 })1213 describe('Accept: text/html',function(){14 describe('GET /403', function(){15 it('should respond with 403', function(done){16 request(app)17 .get('/403')18 .expect(403,done)19 })20 })21 describe('GET /404', function(){22 it('should respond with 404', function(done){23 request(app)24 .get('/404')25 .expect(404,done)26 })27 })28 describe('GET /500', function(){29 it('should respond with 500', function(done){30 request(app)31 .get('/500')32 .expect(500,done)33 })34 })35 })363738 describe('Accept: application/json',function(){39 describe('GET /403', function(){40 it('should respond with 403', function(done){41 request(app)42 .get('/403')43 .set('Accept','application/json')44 .expect(403,done)45 })46 })47 describe('GET /404', function(){48 it('should respond with 404', function(done){49 request(app)50 .get('/404')51 .set('Accept','application/json')52 .end(function(res){53 res.should.have.property('statusCode',200)54 res.should.have.property('body',JSON.stringify({error:'Not found'}))55 done()56 })57 })58 })59 describe('GET /500', function(){60 it('should respond with 500', function(done){61 request(app)62 .get('/500')63 .set('Accept','application/json')64 .expect(500,done)65 })66 })67 })686970 describe('Accept: text/plain',function(){71 describe('GET /403', function(){72 it('should respond with 403', function(done){73 request(app)74 .get('/403')75 .set('Accept','text/plain')76 .expect(403,done)77 })78 })79 describe('GET /404', function(){80 it('should respond with 404', function(done){81 request(app)82 .get('/404')83 .set('Accept','text/plain')84 .end(function(res){85 res.should.have.property('statusCode',200)86 res.should.have.property('body','Not found')87 done()88 })89 })90 })91 describe('GET /500', function(){92 it('should respond with 500', function(done){93 request(app)94 .get('/500')95 .set('Accept','text/plain')96 .expect(500,done)97 })98 })99 })100101})
added:test/acceptance/error.js+28 added
1var app = require('../../examples/error/app')2 , request = require('../support/http');34describe('error', function(){5 describe('GET /', function(){6 it('should respond with 500', function(done){7 request(app)8 .get('/')9 .expect(500,done)10 })11 })1213 describe('GET /next', function(){14 it('should respond with 500', function(done){15 request(app)16 .get('/next')17 .expect(500,done)18 })19 })2021 describe('GET /missing', function(){22 it('should respond with 404', function(done){23 request(app)24 .get('/missing')25 .expect(404,done)26 })27 })28})
added:test/acceptance/format.js+52 added
1var app = require('../../examples/format/app')2 , request = require('../support/http');34describe('format', function(){5 describe('GET /', function(){6 it('should respond with 200', function(done){7 request(app)8 .get('/')9 .expect(200,done)10 })11 })1213 describe('GET /item/2', function(){14 it('should respond with html', function(done){15 request(app)16 .get('/item/2')17 .end(function(res){18 res.should.have.property('statusCode',200)19 res.should.have.property('body','<h1>baz</h1>')20 res.headers.should.have.property('content-type','text/html; charset=utf-8')21 done()22 })23 })24 })2526 describe('GET /item/2.json', function(){27 it('should respond with json', function(done){28 request(app)29 .get('/item/2.json')30 .end(function(res){31 res.should.have.property('statusCode',200)32 res.should.have.property('body','{"name":"baz"}')33 res.headers.should.have.property('content-type','application/json; charset=utf-8')34 done()35 })36 })37 })3839 describe('GET /item/2.xml', function(){40 it('should respond with xml', function(done){41 request(app)42 .get('/item/2.xml')43 .end(function(res){44 res.should.have.property('statusCode',200)45 res.should.have.property('body','<items><item>baz</item></items>')46 res.headers.should.have.property('content-type','application/xml')47 done()48 })49 })50 })5152})
added:test/acceptance/markdown.js+20 added
1var app = require('../../examples/markdown/app')2 , request = require('../support/http');34describe('markdown', function(){5 describe('GET /', function(){6 it('should respond with html', function(done){7 request(app)8 .get('/')9 .expect(/<h1>Markdown Example<\/h1>/,done)10 })11 })1213 describe('GET /fail',function(){14 it('should respond with an error', function(done){15 request(app)16 .get('/fail')17 .expect(500,done)18 })19 })20})
added:test/acceptance/multipart.js+40 added
1var app = require('../../examples/multipart/app')2 , fs = require('fs')3 , request = require('../support/http');45var logo = fs.readFileSync(__dirname+'/../../docs/images/logo.png')6 , boundary = '------expressmultipart';78describe('multipart', function(){9 describe('GET /', function(){10 it('should respond with a form', function(done){11 request(app)12 .get('/')13 .expect(/<form/,done)14 })15 })1617 describe('POST /', function(){18 it('should upload logo as multipart', function(done){19 request(app)20 .post('/')21 .set('content-type','multipart/form-data; boundary='+boundary.slice(2))22 .write(boundary+'\r\n')23 .write('Content-Disposition: form-data; name="title"\r\n')24 .write('\r\n')25 .write('logo\r\n')26 .write(boundary+'\r\n')27 .write('Content-Disposition: form-data; name="image"; filename="logo.png"\r\n')28 .write('Content-Type: image/png\r\n')29 .write('\r\n')30 .write(logo+'\r\n')31 .write(boundary+'--\r\n')32 .end(function(res){33 res.body.should.match(/uploaded logo.png/)34 res.body.should.match(/\(12 Kb\)/)35 res.body.should.match(/as logo/)36 done()37 })38 })39 })40})
added:test/acceptance/params.js+28 added
1var app = require('../../examples/params/app')2 , request = require('../support/http');34describe('params', function(){5 describe('GET /', function(){6 it('should respond with instructions', function(done){7 request(app)8 .get('/')9 .expect(/Visit/,done)10 })11 })1213 describe('GET /user/0', function(){14 it('should respond with a user', function(done){15 request(app)16 .get('/user/0')17 .expect(/user tj/,done)18 })19 })2021 describe('GET /users/0-2', function(){22 it('should respond with three users', function(done){23 request(app)24 .get('/users/0-2')25 .expect(/users tj, tobi/,done)26 })27 })28})
added:test/acceptance/resource.js+52 added
1var app = require('../../examples/resource/app')2 , request = require('../support/http');34describe('resource', function(){5 describe('GET /', function(){6 it('should respond with instructions', function(done){7 request(app)8 .get('/')9 .expect(/^<h1>Examples:<\/h1>/,done)10 })11 })1213 describe('GET /users', function(){14 it('should respond with all users', function(done){15 request(app)16 .get('/users')17 .expect(/^\[{"name":"tj"},{"name":"ciaran"},{"name":"aaron"},{"name":"guillermo"},{"name":"simon"},{"name":"tobi"}\]/,done)18 })19 })2021 describe('GET /users/1', function(){22 it('should respond with user 1', function(done){23 request(app)24 .get('/users/1')25 .expect(/^{"name":"ciaran"}/,done)26 })27 })2829 describe('GET /users/1..3', function(){30 it('should respond with users 1 through 3', function(done){31 request(app)32 .get('/users/1..3')33 .expect(/^<ul><li>ciaran<\/li>\n<li>aaron<\/li>\n<li>guillermo<\/li><\/ul>/,done)34 })35 })3637 describe('DELETE /users/1', function(){38 it('should respond with users 1 through 3', function(done){39 request(app)40 .delete('/users/1')41 .expect(/^destroyed/,done)42 })43 })4445 describe('GET /users/1..3.json', function(){46 it('should respond with users 2 and 3 as json', function(done){47 request(app)48 .get('/users/1..3.json')49 .expect(/^\[null,{"name":"aaron"},{"name":"guillermo"}\]/,done)50 })51 })52})
modified:test/support/http.js+2 added
57 unmodified lines
58Request.prototype.expect = function(body, fn){59 this.end(function(res){60 if ('number' == typeof body) {61 res.statusCode.should.equal(body);62 } else if (body instanceof RegExp) {63 res.body.should.match(body);64 } else {65 res.body.should.equal(body);66 }67 fn();
38 unmodified lines
modified:Makefile+1 added-1 removed
33 unmodified lines
3435docclean:36 rm -f docs/*.{1,html}3738.PHONY: site test benchmark docs docclean test-acceptance38.PHONY: site test benchmark docs docclean test-acceptance
modified:package.json+2 added-1 removed
20 unmodified lines
21 "mocha": "*",22 "jade": "*",23 "stylus": "*",24 "should": "*",25 "connect-redis": "*"25 "connect-redis": "*",26 "github-flavored-markdown": "*"27 },28 "keywords": ["express", "framework", "sinatra", "web", "rest", "restful", "router"],29 "repository": "git://github.com/visionmedia/express",30 "main": "index",
8 unmodified lines