started mvc acceptance 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 d0bc0ad · Browse files · 4 files·+75 added−9 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+75 added−9 removed
- tests:+63 added−0 removed
- other:+12 added−9 removed
Provenance
- Commit
1e85178- Tree
87658c3- Author
TJ Holowaychuk <tj@vision-media.ca>- Committer
TJ Holowaychuk <tj@vision-media.ca>- Parent
d0bc0ad
4 files changed+75 added−9 removed
modified:examples/mvc/lib/boot.js+5 added-4 removed
1234565678891011121341 unmodified lines555657585859606162632 unmodified lines
var express = require('../../..') , fs = require('fs');
module.exports = function(parent){ console.log();module.exports = function(parent, options){ var verbose = options.verbose; verbose && console.log(); fs.readdirSync(__dirname + '/../controllers').forEach(function(name){ console.log(' %s:', name); verbose && console.log(' %s:', name); var obj = require('./../controllers/' + name) , name = obj.name || name , prefix = obj.prefix || '' , app = express()41 unmodified lines }
path = prefix + path; app[method](path, obj[key]); console.log(' %s %s -> %s', method.toUpperCase(), path, key); verbose && console.log(' %s %s -> %s', method.toUpperCase(), path, key); }
// mount the app parent.use(app);2 unmodified linesmodified:examples/mvc/index.js+6 added-4 removed
12344567852 unmodified lines61626364656566676768686970
var express = require('../..');
var app = express();var app = module.exports = express();
// settings
// map .renderFile to ".html" files52 unmodified lines// support _method (PUT in forms etc)app.use(express.methodOverride());
// load controllersrequire('./lib/boot')(app);require('./lib/boot')(app, { verbose: !module.parent });
if (!module.parent) {app.listen(3000);console.log('\n listening on port 3000\n'); app.listen(3000); console.log('\n listening on port 3000\n');}No newline at end of fileadded:test/acceptance/mvc.js+63 added
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
var request = require('../support/http') , app = require('../../examples/mvc');
describe('mvc', function(){ describe('GET /', function(){ it('should redirect to /users', function(done){ request(app) .get('/') .end(function(res){ res.should.have.status(302); res.headers.location.should.include('/users'); done(); }) }) })
describe('GET /users', function(){ it('should display a list of users', function(done){ request(app) .get('/users') .end(function(res){ res.body.should.include('<h1>Users</h1>'); res.body.should.include('>TJ<'); res.body.should.include('>Guillermo<'); res.body.should.include('>Nathan<'); done(); }) }) })
describe('GET /user/:id', function(){ describe('when present', function(){ it('should display the user', function(done){ request(app) .get('/user/0') .end(function(res){ res.body.should.include('<h1>TJ <a href="/user/0/edit">edit'); done(); }) })
it('should display the users pets', function(done){ request(app) .get('/user/0') .end(function(res){ res.body.should.include('/pet/0">Tobi'); res.body.should.include('/pet/1">Loki'); res.body.should.include('/pet/2">Jane'); done(); }) }) })
describe('when not present', function(){ it('should 404', function(done){ request(app) .get('/user/123') .expect(404, done); }) }) })})No newline at end of filemodified:Makefile+1 added-1 removed
14 unmodified lines15 --reporter $(REPORTER)16 17 test-acceptance:18 @NODE_ENV=test ./node_modules/.bin/mocha \19- --reporter spec \19+ --reporter $(REPORTER) \20 test/acceptance/*.js21 22 test-cov: lib-cov23 @EXPRESS_COV=1 $(MAKE) test REPORTER=html-cov > coverage.html11 unmodified lines