Route.js
This file
Path
test/Route.js
238 lines · 5.5 KiB · JavaScript
Last changed by
tests: change Route tests to use callbackDouglas Christopher Wilsonbefore adoptiond0b6b3d
History of this fileTake it
The walk stopped after 200 commits: lines older than 269dc53 point at it.
Invoke router.param() only when route matchesDouglas Christopher Wilsonbefore adoption269dc53
line 1why, one step back1tests: change Route tests to use callbackDouglas Christopher Wilsonbefore adoptiond0b6b3d
line 2why, one step back2var after = require('after');Invoke router.param() only when route matchesDouglas Christopher Wilsonbefore adoption269dc53
lines 3–12why, one step back3var should = require('should');4var express = require('../')5 , Route = express.Route6 , methods = require('methods')7 , assert = require('assert');89describe('Route', function(){1011 describe('.all', function(){12 it('should add handler', function(done){tests: change Route tests to use callbackDouglas Christopher Wilsonbefore adoptiond0b6b3d
line 13why, one step back13 var req = { method: 'GET', url: '/' };Invoke router.param() only when route matchesDouglas Christopher Wilsonbefore adoption269dc53
lines 14–16why, one step back14 var route = new Route('/foo');1516 route.all(function(req, res, next) {tests: change Route tests to use callbackDouglas Christopher Wilsonbefore adoptiond0b6b3d
line 17why, one step back17 req.called = true;Invoke router.param() only when route matchesDouglas Christopher Wilsonbefore adoption269dc53
lines 18–20why, one step back18 next();19 });20tests: change Route tests to use callbackDouglas Christopher Wilsonbefore adoptiond0b6b3d
lines 21–25why, one step back21 route.dispatch(req, {}, function (err) {22 if (err) return done(err);23 should(req.called).be.ok;24 done();25 });Invoke router.param() only when route matchesDouglas Christopher Wilsonbefore adoption269dc53
lines 26–28why, one step back26 })2728 it('should handle VERBS', function(done) {tests: change Route tests to use callbackDouglas Christopher Wilsonbefore adoptiond0b6b3d
line 29why, one step back29 var count = 0;Invoke router.param() only when route matchesDouglas Christopher Wilsonbefore adoption269dc53
line 30why, one step back30 var route = new Route('/foo');tests: change Route tests to use callbackDouglas Christopher Wilsonbefore adoptiond0b6b3d
lines 31–35why, one step back31 var cb = after(methods.length, function (err) {32 if (err) return done(err);33 count.should.equal(methods.length);34 done();35 });Invoke router.param() only when route matchesDouglas Christopher Wilsonbefore adoption269dc53
lines 36–38why, one step back3637 route.all(function(req, res, next) {38 count++;tests: change Route tests to use callbackDouglas Christopher Wilsonbefore adoptiond0b6b3d
line 39why, one step back39 next();Invoke router.param() only when route matchesDouglas Christopher Wilsonbefore adoption269dc53
lines 40–42why, one step back40 });4142 methods.forEach(function testMethod(method) {tests: change Route tests to use callbackDouglas Christopher Wilsonbefore adoptiond0b6b3d
lines 43–44why, one step back43 var req = { method: method, url: '/' };44 route.dispatch(req, {}, cb);Invoke router.param() only when route matchesDouglas Christopher Wilsonbefore adoption269dc53
lines 45–48why, one step back45 });46 })4748 it('should stack', function(done) {tests: change Route tests to use callbackDouglas Christopher Wilsonbefore adoptiond0b6b3d
line 49why, one step back49 var req = { count: 0, method: 'GET', url: '/' };Invoke router.param() only when route matchesDouglas Christopher Wilsonbefore adoption269dc53
lines 50–52why, one step back50 var route = new Route('/foo');5152 route.all(function(req, res, next) {tests: change Route tests to use callbackDouglas Christopher Wilsonbefore adoptiond0b6b3d
line 53why, one step back53 req.count++;Invoke router.param() only when route matchesDouglas Christopher Wilsonbefore adoption269dc53
lines 54–57why, one step back54 next();55 });5657 route.all(function(req, res, next) {tests: change Route tests to use callbackDouglas Christopher Wilsonbefore adoptiond0b6b3d
line 58why, one step back58 req.count++;Invoke router.param() only when route matchesDouglas Christopher Wilsonbefore adoption269dc53
lines 59–61why, one step back59 next();60 });61tests: change Route tests to use callbackDouglas Christopher Wilsonbefore adoptiond0b6b3d
lines 62–65why, one step back62 route.dispatch(req, {}, function (err) {63 if (err) return done(err);64 req.count.should.equal(2);65 done();Invoke router.param() only when route matchesDouglas Christopher Wilsonbefore adoption269dc53
lines 66–71why, one step back66 });67 })68 })6970 describe('.VERB', function(){71 it('should support .get', function(done){tests: change Route tests to use callbackDouglas Christopher Wilsonbefore adoptiond0b6b3d
line 72why, one step back72 var req = { method: 'GET', url: '/' };Invoke router.param() only when route matchesDouglas Christopher Wilsonbefore adoption269dc53
lines 73–75why, one step back73 var route = new Route('');7475 route.get(function(req, res, next) {tests: change Route tests to use callbackDouglas Christopher Wilsonbefore adoptiond0b6b3d
lines 76–77why, one step back76 req.called = true;77 next();Invoke router.param() only when route matchesDouglas Christopher Wilsonbefore adoption269dc53
lines 78–79why, one step back78 })79tests: change Route tests to use callbackDouglas Christopher Wilsonbefore adoptiond0b6b3d
lines 80–84why, one step back80 route.dispatch(req, {}, function (err) {81 if (err) return done(err);82 should(req.called).be.ok;83 done();84 });Invoke router.param() only when route matchesDouglas Christopher Wilsonbefore adoption269dc53
lines 85–87why, one step back85 })8687 it('should limit to just .VERB', function(done){tests: change Route tests to use callbackDouglas Christopher Wilsonbefore adoptiond0b6b3d
line 88why, one step back88 var req = { method: 'POST', url: '/' };Invoke router.param() only when route matchesDouglas Christopher Wilsonbefore adoption269dc53
lines 89–91why, one step back89 var route = new Route('');9091 route.get(function(req, res, next) {tests: change Route tests to use callbackDouglas Christopher Wilsonbefore adoptiond0b6b3d
line 92why, one step back92 throw new Error('not me!');Invoke router.param() only when route matchesDouglas Christopher Wilsonbefore adoption269dc53
lines 93–95why, one step back93 })9495 route.post(function(req, res, next) {tests: change Route tests to use callbackDouglas Christopher Wilsonbefore adoptiond0b6b3d
lines 96–97why, one step back96 req.called = true;97 next();Invoke router.param() only when route matchesDouglas Christopher Wilsonbefore adoption269dc53
lines 98–99why, one step back98 })99tests: change Route tests to use callbackDouglas Christopher Wilsonbefore adoptiond0b6b3d
lines 100–104why, one step back100 route.dispatch(req, {}, function (err) {101 if (err) return done(err);102 should(req.called).be.true;103 done();104 });Invoke router.param() only when route matchesDouglas Christopher Wilsonbefore adoption269dc53
lines 105–107why, one step back105 })106107 it('should allow fallthrough', function(done){tests: change Route tests to use callbackDouglas Christopher Wilsonbefore adoptiond0b6b3d
line 108why, one step back108 var req = { order: '', method: 'GET', url: '/' };Invoke router.param() only when route matchesDouglas Christopher Wilsonbefore adoption269dc53
lines 109–111why, one step back109 var route = new Route('');110111 route.get(function(req, res, next) {tests: change Route tests to use callbackDouglas Christopher Wilsonbefore adoptiond0b6b3d
line 112why, one step back112 req.order += 'a';Invoke router.param() only when route matchesDouglas Christopher Wilsonbefore adoption269dc53
lines 113–116why, one step back113 next();114 })115116 route.all(function(req, res, next) {tests: change Route tests to use callbackDouglas Christopher Wilsonbefore adoptiond0b6b3d
line 117why, one step back117 req.order += 'b';Invoke router.param() only when route matchesDouglas Christopher Wilsonbefore adoption269dc53
lines 118–121why, one step back118 next();119 });120121 route.get(function(req, res, next) {tests: change Route tests to use callbackDouglas Christopher Wilsonbefore adoptiond0b6b3d
lines 122–123why, one step back122 req.order += 'c';123 next();Invoke router.param() only when route matchesDouglas Christopher Wilsonbefore adoption269dc53
lines 124–125why, one step back124 })125tests: change Route tests to use callbackDouglas Christopher Wilsonbefore adoptiond0b6b3d
lines 126–130why, one step back126 route.dispatch(req, {}, function (err) {127 if (err) return done(err);128 req.order.should.equal('abc');129 done();130 });Invoke router.param() only when route matchesDouglas Christopher Wilsonbefore adoption269dc53
lines 131–135why, one step back131 })132 })133134 describe('errors', function(){135 it('should handle errors via arity 4 functions', function(done){tests: change Route tests to use callbackDouglas Christopher Wilsonbefore adoptiond0b6b3d
line 136why, one step back136 var req = { order: '', method: 'GET', url: '/' };Invoke router.param() only when route matchesDouglas Christopher Wilsonbefore adoption269dc53
lines 137–143why, one step back137 var route = new Route('');138139 route.all(function(req, res, next){140 next(new Error('foobar'));141 });142143 route.all(function(req, res, next){tests: change Route tests to use callbackDouglas Christopher Wilsonbefore adoptiond0b6b3d
line 144why, one step back144 req.order += '0';Invoke router.param() only when route matchesDouglas Christopher Wilsonbefore adoption269dc53
lines 145–148why, one step back145 next();146 });147148 route.all(function(err, req, res, next){tests: change Route tests to use callbackDouglas Christopher Wilsonbefore adoptiond0b6b3d
line 149why, one step back149 req.order += 'a';Invoke router.param() only when route matchesDouglas Christopher Wilsonbefore adoption269dc53
lines 150–152why, one step back150 next(err);151 });152tests: change Route tests to use callbackDouglas Christopher Wilsonbefore adoptiond0b6b3d
lines 153–156why, one step back153 route.dispatch(req, {}, function (err) {154 should(err).be.ok;155 should(err.message).equal('foobar');156 req.order.should.equal('a');Invoke router.param() only when route matchesDouglas Christopher Wilsonbefore adoption269dc53
lines 157–161why, one step back157 done();158 });159 })160161 it('should handle throw', function(done) {tests: change Route tests to use callbackDouglas Christopher Wilsonbefore adoptiond0b6b3d
line 162why, one step back162 var req = { order: '', method: 'GET', url: '/' };Invoke router.param() only when route matchesDouglas Christopher Wilsonbefore adoption269dc53
lines 163–169why, one step back163 var route = new Route('');164165 route.all(function(req, res, next){166 throw new Error('foobar');167 });168169 route.all(function(req, res, next){tests: change Route tests to use callbackDouglas Christopher Wilsonbefore adoptiond0b6b3d
line 170why, one step back170 req.order += '0';Invoke router.param() only when route matchesDouglas Christopher Wilsonbefore adoption269dc53
lines 171–174why, one step back171 next();172 });173174 route.all(function(err, req, res, next){tests: change Route tests to use callbackDouglas Christopher Wilsonbefore adoptiond0b6b3d
line 175why, one step back175 req.order += 'a';Invoke router.param() only when route matchesDouglas Christopher Wilsonbefore adoption269dc53
lines 176–178why, one step back176 next(err);177 });178tests: change Route tests to use callbackDouglas Christopher Wilsonbefore adoptiond0b6b3d
lines 179–182why, one step back179 route.dispatch(req, {}, function (err) {180 should(err).be.ok;181 should(err.message).equal('foobar');182 req.order.should.equal('a');Invoke router.param() only when route matchesDouglas Christopher Wilsonbefore adoption269dc53
lines 183–187why, one step back183 done();184 });185 });186187 it('should handle throwing inside error handlers', function(done) {tests: change Route tests to use callbackDouglas Christopher Wilsonbefore adoptiond0b6b3d
line 188why, one step back188 var req = { method: 'GET', url: '/' };Invoke router.param() only when route matchesDouglas Christopher Wilsonbefore adoption269dc53
lines 189–199why, one step back189 var route = new Route('');190191 route.get(function(req, res, next){192 throw new Error('boom!');193 });194195 route.get(function(err, req, res, next){196 throw new Error('oops');197 });198199 route.get(function(err, req, res, next){tests: change Route tests to use callbackDouglas Christopher Wilsonbefore adoptiond0b6b3d
lines 200–201why, one step back200 req.message = err.message;201 next();Invoke router.param() only when route matchesDouglas Christopher Wilsonbefore adoption269dc53
lines 202–203why, one step back202 });203tests: change Route tests to use callbackDouglas Christopher Wilsonbefore adoptiond0b6b3d
lines 204–208why, one step back204 route.dispatch(req, {}, function (err) {205 if (err) return done(err);206 should(req.message).equal('oops');207 done();208 });Invoke router.param() only when route matchesDouglas Christopher Wilsonbefore adoption269dc53
lines 209–211why, one step back209 });210211 it('should handle throw in .all', function(done) {tests: change Route tests to use callbackDouglas Christopher Wilsonbefore adoptiond0b6b3d
line 212why, one step back212 var req = { method: 'GET', url: '/' };Invoke router.param() only when route matchesDouglas Christopher Wilsonbefore adoption269dc53
lines 213–218why, one step back213 var route = new Route('');214215 route.all(function(req, res, next){216 throw new Error('boom!');217 });218tests: change Route tests to use callbackDouglas Christopher Wilsonbefore adoptiond0b6b3d
line 219why, one step back219 route.dispatch(req, {}, function(err){Invoke router.param() only when route matchesDouglas Christopher Wilsonbefore adoption269dc53
lines 220–226why, one step back220 should(err).be.ok;221 err.message.should.equal('boom!');222 done();223 });224 });225226 it('should handle single error handler', function(done) {tests: change Route tests to use callbackDouglas Christopher Wilsonbefore adoptiond0b6b3d
line 227why, one step back227 var req = { method: 'GET', url: '/' };Invoke router.param() only when route matchesDouglas Christopher Wilsonbefore adoption269dc53
lines 228–234why, one step back228 var route = new Route('');229230 route.all(function(err, req, res, next){231 // this should not execute232 true.should.be.false;233 });234tests: change Route tests to use callbackDouglas Christopher Wilsonbefore adoptiond0b6b3d
line 235why, one step back235 route.dispatch(req, {}, done);Invoke router.param() only when route matchesDouglas Christopher Wilsonbefore adoption269dc53
lines 236–238why, one step back236 });237 })238})